-
Notifications
You must be signed in to change notification settings - Fork 1
/
rguide
executable file
·77 lines (60 loc) · 2.19 KB
/
rguide
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import argparse
import json
from oglaf import knowledge
parser = argparse.ArgumentParser(description='Build an Oglaf reading guide based on tags.')
parser.add_argument('-tag', action='append', metavar='tag', default=None,
help='Tag to search for, can be specified more than once (logical AND)')
parser.add_argument('-arc', action='store', metavar='arc', default=None,
help='Story arc to search for')
args = parser.parse_args()
if args.tag is None and args.arc is None:
parser.print_help()
quit()
tome = knowledge.TomeOfKnowledge()
# Generate list of titles containing all tags
titles = list()
for title in tome.titles.keys():
matched_all = True
if args.tag is not None:
for tag in args.tag:
ltag = tag.lower()
if ltag in tome.lctags.keys():
proper_tag = tome.lctags[ltag]
if proper_tag not in tome.titles[title]['tags']:
matched_all = False
break
else:
matched_all = False
break
else:
larc = args.arc.lower()
if larc in tome.lcarcs.keys():
proper_arc = tome.lcarcs[larc]
if proper_arc not in tome.titles[title]['arcs']:
matched_all = False
else:
matched_all = False
if matched_all:
titles.append(title)
# Generate URL list in ascending order based on title list
reading_list = dict()
for title in titles:
order = tome.titles[title]['publishOrder']
reading_list[order] = dict()
reading_list[order]['title'] = title
reading_list[order]['urls'] = tome.titles[title]['urls']
# Print results
if args.tag is not None:
print("You're searching for tags: {}".format(', '.join(args.tag)))
else:
print("You're searching for arc: {}".format(args.arc))
if len(reading_list) == 0:
print("Sorry, there are no titles matching your criteria.")
quit()
print("The following list shows the titles and URLs for matching strips, in publication date order. Enjoy!\n")
for entry in sorted(reading_list.keys()):
print(reading_list[entry]['title'])
for url in reading_list[entry]['urls']:
print("\t" + url)
print()