Files
predictV1/start/parse_pro_matches.py
mamonov.ep 8a134239d7 Initial commit: добавление проекта predictV1
Включает модели ML для предсказаний, API маршруты, скрипты обучения и данные.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-21 17:22:58 +03:00

80 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import requests
import psycopg2
from psycopg2.extras import execute_values
PAGE = 10
url = "https://api.opendota.com/api/proMatches"
all_matches = []
less_than_match_id = None
# Разрешенные лиги
ALLOWED_LEAGUES = [17420] # Замените на нужные ID лиг
for page in range(PAGE):
params = {}
if less_than_match_id:
params['less_than_match_id'] = less_than_match_id
response = requests.get(url, params=params)
if response.status_code == 200:
matches = response.json()
all_matches.extend(matches)
print(f"Страница {page + 1}: получено {len(matches)} матчей")
if matches:
less_than_match_id = matches[-1]['match_id']
else:
print(f"Ошибка на странице {page + 1}: {response.status_code}")
break
print(f"\nВсего получено {len(all_matches)} матчей")
# Подключение к базе данных
conn = psycopg2.connect(
host="localhost",
port=5432,
database="korobka_db",
user="postgres",
password="postgres"
)
cursor = conn.cursor()
# Подготовка данных для вставки (фильтр по leagueid)
data = [
(
match['match_id'],
match.get('start_time'),
match.get('leagueid'),
match.get('radiant_team_id'),
match.get('dire_team_id'),
match.get('radiant_win'),
'pro' # ← добавили source
)
for match in all_matches
if match.get('leagueid') in ALLOWED_LEAGUES
]
print(f"Отфильтровано {len(data)} матчей из {len(all_matches)} по разрешенным лигам")
# Вставка данных в таблицу
execute_values(
cursor,
"""INSERT INTO matches (id, start_time, leagueid, radiant_team_id, dire_team_id, radiant_win, source)
VALUES %s
ON CONFLICT (id) DO UPDATE SET
start_time = EXCLUDED.start_time,
leagueid = EXCLUDED.leagueid,
radiant_team_id = EXCLUDED.radiant_team_id,
dire_team_id = EXCLUDED.dire_team_id,
radiant_win = EXCLUDED.radiant_win,
source = EXCLUDED.source""",
data
)
conn.commit()
cursor.close()
conn.close()
print(f"Успешно сохранено {len(data)} матчей в БД")