From 320f6913f24e05560c46a161fed6cd0f50ddf6b6 Mon Sep 17 00:00:00 2001 From: Rajesh Dawadi Date: Thu, 30 Apr 2026 11:00:51 -0700 Subject: [PATCH] Rename understatdb to footballdb, understat.py to scraper.py --- {understatdb => footballdb}/__init__.py | 2 +- {understatdb => footballdb}/_nbdev.py | 4 +- {understatdb => footballdb}/cli.py | 48 +++++++++---------- {understatdb => footballdb}/db.py | 2 +- .../understat.py => footballdb/scraper.py | 6 +-- settings.ini | 6 +-- 6 files changed, 34 insertions(+), 34 deletions(-) rename {understatdb => footballdb}/__init__.py (77%) rename {understatdb => footballdb}/_nbdev.py (88%) rename {understatdb => footballdb}/cli.py (79%) rename {understatdb => footballdb}/db.py (98%) rename understatdb/understat.py => footballdb/scraper.py (95%) diff --git a/understatdb/__init__.py b/footballdb/__init__.py similarity index 77% rename from understatdb/__init__.py rename to footballdb/__init__.py index 650d5ae..d2f1b75 100644 --- a/understatdb/__init__.py +++ b/footballdb/__init__.py @@ -2,5 +2,5 @@ from . import ( db, - understat + scraper ) diff --git a/understatdb/_nbdev.py b/footballdb/_nbdev.py similarity index 88% rename from understatdb/_nbdev.py rename to footballdb/_nbdev.py index 5253355..d15b11b 100644 --- a/understatdb/_nbdev.py +++ b/footballdb/_nbdev.py @@ -25,8 +25,8 @@ "db.py", "understat.py"] -doc_url = "https://torvaney.github.io/understatdb/" +doc_url = "https://torvaney.github.io/footballdb/" -git_url = "https://github.com/torvaney/understatdb/tree/master/" +git_url = "https://github.com/torvaney/footballdb/tree/master/" def custom_doc_links(name): return None diff --git a/understatdb/cli.py b/footballdb/cli.py similarity index 79% rename from understatdb/cli.py rename to footballdb/cli.py index 659432c..359af29 100644 --- a/understatdb/cli.py +++ b/footballdb/cli.py @@ -16,7 +16,7 @@ import pyprojroot import typer -import understatdb +import footballdb # Cell @@ -40,7 +40,7 @@ def __call__(self, *args, **kwargs): def initialize_db(): """ Load database config from environment and initialise - `understatdb.db.DB` with a database connection. + `footballdb.db.DB` with a database connection. """ # Load database config from environment @@ -54,7 +54,7 @@ def initialize_db(): # Configure proxy database to use configured postgres typer.secho('Initialising database connection...', fg=typer.colors.BRIGHT_BLACK) - understatdb.db.DB.initialize(postgres_db) + footballdb.db.DB.initialize(postgres_db) # Cell @@ -71,8 +71,8 @@ def migrate(interactive: bool = True): # Migrate database tables typer.secho('Migrating database tables...', fg=typer.colors.BRIGHT_BLACK) - understatdb.db.DB.evolve( - ignore_tables=understatdb.db.EVOLVE_IGNORE_TABLES + dbt_tables, + footballdb.db.DB.evolve( + ignore_tables=footballdb.db.EVOLVE_IGNORE_TABLES + dbt_tables, interactive=interactive ) typer.secho('Done!', fg=typer.colors.GREEN, bold=True) @@ -105,7 +105,7 @@ def build_tables(args: typing.List[str] = typer.Option([], help='Additional argu # Use the list of league *values* (i.e. strings) so that the help text shows # all the possible inputs the user can use -_DEFAULT_INGEST_LEAGUES = [l.value for l in understatdb.understat.League] +_DEFAULT_INGEST_LEAGUES = [l.value for l in footballdb.scraper.League] _DEFAULT_INGEST_SEASONS = list(range(2014, 2021)) @@ -115,29 +115,29 @@ def ingest( leagues: typing.List[str] = typer.Option( _DEFAULT_INGEST_LEAGUES, help='Leagues to import', - callback=lambda xs: [understatdb.understat.League(x) for x in xs] + callback=lambda xs: [footballdb.scraper.League(x) for x in xs] ), seasons: typing.List[int] = typer.Option( _DEFAULT_INGEST_SEASONS, help='Seasons to import (by start year)' ), ): - """ Ingest match and shot data from Understat.com """ + """ Ingest match and shot data """ initialize_db() - client = understatdb.understat.Understat() + client = footballdb.scraper.FootballScraper() for league, season in itertools.product( - [understatdb.understat.League(l) for l in leagues], + [footballdb.scraper.League(l) for l in leagues], seasons ): # Add league & season to DB - with understatdb.db.DB.atomic(): - db_league, _ = understatdb.db.League.get_or_create(name=league.value) - db_season, _ = understatdb.db.Season.get_or_create(name=season) + with footballdb.db.DB.atomic(): + db_league, _ = footballdb.db.League.get_or_create(name=league.value) + db_season, _ = footballdb.db.Season.get_or_create(name=season) # Check if a record for this league and season already exists. If so, skip it. - existing_record = understatdb.db.Matches.get_or_none( + existing_record = footballdb.db.Matches.get_or_none( league_id=db_league.id, season_id=db_season.id ) @@ -151,23 +151,23 @@ def ingest( # Add match and shot data to DB typer.secho(f'Ingesting data for {league.value}, {season}', fg=typer.colors.BLUE) - with understatdb.db.DB.atomic(): + with footballdb.db.DB.atomic(): # Fetch match data from understat matches = client.matches(league, season) # Delete any old match data if refresh: - understatdb.db.Matches.delete().where( - (understatdb.db.Matches.league_id==db_league.id) & - (understatdb.db.Matches.season_id==db_season.id) + footballdb.db.Matches.delete().where( + (footballdb.db.Matches.league_id==db_league.id) & + (footballdb.db.Matches.season_id==db_season.id) ).execute() - db_matches = understatdb.db.Matches.create( + db_matches = footballdb.db.Matches.create( league_id=db_league.id, season_id=db_season.id, json=matches, - version=understatdb.__version__ + version=footballdb.__version__ ) with typer.progressbar(matches, label="Shots") as progress: @@ -187,14 +187,14 @@ def ingest( # Delete any old shots data if refresh: - understatdb.db.Shots.delete().where( - understatdb.db.Shots.match_id==match_id + footballdb.db.Shots.delete().where( + footballdb.db.Shots.match_id==match_id ).execute() - db_shots = understatdb.db.Shots.create( + db_shots = footballdb.db.Shots.create( match_id=match_id, json=shots, - version=understatdb.__version__ + version=footballdb.__version__ ) # Rebuild tables in dbt diff --git a/understatdb/db.py b/footballdb/db.py similarity index 98% rename from understatdb/db.py rename to footballdb/db.py index 47aff66..cee7d32 100644 --- a/understatdb/db.py +++ b/footballdb/db.py @@ -30,7 +30,7 @@ def prefixed_snake_case(prefix, cls): @evolve_ignore class BaseModel(peewee.Model): """ - A model for base (json) data from Understat + A model for base (json) football match data """ class Meta: database = DB diff --git a/understatdb/understat.py b/footballdb/scraper.py similarity index 95% rename from understatdb/understat.py rename to footballdb/scraper.py index 14af925..1e78dd8 100644 --- a/understatdb/understat.py +++ b/footballdb/scraper.py @@ -36,7 +36,7 @@ def extract_json(soup, json_var): # 'Competition' might be a better name, but let's stick with understat's terminology class League(enum.Enum): """ - Understat leagues + Football leagues """ EPL = 'EPL' LA_LIGA = 'La_Liga' @@ -47,9 +47,9 @@ class League(enum.Enum): # Cell -class Understat: +class FootballScraper: """ - Fetches understat data webpages + Fetches football data webpages """ def __init__(self, base_url: str='https://understat.com'): diff --git a/settings.ini b/settings.ini index 17b3838..9dcc4b6 100644 --- a/settings.ini +++ b/settings.ini @@ -1,8 +1,8 @@ [DEFAULT] # All sections below are required unless otherwise specified host = github -lib_name = understatdb -repo_name = understat-db +lib_name = footballdb +repo_name = football-postgres user = torvaney description = An extendable project for creating a database of soccer data @@ -39,7 +39,7 @@ dev_requirements = nbdev console_scripts = - understat-db=understatdb.cli:app + football-postgres=footballdb.cli:app # Optional. Same format as setuptools dependency-links # dep_links =