-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
59 lines (47 loc) · 1.38 KB
/
demo.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
51
52
53
54
55
56
57
58
59
import json
import textwrap
from datetime import datetime
from collections import Counter
import click
from prettytable import PrettyTable # type: ignore[import]
tw = textwrap.TextWrapper(width=25, drop_whitespace=True, max_lines=2)
def ach_stats(ach):
count = 0
for a in ach:
if a["progress"]["unlocked"]:
count += 1
return "{}/{}".format(count, len(ach))
def most_achieved_in(ach):
dates = []
for a in ach:
if a["progress"]["unlocked"]:
dates.append(datetime.fromtimestamp(a["progress"]["data"]).year)
c = Counter(dates)
if len(c):
return c.most_common(1)[0][0]
else:
return "----"
@click.command()
@click.option(
"--from-file",
type=click.Path(exists=True),
required=True,
help="File that contains the HTML dumps",
)
def main(from_file: str) -> None:
with open(from_file, "r") as fj:
parsed_data = json.load(fj)
p_table = PrettyTable()
p_table.field_names = ["Name", "Hours", "Achievements", "Most In"]
for _, game_data in parsed_data.items():
p_table.add_row(
[
"\n".join(tw.wrap(game_data["name"])),
game_data["hours"],
ach_stats(game_data["achievements"]),
most_achieved_in(game_data["achievements"]),
]
)
print(p_table)
if __name__ == "__main__":
main()