Skip to content

Commit

Permalink
scrape sports hall only for new or updated games
Browse files Browse the repository at this point in the history
  • Loading branch information
djbrown authored Mar 30, 2024
1 parent b85bcef commit de811e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/base/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def add_ranking_place(items: list, field: str):
item.place = previous.place


def scrape_game(game_row, league: League, sports_hall: SportsHall | None, ignore_list: list[int] | None = None):
def scrape_game(
game_row,
league: League,
ignore_list: list[int] | None = None,
processed_sports_halls: set[int] | None = None,
):
if ignore_list is None:
ignore_list = []

Expand All @@ -54,6 +59,13 @@ def scrape_game(game_row, league: League, sports_hall: SportsHall | None, ignore
report_number = parsing.parse_report_number(game_row[10])
forfeiting_team = parsing.parse_forfeiting_team(game_row[10], home_team, guest_team)

try:
sports_hall = scrape_sports_hall(game_row, processed=processed_sports_halls)
except Exception:
LOGGER.exception("Could not import Sports Hall")
if sports_hall is not None:
processed_sports_halls.add(sports_hall.bhv_id)

game = Game.objects.filter(number=number, league__season=league.season).first()
if game is None:
game = Game.objects.create(
Expand Down
5 changes: 1 addition & 4 deletions src/games/management/commands/import_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ def import_league(self, league: League):
game_rows = parsing.parse_game_rows(dom)
for game_row in game_rows:
try:
sports_hall = logic.scrape_sports_hall(game_row, processed=self.options["processed_sports_halls"])
if sports_hall is not None:
self.options["processed_sports_halls"].add(sports_hall.bhv_id)
logic.scrape_game(game_row, league, sports_hall, self.options["games"])
logic.scrape_game(game_row, league, self.options["games"], self.options["processed_sports_halls"])
except Exception:
LOGGER.exception("Could not import Game")

0 comments on commit de811e7

Please sign in to comment.