Git Product home page Git Product logo

understat's Introduction

A Python package for https://understat.com/.

Join the Discord server or submit an issue for help and / or suggestions!

Installing understat

The recommended way to install understat is via pip.

pip install understat

To install it directly from GitHub you can do the following:

git clone git://github.com/amosbastian/understat.git

You can also install a .tar file or .zip file

curl -OL https://github.com/amosbastian/understat/tarball/master
curl -OL https://github.com/amosbastian/understat/zipball/master # Windows

Once it has been downloaded you can easily install it using pip:

cd understat
pip install .

Usage

An example of using understat can be found below:

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())

Contributing

  1. Fork the repository on GitHub.
  2. Run the tests with pytest tests/ to confirm they all pass on your system. If the tests fail, then try and find out why this is happening. If you aren't able to do this yourself, then don't hesitate to either create an issue on GitHub, or send an email to [email protected].
  3. Either create your feature and then write tests for it, or do this the other way around.
  4. Run all tests again with with pytest tests/ to confirm that everything still passes, including your newly added test(s).
  5. Create a pull request for the main repository's master branch.

Documentation

Documentation and examples for understat can be found at http://understat.readthedocs.io/en/latest/.

understat's People

Contributors

ahorn639 avatar amosbastian avatar chrismusson avatar gracjans avatar paguos avatar tyketchum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

understat's Issues

run time error

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())`

Example in the readme is not working

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
  • run the example

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

'NoneType' object has no attribute 'group'

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)

UnboundLocalError

local variable 'match' referenced before assignment

This is a frequent issue across many of the functions - it occurs for a lot of the examples.

Replace BeautifulSoup with lxml or similar

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

Apply filters on tables

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.

Tests don't all pass off-season

test_get_league_results_with_options() includes:

assert len(results) > 0

Which is not true when there are no unplayed fixtures in a season

Pulling Match Events Other Than Goals

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.

Pull additional data for each match

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.

Only last week

I use

understat.get_league_results("Bundesliga",2019,) 

to get the results. How can I set options to only get the previous week?

Fixtures not working?

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,

Possible issue on Anaconda

Hello! With...

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())


I get the following

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.