Skip to main content

grab soccer data and build databases

Project description

footystats

Install with:

pip install footystats

Description

This package contains two major functions:

  1. Build sources from www.worldfootball.net
  2. 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

  1. Premier LeagueLeagues.PREMIERLEAGUE
  2. La LigaLeagues.LALIGA
  3. Ligue 1Leagues.LIGUE1
  4. BundesligaLeagues.BUNDESLIGA
  5. Serie ALeagues.SERIEA
  6. ChampionshipLeagues.CHAMPIONSHIP
  7. La Liga 2Leagues.LALIGA2
  8. Ligue 2Leagues.LIGUE2
  9. 2. BundesligaLeagues.BUNDESLIGA2
  10. Serie BLeagues.SERIEB
  11. Primeira LigaLeagues.PRIMEIRALIGA
  12. EredivisieLeagues.EREDIVISIE
  13. All LeaguesLeagues.ALL

(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

footystats-0.2.1.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

footystats-0.2.1-py3-none-any.whl (2.9 MB view details)

Uploaded Python 3

File details

Details for the file footystats-0.2.1.tar.gz.

File metadata

  • Download URL: footystats-0.2.1.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

Hashes for footystats-0.2.1.tar.gz
Algorithm Hash digest
SHA256 57e36da89b3ccd0394d8e43eb5f9258c201c402a665b25a0ce4b6b718443a937
MD5 8726cb4afe0ba4bc4e6c92a3f3cc8329
BLAKE2b-256 83b2ec85a239fe9823ffaa6961f9575b1b0c04e4931cfcabadf5206eef62acff

See more details on using hashes here.

File details

Details for the file footystats-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: footystats-0.2.1-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

Hashes for footystats-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1178eb58509e62c059231ce488a33c607dc62aa5236e406fc74b435d998dfb83
MD5 4114650e267989a4cc203414a74145c8
BLAKE2b-256 beb5e65a15f03a0d9d2fbc31b0ce8ff3ce0dcf1d4d56880512baf5afa1f3a113

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page