Skip to content

Commit

Permalink
Skip updates of page slugs, all mappings and tracked mappings if dail…
Browse files Browse the repository at this point in the history
…y data has already been fetched
  • Loading branch information
woctezuma committed Mar 12, 2024
1 parent 49d9ac6 commit 50a07d0
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions fetch_mappings_for_today.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from src.discord_utils import post_slugs_to_discord
from src.download_utils import download_page_slugs
from src.json_utils import load_json, save_json
from src.time_utils import get_fname_for_today
from src.webhook_utils import (
WEBHOOK_KEYWORD_LATE_TROPHY,
WEBHOOK_KEYWORD_NEW,
Expand All @@ -16,32 +17,36 @@
def main() -> None:
logging.getLogger('backoff').addHandler(logging.StreamHandler())

force_update = True

if force_update or not Path(PAGE_SLUGS_FNAME).exists():
print('Updating page slugs.')
page_slugs = download_page_slugs(include_dlc=False)
save_json(sorted(page_slugs), PAGE_SLUGS_FNAME, prettify=True)
else:
page_slugs = load_json(PAGE_SLUGS_FNAME)

print('Updating all page mappings.')
new_game_slugs = update_all_page_mappings(page_slugs)
post_slugs_to_discord(new_game_slugs, webhook_keyword=WEBHOOK_KEYWORD_NEW)

print('Updating tracked page mappings.')
# First, for new game slugs in order to quickly post to Discord. This should find new tracked slugs in a short time.
new_tracked_game_slugs = update_tracked_page_mappings(new_game_slugs)
post_slugs_to_discord(
new_tracked_game_slugs,
webhook_keyword=WEBHOOK_KEYWORD_TROPHY,
)
# Second, for all the page slugs. This is less rewarding: there are many checks... and very few new tracked slugs!
new_tracked_game_slugs = update_tracked_page_mappings(page_slugs)
post_slugs_to_discord(
new_tracked_game_slugs,
webhook_keyword=WEBHOOK_KEYWORD_LATE_TROPHY,
)
daily_data_fname = get_fname_for_today()
daily_data_has_already_been_fetched = Path(daily_data_fname).exists()

if not daily_data_has_already_been_fetched:
force_update = True

if force_update or not Path(PAGE_SLUGS_FNAME).exists():
print('Updating page slugs.')
page_slugs = download_page_slugs(include_dlc=False)
save_json(sorted(page_slugs), PAGE_SLUGS_FNAME, prettify=True)
else:
page_slugs = load_json(PAGE_SLUGS_FNAME)

print('Updating all page mappings.')
new_game_slugs = update_all_page_mappings(page_slugs)
post_slugs_to_discord(new_game_slugs, webhook_keyword=WEBHOOK_KEYWORD_NEW)

print('Updating tracked page mappings.')
# First, for new game slugs in order to quickly post to Discord. This should find new tracked slugs in a short time.
new_tracked_game_slugs = update_tracked_page_mappings(new_game_slugs)
post_slugs_to_discord(
new_tracked_game_slugs,
webhook_keyword=WEBHOOK_KEYWORD_TROPHY,
)
# Second, for all the page slugs. This is less rewarding: there are many checks... and very few new tracked slugs!
new_tracked_game_slugs = update_tracked_page_mappings(page_slugs)
post_slugs_to_discord(
new_tracked_game_slugs,
webhook_keyword=WEBHOOK_KEYWORD_LATE_TROPHY,
)


if __name__ == '__main__':
Expand Down

0 comments on commit 50a07d0

Please sign in to comment.