-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_trek.py
54 lines (42 loc) · 1.94 KB
/
generate_trek.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
"""Trekpedia JSON.
Produce JSON dumps of Star Trek data suitable for adding to an API.
"""
import sys
import colorama
from rich import print # pylint: disable=redefined-builtin
from lib.trekpedia import Trekpedia
MAIN_URL = "https://en.wikipedia.org/wiki/Star_Trek"
JSON_TEMPLATE = "output/star_trek_series_{}_{}_episodes.json"
# ---------------------------------------------------------------------------- #
# Main Code #
# ---------------------------------------------------------------------------- #
def main(_args):
"""Run the main program, parse and save data from Wikipedia."""
try:
trekpedia = Trekpedia(summary_url=MAIN_URL, json_template=JSON_TEMPLATE)
colorama.init()
print(
"Trekpedia : Parse '[cyan]Star Trek[/cyan]' "
"data from the Web and save as JSON.\n"
)
print("\u00a9 2023 Grant Ramsay <grant@gnramsay.com>\n")
print(f"Version {trekpedia.version}\n")
# ---- get the series info and save to a JSON file for later use. ---- #
print("Getting Series Data ... ", end="")
trekpedia.get_series_info()
trekpedia.save_json(
"output/star_trek_series_info.json", trekpedia.series_data
)
print("Done!\n")
# ----------- loop through each series and parse then save ----------- #
for series_data in trekpedia.series_data.items():
if series_data[0] not in [11]:
trekpedia.parse_series(series_data)
except KeyboardInterrupt:
print("\r", " " * 80)
print("[red][bold]Escape Pressed, processing ABORTED.\n")
# ---------------------------------------------------------------------------- #
# Actually run our code, unless we have been imported #
# ---------------------------------------------------------------------------- #
if __name__ == "__main__":
main(sys.argv[1:])