grab soccer data and build databases
Project description
footystats
Install with:
pip install footystats
Description
This package contains two major functions:
- Build sources from www.worldfootball.net
- Build database from the acquired sources
The available soccer leagues are listed in an Enum called Leagues.
This enum is used as an argument in many functions.
Supported Leagues
- Premier League –
Leagues.PREMIERLEAGUE - La Liga –
Leagues.LALIGA - Ligue 1 –
Leagues.LIGUE1 - Bundesliga –
Leagues.BUNDESLIGA - Serie A –
Leagues.SERIEA - Championship –
Leagues.CHAMPIONSHIP - La Liga 2 –
Leagues.LALIGA2 - Ligue 2 –
Leagues.LIGUE2 - 2. Bundesliga –
Leagues.BUNDESLIGA2 - Serie B –
Leagues.SERIEB - Primeira Liga –
Leagues.PRIMEIRALIGA - Eredivisie –
Leagues.EREDIVISIE - All Leagues –
Leagues.ALL
WORLDFOOTBALL
(1) BUILD SOURCES webscrapping from online sites
To obtain the sources, prepare a folder to save the sources (json) and use this path as argument as in the example below:
from footystats.leagues import Leagues
from footystats.sources import makeSources
sourcesRepertory="YOUR_PATH_TO_SOURCES"
makeSources(Leagues.LALIGA, sourcesRepertory)
makeSources(Leagues.ALL, sourcesRepertory)
be aware than the procedure to grab data use human-like behaviour to circumvent anti-bot protections from cloudflare. Then, browsers are called to fake a real user who would click.
You can load the sources using
from footystats.sources import loadSources
sources:dict = loadSources(Leagues.LALIGA,sourcesRepertory)
If you want to enrich the sources with more recent data:
from footystats.sources import updateSources
updateSources(Leagues.LALIGA,sourcesRepertory)
To look the produced sources, you can use a debug function that writes the json dict within.txt file (auto naming of the debug file) The debug file is exported in the current working directory from which the script is run.
from footystats.debug import debugDatabase
debugDatabase(Leagues.LALIGA, sources, startYear="2015")
this will write the sources from season 2015-2016
(2) BUILD DATABASE: post treatment of sources
If you have sources, you can proceed to build database. Databases are post-treated sources (json dict). You also need to establish a repertory where to save the databases if you use Leagues.ALL, all database leagues will be build. If debug is True, then the .txt files are also exported
from footystats.database import makeDatabase
mySavePathForDatabase:str="PATH_TO_DATABASES"
makeDatabase(Leagues.LALIGA, sourcesRepertory, mySavePathForDatabase,debug=True,debugYear="2020")
(3) Load the database and enjoy for your custom projects
from footystats.database import loadDatabase
my_database:dict = loadDatabase(Leagues.LALIGA,mySavePathForDatabase)
SOFASCORE
The part dealing with sofascore scrapping is consequent. The global aim is to obtain for each match in each season the team rating as well as the list of involved players. This is a long 2 step process:
(1) MAKE REGISTERS
First build a register (dictionnary) for each league to store the season schedules and most importantly the location of the match reports (key = "url") Since we simulate a human-behaviour web browsing, we need asynchronous functions. Thats why we use the asyncio lib.
import asyncio
from footystats.sofascore import makeMatchRegister
sofaroot_past =Path(r"D:\FOOTBALL\teams\past")
sofaroot_now =Path(r"D:\FOOTBALL\teams\current")
asyncio.run(makeMatchRegister(Leagues.ALL,path=sofaroot_past,current=False)) # False = for 5 previous seasons
asyncio.run(makeMatchRegister(Leagues.SERIEB,path=sofaroot_now,current=True)) # True = for current season
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file footystats-0.2.2.tar.gz.
File metadata
- Download URL: footystats-0.2.2.tar.gz
- Upload date:
- Size: 2.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d30e7724e5ab2263f4e7dddac16eed20129eb24ff087950deb87fb281031dd4
|
|
| MD5 |
d2fa8c3ffe831cae2566231efff2d412
|
|
| BLAKE2b-256 |
9cee5b9c6bd46e0e0ae0c556647c10f07a8a6b621f4bf8b2be0c284d70f670df
|
File details
Details for the file footystats-0.2.2-py3-none-any.whl.
File metadata
- Download URL: footystats-0.2.2-py3-none-any.whl
- Upload date:
- Size: 2.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87ea392176617df5c3a540f2c18518c689f86ff228415c293ddabf49a74cdbf9
|
|
| MD5 |
57a2f5f5cd4512c471560a5395f65bc0
|
|
| BLAKE2b-256 |
d9d25152352e4d6074662a6f70de98bd60be1c27af5cca37916957e4fc8e2b72
|