aiosofascore 0.0.1__tar.gz

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include README.md
2
+ include LICENSE
3
+ recursive-include src *.py
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.1
2
+ Name: aiosofascore
3
+ Version: 0.0.1
4
+ Summary: API client for SofaScore soccer data
5
+ Home-page: https://github.com/Rooney27/aio_sofascore
6
+ Author: Philip
7
+ Author-email: vasilewskij.fil@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: aiohttp
15
+ Requires-Dist: pydantic
16
+
17
+ # Aiosofascore
18
+
19
+ **Aiosofascore** is an API client for SofaScore's soccer data, designed to provide easy access to soccer categories, tournaments, events, and much more. It is built with `aiohttp` for asynchronous HTTP requests and can be integrated into any Python project that needs soccer-related data.
20
+
21
+ ## Features
22
+
23
+ - Fetch soccer categories and tournaments
24
+ - Get detailed tournament standings and seasons
25
+ - Retrieve pregame forms, head-to-head stats, and event managers
26
+ - Built using Python's asynchronous capabilities with `aiohttp`
27
+
28
+ ## Installation
29
+
30
+ To install **aiosofascore** from PyPI, run the following command:
31
+
32
+ ```bash
33
+ pip install my_project
@@ -0,0 +1,17 @@
1
+ # Aiosofascore
2
+
3
+ **Aiosofascore** is an API client for SofaScore's soccer data, designed to provide easy access to soccer categories, tournaments, events, and much more. It is built with `aiohttp` for asynchronous HTTP requests and can be integrated into any Python project that needs soccer-related data.
4
+
5
+ ## Features
6
+
7
+ - Fetch soccer categories and tournaments
8
+ - Get detailed tournament standings and seasons
9
+ - Retrieve pregame forms, head-to-head stats, and event managers
10
+ - Built using Python's asynchronous capabilities with `aiohttp`
11
+
12
+ ## Installation
13
+
14
+ To install **aiosofascore** from PyPI, run the following command:
15
+
16
+ ```bash
17
+ pip install my_project
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.1
2
+ Name: aiosofascore
3
+ Version: 0.0.1
4
+ Summary: API client for SofaScore soccer data
5
+ Home-page: https://github.com/Rooney27/aio_sofascore
6
+ Author: Philip
7
+ Author-email: vasilewskij.fil@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: aiohttp
15
+ Requires-Dist: pydantic
16
+
17
+ # Aiosofascore
18
+
19
+ **Aiosofascore** is an API client for SofaScore's soccer data, designed to provide easy access to soccer categories, tournaments, events, and much more. It is built with `aiohttp` for asynchronous HTTP requests and can be integrated into any Python project that needs soccer-related data.
20
+
21
+ ## Features
22
+
23
+ - Fetch soccer categories and tournaments
24
+ - Get detailed tournament standings and seasons
25
+ - Retrieve pregame forms, head-to-head stats, and event managers
26
+ - Built using Python's asynchronous capabilities with `aiohttp`
27
+
28
+ ## Installation
29
+
30
+ To install **aiosofascore** from PyPI, run the following command:
31
+
32
+ ```bash
33
+ pip install my_project
@@ -0,0 +1,20 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ setup.py
5
+ aiosofascore.egg-info/PKG-INFO
6
+ aiosofascore.egg-info/SOURCES.txt
7
+ aiosofascore.egg-info/dependency_links.txt
8
+ aiosofascore.egg-info/requires.txt
9
+ aiosofascore.egg-info/top_level.txt
10
+ src/__init__.py
11
+ src/execptions.py
12
+ src/api/__init__.py
13
+ src/api/mixins.py
14
+ src/api/soccer/__init__.py
15
+ src/api/soccer/base.py
16
+ src/api/soccer/categories.py
17
+ src/api/soccer/event.py
18
+ src/api/soccer/tournaments.py
19
+ src/api/soccer/schemas/__init__.py
20
+ src/api/soccer/schemas/base.py
@@ -0,0 +1,2 @@
1
+ aiohttp
2
+ pydantic
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="aiosofascore",
5
+ version="0.0.1",
6
+ description="API client for SofaScore soccer data",
7
+ long_description=open('README.md').read(),
8
+ long_description_content_type="text/markdown",
9
+ author="Philip", # Ваше имя
10
+ author_email="vasilewskij.fil@gmail.com",
11
+ url="https://github.com/Rooney27/aio_sofascore",
12
+ packages=find_packages(),
13
+ classifiers=[
14
+ "Programming Language :: Python :: 3",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Operating System :: OS Independent",
17
+ ],
18
+ install_requires=[
19
+ "aiohttp",
20
+ "pydantic"
21
+ ],
22
+ python_requires='>=3.10', # Укажите минимальную версию Python
23
+ )
File without changes
File without changes
@@ -0,0 +1,30 @@
1
+ from aiohttp import ClientSession, ClientResponse
2
+
3
+ from sofascore.execptions import ResponseParseContentError
4
+
5
+
6
+ class ClientSessionManagerMixin:
7
+ async def __aenter__(self):
8
+ headers = {
9
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 YaBrowser/24.12.0.0 Safari/537.36'
10
+ }
11
+ self.session = ClientSession(headers=headers)
12
+
13
+ async def __aexit__(self, exc_type, exc_val, exc_tb):
14
+ await self.session.close()
15
+
16
+ async def _get(self, path: str, params: dict = None) -> ClientResponse:
17
+ """
18
+ Executes an HTTP GET request to the given API path.
19
+
20
+ Args:
21
+ path (str): The API path to request.
22
+ params (dict, optional): Query parameters for the request.
23
+
24
+ Returns:
25
+ ClientResponse: The response from the API.
26
+ """
27
+ result = await self.session.get(self.BASE_URL + path, params=params)
28
+ if result.ok:
29
+ return await result.json()
30
+ raise ResponseParseContentError(result,path)
File without changes
@@ -0,0 +1,14 @@
1
+ from src.api.mixins import ClientSessionManagerMixin
2
+ from src.api.soccer.categories import SoccerCategoriesApi
3
+ from src.api.soccer.event import SoccerEventApi
4
+ from src.api.soccer.tournaments import SoccerTournamentApi
5
+
6
+ __all__ =['BaseSoccerApi']
7
+
8
+ class BaseSoccerApi(ClientSessionManagerMixin, SoccerCategoriesApi,
9
+ SoccerTournamentApi, SoccerEventApi):
10
+ """
11
+ Base API client for interacting with SofaScore's soccer API.
12
+ Provides methods for fetching soccer categories and tournaments.
13
+ """
14
+ BASE_URL = 'https://api.sofascore.com/'
@@ -0,0 +1,21 @@
1
+ from typing import Union
2
+
3
+ from src.api.soccer.schemas.base import CategoryList, Category
4
+
5
+ __all__ = ['SoccerCategoriesApi']
6
+
7
+ class SoccerCategoriesApi:
8
+ async def get_categories(self) -> Union[CategoryList,list]:
9
+ """
10
+ Fetches a list of soccer categories.
11
+
12
+ Returns:
13
+ CategoryList: A list of soccer categories encapsulated in a CategoryList object.
14
+ Returns an empty list if an error occurs during the request or JSON parsing.
15
+ """
16
+ async with self:
17
+ content = await self._get('api/v1/sport/football/categories/')
18
+ return CategoryList(
19
+ categories=[Category(**category) for category in
20
+ content['categories']]
21
+ )
@@ -0,0 +1,20 @@
1
+ from src.api.soccer.schemas.base import PregameTeamForm, H2H, \
2
+ EventManagers
3
+
4
+
5
+ class SoccerEventApi:
6
+
7
+ async def get_pregame_form(self,event_id:str)->PregameTeamForm:
8
+ async with self:
9
+ result = self._get(f'api/v1/event/{event_id}/pregame-form')
10
+ return PregameTeamForm(**result)
11
+
12
+ async def get_h2h(self,event_id:str)->H2H:
13
+ async with self:
14
+ result = self._get(f'api/v1/event/{event_id}/h2h')
15
+ return H2H(**result)
16
+
17
+ async def get_managers(self,event_id:str)->EventManagers:
18
+ async with self:
19
+ result = self._get(f'api/v1/event/{event_id}/managers')
20
+ return EventManagers(**result)
@@ -0,0 +1 @@
1
+ from .base import *
@@ -0,0 +1,267 @@
1
+ from typing import Optional, Iterator
2
+ from pydantic import BaseModel, fields, Field
3
+
4
+
5
+
6
+ class Sport(BaseModel):
7
+ """
8
+ Represents a sport entity with essential attributes.
9
+
10
+ Attributes:
11
+ name (str): Name of the sport.
12
+ slug (str): URL-friendly identifier for the sport.
13
+ id (int): Unique identifier for the sport.
14
+ """
15
+ name: str
16
+ slug: str
17
+ id: int
18
+
19
+
20
+ class Category(BaseModel):
21
+ """
22
+ Represents a category associated with a sport.
23
+
24
+ Attributes:
25
+ name (str): Name of the category.
26
+ slug (str): URL-friendly identifier for the category.
27
+ sport (Sport): The sport associated with this category.
28
+ priority (Optional[int]): Priority level for the category (if available).
29
+ id (int): Unique identifier for the category.
30
+ flag (str): Country flag or symbol associated with the category.
31
+ """
32
+ name: str
33
+ slug: str
34
+ sport: Sport
35
+ priority: Optional[int] = None
36
+ id: int
37
+ flag: str
38
+
39
+
40
+ class CategoryList(BaseModel):
41
+ """
42
+ Represents a list of Category objects with search functionality.
43
+
44
+ Attributes:
45
+ categories (list[Category]): A list containing Category objects.
46
+
47
+ Methods:
48
+ find_all_by_name(name: str, search_amateur: bool = False) -> list[Category]:
49
+ Finds categories by name with an optional search for amateur categories.
50
+ """
51
+ categories: list[Category]
52
+
53
+ def find_all_by_name(self, name: str, search_amateur=False) -> list[
54
+ Category]:
55
+ """
56
+ Finds all categories whose names contain the given substring.
57
+
58
+ Args:
59
+ name (str): The substring to search for in category names.
60
+ search_amateur (bool, optional): Whether to include only amateur categories. Defaults to False.
61
+
62
+ Returns:
63
+ list[Category]: A list of categories matching the criteria.
64
+ """
65
+ return [c for c in self.categories if
66
+ name.lower() in c.name.lower() and
67
+ ('amateur' in c.name.lower()) == search_amateur]
68
+ def __iter__(self)->Iterator[Category]:
69
+ return iter(self.categories)
70
+
71
+ class UniqueTournament(BaseModel):
72
+ """
73
+ Represents a unique soccer tournament.
74
+
75
+ Attributes:
76
+ name (str): Name of the tournament.
77
+ slug (str): URL-friendly identifier for the tournament.
78
+ primaryColorHex (Optional[str]): Primary color in hexadecimal format.
79
+ secondaryColorHex (Optional[str]): Secondary color in hexadecimal format.
80
+ category (Category): The category associated with the tournament.
81
+ userCount (int): Number of users following the tournament.
82
+ id (int): Unique identifier for the tournament.
83
+ displayInverseHomeAwayTeams (bool): Flag indicating if home/away teams should be inversed in display.
84
+ """
85
+ name: str
86
+ slug: str
87
+ primaryColorHex: Optional[str] = None
88
+ secondaryColorHex: Optional[str] = None
89
+ category: Category
90
+ userCount: int
91
+ id: int
92
+ displayInverseHomeAwayTeams: bool
93
+
94
+
95
+ class Tournament(BaseModel):
96
+ category: Category
97
+ id: int
98
+ is_group: bool = Field(..., alias="isGroup")
99
+ is_live: bool = Field(..., alias="isLive")
100
+ name: str
101
+ priority: int
102
+ slug: str
103
+ uniqueTournament: UniqueTournament
104
+
105
+
106
+ class Promotion(BaseModel):
107
+ id: int
108
+ text: str
109
+
110
+
111
+ class Team(BaseModel):
112
+ disabled: bool
113
+ entityType: str
114
+ gender: str
115
+ id: int
116
+ name: str
117
+ name_code: str = Field(..., alias="nameCode")
118
+ national: bool
119
+ short_name: str = Field(..., alias="shortName")
120
+ slug: str
121
+
122
+
123
+ class StandingsRow(BaseModel):
124
+ descriptions: list[str]
125
+ draws: int
126
+ id: int
127
+ losses: int
128
+ matches: int
129
+ points: int
130
+ position: int
131
+ promotion: Promotion = None
132
+ score_diff_formatted: str = Field(..., alias="scoreDiffFormatted")
133
+ scores_against: int = Field(..., alias="scoresAgainst")
134
+ scores_for: int = Field(..., alias="scoresFor")
135
+ team: Team
136
+ wins: int
137
+
138
+
139
+ class Standings(BaseModel):
140
+ descriptions: list[str]
141
+ id: int
142
+ name: str
143
+ rows: list[StandingsRow]
144
+ tournament: Tournament
145
+
146
+
147
+ class Season(BaseModel):
148
+ name: str
149
+ year: str
150
+ editor: bool
151
+ id: int
152
+
153
+
154
+ class SeasonList(BaseModel):
155
+ seasons: list[Season]
156
+
157
+ def get_season_by_year(self, year: str) -> Season:
158
+ return next((season for season in self.seasons if season.year == year),
159
+ None)
160
+
161
+ def get_current_season(self) -> Season:
162
+ return self.seasons[0]
163
+
164
+ def __iter__(self) ->Iterator[Season]:
165
+ return iter(self.seasons)
166
+
167
+
168
+ class TeamForm(BaseModel):
169
+ avg_rating: str = Field(alias='avgRating')
170
+ form: list[str]
171
+ position: int
172
+ value: str
173
+
174
+
175
+ class PregameTeamForm(BaseModel):
176
+ away_team: TeamForm = Field(alias='awayTeam')
177
+ home_team: TeamForm = Field(alias='homeTeam')
178
+
179
+
180
+ class Duel(BaseModel):
181
+ away_wins: int = Field(alias='awayWins')
182
+ draws: int
183
+ home_wins: int = Field(alias='homeWins')
184
+
185
+
186
+ class H2H(BaseModel):
187
+ manager_duel: Duel = Field(alias='managerDuel')
188
+ team_duel: Duel = Field(alias='teamDuel')
189
+
190
+
191
+ class Manager(BaseModel):
192
+ name: str
193
+ slug: str
194
+ short_name: str = Field(alias='shortName')
195
+ id: str
196
+
197
+
198
+ class EventManagers(BaseModel):
199
+ home_manager: Manager = Field(alias='homeManager')
200
+ away_manager: Manager = Field(alias='awayManager')
201
+
202
+
203
+ class RoundInfo(BaseModel):
204
+ round: int
205
+
206
+
207
+ class City:
208
+ name: str
209
+
210
+
211
+ class VenueCoordinates(BaseModel):
212
+ latitude: str
213
+ longtitude: str
214
+
215
+
216
+ class Country(BaseModel):
217
+ alpha2: str
218
+ alpha3: str
219
+ name: str
220
+ slug: str
221
+
222
+
223
+ class Stadium(BaseModel):
224
+ name: str
225
+ capacity: int
226
+
227
+
228
+ class Venue(BaseModel):
229
+ city: City
230
+ venue_coordinates: VenueCoordinates = Field(alias='venueCoordinates')
231
+ hidden: bool
232
+ slug: str
233
+ name: str
234
+ capacity: int
235
+ id: int
236
+ country: Country
237
+ stadium: Stadium
238
+
239
+
240
+ class Referee(BaseModel):
241
+ name: str
242
+ slug: str
243
+ yellow_cards: int = Field(alias='yellowCards')
244
+ red_cards: int = Field(alias='redCards')
245
+ yellow_red_cards: int = Field(alias='yellowRedCards')
246
+ games: int
247
+ sport: Sport
248
+ id: int
249
+ country: Country
250
+
251
+
252
+ class EventTeam(Team):
253
+ sport: Sport
254
+ manager: Manager
255
+ venue: Venue
256
+ country: Country
257
+
258
+
259
+ # TODO: Create Prematch,live,fulltime Event
260
+ class Event(BaseModel):
261
+ tournament: Tournament
262
+ season: Season
263
+ round_info: RoundInfo = Field(alias='roundInfo')
264
+ custom_id: str = Field(alias='customId')
265
+ venue: Venue
266
+ home_team: EventTeam = Field(alias='homeTeam')
267
+ away_team: EventTeam = Field(alias='awayTeam')
@@ -0,0 +1,48 @@
1
+ from src.api.soccer.schemas.base import UniqueTournament, Category, \
2
+ SeasonList, Standings
3
+
4
+ __all__ = ['SoccerTournamentApi']
5
+
6
+
7
+ class SoccerTournamentApi:
8
+ async def get_tournament_by_category(self, category: Category) -> list[
9
+ UniqueTournament]:
10
+ """
11
+ Fetches a list of unique tournaments for a given soccer category.
12
+
13
+ Args:
14
+ category (Category): The soccer category for which to retrieve tournaments.
15
+
16
+ Returns:
17
+ list[UniqueTournament]: A list of unique tournaments for the given category.
18
+ """
19
+ async with self:
20
+ content = await self._get(
21
+ f'api/v1/category/{category.id}/unique-tournaments')
22
+ return [
23
+ UniqueTournament(**uniqueTournament)
24
+ for uniqueTournament in
25
+ content['groups'][0]['uniqueTournaments']
26
+ ]
27
+
28
+ async def get_tournament_seasons(self,
29
+ unique_tournament: UniqueTournament) -> SeasonList:
30
+ async with self:
31
+ response = await self._get(
32
+ f'api/v1/unique-tournament/{unique_tournament.id}/seasons')
33
+ seasons = response['seasons']
34
+ return SeasonList(seasons=seasons)
35
+
36
+ async def get_tournament_standings(self,
37
+ unique_tournament: UniqueTournament,
38
+ season_year: str = None):
39
+ if season_year:
40
+ season = await (await self.get_tournament_seasons(unique_tournament)).get_season_by_year(season_year)
41
+ else:
42
+ season = await (await self.get_tournament_seasons(unique_tournament)).get_current_season()
43
+
44
+ async with self:
45
+ response = await self._get(
46
+ f'api/v1/unique-tournament/{unique_tournament.id}/season/{season.id}/standings/home')
47
+ standings = response['standings'][0]
48
+ return Standings(**standings)
@@ -0,0 +1,16 @@
1
+ from aiohttp import ClientResponse
2
+
3
+
4
+ class ResponseParseContentError(Exception):
5
+ def __init__(self,response:ClientResponse,path:str):
6
+ self._response = response
7
+ self._path = path
8
+ @property
9
+ def response(self):
10
+ return self._response
11
+
12
+ def __str__(self):
13
+ return ('Response processing error:\n'
14
+ f'api call: {self._path}'
15
+ f'response status:{self._response.status}'
16
+ f'response content:{self._response.content}')