-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch_data_for_today.py
50 lines (41 loc) · 1.57 KB
/
fetch_data_for_today.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import logging
from pathlib import Path
from src.data_filters import (
hide_games_missing_a_stat,
hide_games_with_buggy_achievements,
hide_games_with_inconsistent_stats,
hide_games_with_zero_player,
)
from src.data_utils import (
load_tracked_page_mappings,
populate_rating_counts,
populate_slugs,
)
from src.export_utils import write_markdown_files
from src.fetch_utils import fetch_data_for_several_ids
from src.json_utils import load_json, save_json
from src.time_utils import get_fname_for_today
def main() -> None:
logging.getLogger('backoff').addHandler(logging.StreamHandler())
output_fname = get_fname_for_today()
Path(output_fname).parent.mkdir(parents=True, exist_ok=True)
requires_to_download_json = not Path(output_fname).exists()
requires_to_update_markdown = requires_to_download_json
if requires_to_download_json:
print('Updating JSON.')
sandbox_ids_dict = load_tracked_page_mappings()
data = fetch_data_for_several_ids(sandbox_ids=sandbox_ids_dict.values())
save_json(data, output_fname, prettify=True, indent=2)
else:
data = load_json(output_fname)
if requires_to_update_markdown:
print('Updating Markown.')
data = populate_slugs(data)
data = populate_rating_counts(data)
data = hide_games_missing_a_stat(data)
data = hide_games_with_inconsistent_stats(data)
data = hide_games_with_zero_player(data)
data = hide_games_with_buggy_achievements(data)
write_markdown_files(data)
if __name__ == '__main__':
main()