Comments (3)
I'm not sure how Understat does this specifically but they probably do something like this:
import asyncio
import datetime
import json
import aiohttp
from dateutil.parser import parse
from understat import Understat
def get_latest_week_results(results, week):
latest_results = [
result for result in results
if parse(result["datetime"]).date().isocalendar()[1] == week]
if not latest_results:
return get_latest_week_results(results, week - 1)
return latest_results
async def main():
async with aiohttp.ClientSession() as session:
understat = Understat(session)
results = await understat.get_league_results("Bundesliga", 2019)
current_week = datetime.datetime.now().isocalendar()[1]
print(json.dumps(get_latest_week_results(results, current_week), indent=4))
if __name__ == "__main__":
asyncio.run(main())
I mean, it's basically the same thing as above, but it just uses the week number instead. It always gets the latest results, which is what I think you want. To get the next fixtures they'd probably have a similar function to get_latest_week_results
, but the other way around (and using fixtures instead of results), which executes when someone clicks the buttons.
from understat.
You'd have to filter the results list by certain dates yourself. Something like this should do the trick:
import asyncio
import datetime
import json
import aiohttp
from dateutil.parser import parse
from understat import Understat
def previous_week_range(date):
start_date = date + datetime.timedelta(-date.weekday(), weeks=-1)
end_date = date + datetime.timedelta(-date.weekday() - 1)
return start_date, end_date
async def main():
date_one, date_two = previous_week_range(datetime.date.today())
async with aiohttp.ClientSession() as session:
understat = Understat(session)
results = await understat.get_league_results("Bundesliga", 2019)
filtered_results = [result for result in results
if parse(result["datetime"]).date() >= date_one and
parse(result["datetime"]).date() <= date_two]
print(json.dumps(filtered_results, indent=4))
if __name__ == "__main__":
asyncio.run(main())
from understat.
But this only works if the last matchday was a week before 😄
So if we have a break for national games (like atm) it doesn't work anymore 😢
If I look at understat they also filter there data and only show "current matchday" and some buttons to switch prev and next. How do they do this? Is there any list "this matchday contains the following games: id1, id2, id3.." so that I can get this list and every single game?
from understat.
Related Issues (17)
- Pulling Match Events Other Than Goals HOT 4
- Apply filters on tables HOT 1
- run time error HOT 5
- Pull additional data for each match HOT 5
- UnboundLocalError
- Possible to filter get_team_players result by date/game week? HOT 1
- feat: Building Conda Packages
- ci: Create Basic CI/CD pipeline using Github Actions
- 'NoneType' object has no attribute 'group' HOT 5
- Example in the readme is not working HOT 1
- Possible issue on Anaconda HOT 4
- Fixtures not working? HOT 1
- Add endpoint for individual match stats
- Replace BeautifulSoup with lxml or similar
- Tests don't all pass off-season HOT 1
- error messages HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from understat.