Участник:Гиперболоид инженера Мошонкина/скрипт: различия между версиями

Нет описания правки
Нет описания правки
Строка 16: Строка 16:


         num_teams = int(match.group(2))
         num_teams = int(match.group(2))
         legs_indicator = int(match.group(3))
         legs_indicator = int(match.group(3)) # Читаем цифру после А (1 или 2)
         leg_val = 1 if legs_indicator == 2 else 0
         leg_val = 1 if legs_indicator == 2 else 0 # 1 - два круга (дома/выезд), 0 - один круг (нейтральное)


         body = match.group(4)
         body = match.group(4)
        # Убрано "if p.strip()", чтобы сохранять пустые поля, если статус не указан
         parts = [p.strip() for p in body.split('|')]
         parts = [p.strip() for p in body.split('|')]


Строка 42: Строка 41:
         lua_output.append('            matches = {')
         lua_output.append('            matches = {')


        # Распределение матчей
         for i, team in enumerate(teams):
         for i, team in enumerate(teams):
             score_idx = 0
             score_idx = 0
             for j, opp in enumerate(teams):
             for j, opp in enumerate(teams):
                 if i == j: continue
                 if i == j: continue # Сама с собой не играет
               
                # Считываем счёт в любом случае, чтобы правильно двигаться по матрице
                 if score_idx < len(team["scores"]):
                 if score_idx < len(team["scores"]):
                     score_str = team["scores"][score_idx]
                     score_str = team["scores"][score_idx]
                     score_idx += 1
                     score_idx += 1
                     if ':' in score_str:
                   
                        g1, g2 = score_str.split(':')
                    # ЛОГИКА ФИЛЬТРАЦИИ:
                        lua_output.append(f'                {{"{team["name"]}", "{opp["name"]}", {g1.strip()}, {g2.strip()}, {leg_val}}},')
                    # Если 2 круга (leg_val == 1) - пишем все матчи
                    # Если 1 круг (leg_val == 0) - пишем только уникальные пары (где индекс i < j)
                     if leg_val == 1 or (leg_val == 0 and i < j):
                        if ':' in score_str:
                            g1, g2 = score_str.split(':')
                            lua_output.append(f'                {{"{team["name"]}", "{opp["name"]}", {g1.strip()}, {g2.strip()}, {leg_val}}},')


         lua_output.append('            }')
         lua_output.append('            }')
Строка 57: Строка 64:


     # --- 2. Парсинг матчей на вылет ---
     # --- 2. Парсинг матчей на вылет ---
    # Регулярка для И1, И2 и т.д.
     knockout_pattern = re.compile(r'\{\{И\d+\s*\|?(.*?)\}\}', re.IGNORECASE | re.DOTALL)
     knockout_pattern = re.compile(r'\{\{И\d+\s*\|?(.*?)\}\}', re.IGNORECASE | re.DOTALL)
     ko_counter = 1
     ko_counter = 1
Строка 63: Строка 69:
     for match in knockout_pattern.finditer(wiki_text):
     for match in knockout_pattern.finditer(wiki_text):
         body = match.group(1)
         body = match.group(1)
        # Убрано "if p.strip()", чтобы читать пустые цвета (например ||АЛЯ|)
         parts = [p.strip() for p in body.split('|')]
         parts = [p.strip() for p in body.split('|')]


Строка 85: Строка 90:
             base_scores = score_str
             base_scores = score_str


            # Парсинг доп. времени и пенальти
             if '(' in score_str:
             if '(' in score_str:
                 base_scores, ext = score_str.split('(', 1)
                 base_scores, ext = score_str.split('(', 1)
Строка 99: Строка 103:
                         p1, p2 = pen_match.groups()
                         p1, p2 = pen_match.groups()


            # Разбиваем по запятой для двойных противостояний
             matches_list = [s.strip() for s in base_scores.split(',')]
             matches_list = [s.strip() for s in base_scores.split(',')]


             if len(matches_list) == 2:
             if len(matches_list) == 2:
                # --- ЛОГИКА ДЛЯ ДВУХ МАТЧЕЙ ---
                 m1 = matches_list[0]
                 m1 = matches_list[0]
                 m2 = matches_list[1]
                 m2 = matches_list[1]
Строка 119: Строка 121:
                 )
                 )
             else:
             else:
                # --- ЛОГИКА ДЛЯ ОДНОГО МАТЧА ---
                 m1 = matches_list[0]
                 m1 = matches_list[0]
                 g1, g2 = "nil", "nil"
                 g1, g2 = "nil", "nil"
Строка 139: Строка 140:
# --- ЗАПУСК ---
# --- ЗАПУСК ---
if __name__ == "__main__":
if __name__ == "__main__":
     # Тестовые данные из вашего примера
     # Тестовые данные с группами А2 (2 круга) и А1 (1 круг)
     data = """
     data = """
     {{И1|G|КИР|4:3, 2:0|АЛЯ|R}}
    ; Группа 1
      
     {{Группа 3-А2|
     {{И2|G|КИР|4:3|АЛЯ|R}}
    G|КИР|2:0|3:3|
     G|ЦАР|0:2|4:2|
     R|ДОМ|3:3|2:4}}
      
      
     {{И3||АЛЯ|3:5|СЕН|}}
    ; Группа 2
     {{Группа 3-А1|
    G|КИР|2:0|3:3|
    G|ЦАР|0:2|4:2|
    R|ДОМ|3:3|2:4}}
     """
     """