rustat-python-api 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ from .parser import RuStatParser
2
+
3
+ __all__ = ['RuStatParser']
@@ -0,0 +1,127 @@
1
+ import requests
2
+ import pandas as pd
3
+ from collections import defaultdict
4
+ from tqdm import tqdm
5
+
6
+ from urls import URLs
7
+
8
+
9
+ class RuStatParser:
10
+ def __init__(self, user: str, password: str):
11
+ self.numeric_columns = [
12
+ 'id', 'number', 'player_id', 'team_id', 'half', 'second',
13
+ 'pos_x', 'pos_y', 'pos_dest_x', 'pos_dest_y', 'len', 'possession_id', 'possession_team_id',
14
+ 'opponent_id', 'opponent_team_id', 'zone_id', 'zone_dest_id',
15
+ 'possession_number', 'attack_status_id', 'attack_team_id', 'assistant_id', 'touches', 'xg'
16
+ ]
17
+
18
+ self.user = user
19
+ self.password = password
20
+
21
+ self.cached_info = {}
22
+
23
+ @staticmethod
24
+ def resp2data(query: str) -> dict:
25
+ response = requests.get(query)
26
+ return response.json()
27
+
28
+ def get_rpl_info(self):
29
+ for season_id in tqdm(range(1, 36)):
30
+ data = self.resp2data(
31
+ URLs["tournament_teams"].format(
32
+ user=self.user,
33
+ password=self.password,
34
+ season_id=season_id
35
+ )
36
+ )
37
+
38
+ if data:
39
+ first_team_id = data["data"]["row"][0]["id"]
40
+ first_team_schedule = self.resp2data(
41
+ URLs["schedule"].format(
42
+ user=self.user,
43
+ password=self.password,
44
+ team_id=first_team_id,
45
+ season_id=season_id
46
+ )
47
+ )
48
+
49
+ if first_team_schedule:
50
+ last_match = first_team_schedule["data"]["row"][0]
51
+ season_name = f'{last_match["tournament_name"]} {last_match["season_name"]}'
52
+ else:
53
+ season_name = ""
54
+
55
+ self.cached_info[season_id] = {
56
+ "season_name": season_name,
57
+ "season_teams": data["data"]["row"]
58
+ }
59
+
60
+ return self.cached_info
61
+
62
+ def get_schedule(self, team_id: str, season_id: str) -> dict:
63
+ data = self.resp2data(
64
+ URLs["schedule"].format(
65
+ user=self.user,
66
+ password=self.password,
67
+ team_id=team_id,
68
+ season_id=season_id
69
+ )
70
+ )
71
+
72
+ if not data:
73
+ return {}
74
+
75
+ return {
76
+ int(row["id"]): {
77
+ "match_date": row["match_date"],
78
+ "team1_id": int(row["team1_id"]),
79
+ "team2_id": int(row["team2_id"]),
80
+ "team1_name": row["team1_name"],
81
+ "team2_name": row["team2_name"]
82
+ }
83
+ for row in data["data"]["row"]
84
+ }
85
+
86
+ def get_events(self, match_id: int) -> pd.DataFrame | None:
87
+ data = self.resp2data(
88
+ URLs["events"].format(
89
+ user=self.user,
90
+ password=self.password,
91
+ match_id=match_id
92
+ )
93
+ )
94
+
95
+ if not data:
96
+ return None
97
+
98
+ df = pd.json_normalize(data["data"]["row"])
99
+
100
+ numeric_columns = [column for column in self.numeric_columns if column in df.columns]
101
+ df[numeric_columns] = df[numeric_columns].apply(pd.to_numeric, errors='coerce')
102
+
103
+ return df
104
+
105
+ def get_match_stats(self, match_id: int) -> dict:
106
+ data = self.resp2data(
107
+ URLs["match_stats"].format(
108
+ user=self.user,
109
+ password=self.password,
110
+ match_id=match_id
111
+ )
112
+ )
113
+
114
+ if not data:
115
+ return {}
116
+
117
+ stats = defaultdict(dict)
118
+
119
+ for row in data['data']['row']:
120
+ team_id = int(row['team_id'])
121
+ param_name = row['param_name']
122
+
123
+ param_value = float(row['value'])
124
+
125
+ stats[param_name][team_id] = param_value
126
+
127
+ return stats
@@ -0,0 +1,6 @@
1
+ URLs = {
2
+ "schedule": "http://feeds.rustatsport.ru/?tpl=35&user={user}&key={password}&team_id={team_id}&season_id={season_id}&date_start=&date_end=&format=json",
3
+ "events": "http://feeds.rustatsport.ru/?tpl=36&user={user}&key={password}&match_id={match_id}&start_ms=0&dl=0&lang_id=1&format=json",
4
+ "match_stats": "http://feeds.rustatsport.ru/?tpl=207&user={user}&key={password}&match_id={match_id}&lang_id=1&format=json",
5
+ "tournament_teams": "http://feeds.rustatsport.ru/?tpl=32&user={user}&key={password}&tournament_id=2&season_id={season_id}&date_start=&date_end=&lang_id=1&format=json"
6
+ }
@@ -0,0 +1 @@
1
+ Делайте че хотите с этим кодом.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.1
2
+ Name: rustat-python-api
3
+ Version: 0.1.0
4
+ Summary: A Python wrapper for RuStat API
5
+ Home-page: https://github.com/dailydaniel/rustat-python-api
6
+ Author: Daniel Zholkovsky
7
+ Author-email: daniel@zholkovsky.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests==2.32.3
16
+ Requires-Dist: pandas==2.2.3
17
+
18
+ # rustat-python-api
@@ -0,0 +1,8 @@
1
+ rustat_python_api/__init__.py,sha256=wJVi55HFoMQltJCu09lzrnTUJ77zBCs-SKORDoLR3jw,61
2
+ rustat_python_api/parser.py,sha256=1zgY3WVEkbKmUOF82GmuFT3gu7ym7IxOQAG9YVmkw9Q,3835
3
+ rustat_python_api/urls.py,sha256=YZyfFd6UdvDwBF_DC4-xm3H_F5fV4bppeUA2Iur7Acw,604
4
+ rustat_python_api-0.1.0.dist-info/LICENSE,sha256=4Cohqg5p6Mq1xyrzdEX8AvFSA62GSVvapEOr2xK_tgY,57
5
+ rustat_python_api-0.1.0.dist-info/METADATA,sha256=3BbI1xyGY820_j9-7-B1HpwMEBJIFH5yo6y4gDxOhAA,551
6
+ rustat_python_api-0.1.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
7
+ rustat_python_api-0.1.0.dist-info/top_level.txt,sha256=VK0hmkKZE9YThxolUcoE6JtGI67NFeKJMBLuet8kI4w,18
8
+ rustat_python_api-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.44.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ rustat_python_api