amosbastian / understat Goto Github PK
View Code? Open in Web Editor NEWAn asynchronous Python package for https://understat.com/.
License: MIT License
An asynchronous Python package for https://understat.com/.
License: MIT License
test_get_league_results_with_options() includes:
assert len(results) > 0
Which is not true when there are no unplayed fixtures in a season
local variable 'match' referenced before assignment
This is a frequent issue across many of the functions - it occurs for a lot of the examples.
Would it be possible to add a new function to your package that allows you to pull all the events that happen in a match (and their corresponding times), which is essentially substitutions and cards? Doesn't seem to be supported with any of your current functions.
The example in the readme is not updated and still uses the get_players
method which is not available anymore in the master branch.
Steps to reproduce:
pip install understat
I get the following error:
Traceback (most recent call last):
File "test.py", line 18, in <module>
loop.run_until_complete(main())
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "test.py", line 12, in main
data = await understat.get_players("epl", 2019, {"team_title": "Manchester United"})
AttributeError: 'Understat' object has no attribute 'get_players'
Works fine with version 0.1.0 though
import asyncio
import json
import aiohttp
from understat import Understat
async def main():
async with aiohttp.ClientSession() as session:
understat = Understat(session)
data = await understat.get_league_players("epl", 2018, {"team_title": "Manchester United"})
print(json.dumps(data))
if name == "main":
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())
runfile('D:/undesstattest.py', wdir='D:')
Traceback (most recent call last):
File "D:\undesstattest.py", line 19, in
loop.run_until_complete(main())
File "D:\anaconda3\lib\asyncio\base_events.py", line 623, in run_until_complete
self._check_running()
File "D:\anaconda3\lib\asyncio\base_events.py", line 585, in _check_running
raise RuntimeError(
RuntimeError: Cannot run the event loop while another loop is running
The script is running on Anaconda through Spyder. Am I doint something wrong? Many tks.
Greetings! The functions involving fixtures don't seem to be working. I'm running the standard code
import asyncio
import json
import nest_asyncio
import aiohttp
from understat import Understat
async def main():
async with aiohttp.ClientSession() as session:
understat = Understat(session)
fixtures= await understat.get_team_fixtures("Bayern Munich", 2022)
clubmatches=json.dumps(fixtures, indent=4, ensure_ascii=False)
print(clubmatches)
if name == "main":
nest_asyncio.apply()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())
The result is an empty list [] with no error message. I've tried also with the standard example (Manchester United, 2018). Other functions involving fixtures are giving the same result back.
I'm running the script on Anaconda, Spyder, Windows OS, Python 3.9.16. Other functions work fine. Many thanks and best regards,
Currently, there are certain match stats that you cannot retrieve from the get_league_results endpoint. They live on the match endpoint under the stats tab (or match_stats in the source code).
e.g. See stats tab on this https://understat.com/match/22073
Pretty simple change
I got a run time error which is : This event loop is already running.
My code is:
`async def main():
async with aiohttp.ClientSession() as session:
understat = Understat(session)
results = await understat.get_team_results(
"Levante",
2019,
side="a"
)
print(json.dumps(results))
if name == "main":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())`
BeautifulSoup is quite a heavyweight package to be just grabbing one JSON variable from the page. Lxml might be quicker or since understat.com is pretty well-formed you could even treat the whole document as a string and just search for the <script> tag.
I'm happy to do this and submit it as a PR if you agree it's worthwhile
Since today or yesterday it's no longer possible to get data from understat.com.
The package throws NoneType errors. For me it looks like the website changed the structure a bit and
the scraping is no longer working.
Here's the code example I used with Juypter notebooks:
import asyncio
import json
import pandas as pd
import aiohttp
from understat import Understat
lst_leagues = [
"bundesliga"
,"la_liga"
,"serie_a"
,"ligue_1"
,"rfpl"
,"EPL"
]
lst_seasons = [
{"param_season" : "2020", "directory_season" : "2020_21"}
]
async def load_fixtures(league, season):
async with aiohttp.ClientSession() as session:
understat = Understat(session)
fixtures = await understat.get_league_results(
league,
season["param_season"]
)
df_fixtures = pd.DataFrame(fixtures)
await session.close()
return df_fixtures
for league in lst_leagues:
for season in lst_seasons:
df_fixtures = await load_fixtures(league, season)
Include the condo packages as another package distribution.
I use
understat.get_league_results("Bundesliga",2019,)
to get the results. How can I set options to only get the previous week?
It would be useful to be able to apply the filters on the tables in understat. For example, on a team's page, there is a players table. This table can be filtered by start date and end date, giving you the stats for the players in a particular period of time.
Options which would apply these filters when fetching the data would be super useful.
Firstly, thanks for the brilliant package!
Would it be possible to pull additional match data (i.e. all the fields found on the 'stats' tab of a match page) from Understat, either as a a new standalone function, or adding the additional data into results that are pulled through from the 'Understat.get_league_results' function?
So we would get all the following data for each match: CHANCES, GOALS, xG, SHOTS, SHOTS ON TARGET, DEEP, PPDA, xPTS
Many thanks.
Hi! Is it possible to filter the get_team_players result by date/game week? On the website I can see you can filter the result by start and end date, but not sure how to do that with the API.
Matteo
Add a basic CI/CD pipeline to ensure the quality of the code.
Initial steps:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.