-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
114 lines (94 loc) · 2.67 KB
/
__main__.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import requests
import click
import textwrap
import random
import re
width = 0
TO_REPLACE = [
"CDU / CSU",
"CDU/CSU",
r"/(?:<!(Europäischen|Europäische) )Union/",
"CDU und CSU",
"CDU",
"CSU",
"Freie Demokraten",
"Liberalen",
"Liberale",
"FDP",
"BÜNDNIS 90 / DIE GRÜNEN",
"BÜNDNIS 90/DIE GRÜNEN",
"Grünen",
"PIRATENpartei",
"alternative für deutschland",
"Die Linken",
"Die Linke",
"Linken",
"Linke",
"Die Linkspartei.PDS",
"unionsgeführten Regierungen",
"SPD",
"CDU/CSU",
"GRÜNE",
"FDP",
"PIRATEN",
"DIE LINKE",
"NPD",
"Die PARTEI",
"AfD",
]
def replace_string_to_regex(replace_string):
if replace_string.startswith("/") and replace_string.endswith("/"):
return re.compile(replace_string[1:-1], re.IGNORECASE)
return re.compile(re.escape(replace_string), re.IGNORECASE)
TO_REPLACE = list(map(replace_string_to_regex, TO_REPLACE))
def wrap_print(content, indent=0):
global width
print(
textwrap.indent(
textwrap.fill(content, (width if width else 80) - indent), " " * indent
)
)
@click.command()
def main():
global width
width = click.get_terminal_size()[0]
while True:
click.clear()
# see https://stackoverflow.com/a/26445590 for color codes
print(
"Wilkommen zu ParteiDuell "
+ "\033[31mK\033[0m\033[33ml\033[0m\033[93m"
+ "\033[32mi\033[0m\033[34me\033[0m\033[35mh\033[0m"
)
print("")
r = requests.get("https://api.parteiduell.de/list")
json = r.json()[0]
wrap_print(json["these"])
print()
statement = random.choice(list(json["possibleAnswers"].keys()))
for replace_regex in TO_REPLACE:
json["possibleAnswers"][statement] = replace_regex.sub(
"█████", json["possibleAnswers"][statement]
)
print(json["possibleAnswers"][statement])
keys = list(json["possibleAnswers"])
print(", ".join(f"{i}: {answer}" for i, answer in enumerate(keys)))
party = input("> ")
try:
party = int(party)
party = keys[party]
except ValueError as error:
print(error)
print()
print()
if statement == party:
print("Richtig!")
else:
print(f"Falsch, diese Aussage war von {statement}")
print()
print(f"Die Partei {party} hat folgendes Statement abgegeben:\n")
wrap_print(json["possibleAnswers"][party], indent=4)
print()
click.pause()
if __name__ == "__main__":
main()