-
Notifications
You must be signed in to change notification settings - Fork 7
/
protokolle.py
executable file
·94 lines (73 loc) · 3.03 KB
/
protokolle.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
#!/usr/bin/env python3
"""
Measure how many protocols are published for the meetings of the
Berzirksausschüsse in Munich using the OParl API of München Transparent
This is meant to be very simple, so the cache won't see any update on the
server (yet). If you want to include updates from the server, delete the cache
folder.
## Usage
Clone https://github.com/oparl/spec. Then run
```
python3 protokolle.py --schema /path/to/oparl/schema --cache /some/path/for/the/cache
```
## NOTE
This is not a scientific study but an example for using the OParl API, so
the numbers are a bit sloppy.
"""
import argparse
from oparl_cache import OParlCache
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--entrypoint", default="https://www.muenchen-transparent.de/oparl/v1.0/list/body")
parser.add_argument("--schema", default="/home/konsti/oparl/schema")
parser.add_argument("--cache", default="/home/konsti/cache-python")
args = parser.parse_args()
cacher = OParlCache(args.entrypoint, args.schema, args.cache, True)
bodies = cacher.get_from_cache(args.entrypoint)
bodies.pop(0) # Remove the Stadtrat
bezirkausschuesse_stats = []
for ba in bodies:
meetings = cacher.get_from_cache(ba["meeting"])
total = 0
good = 0
bad = 0
undecided = 0
for meeting in meetings:
# Exclude minor meetings
if "UA" in meeting["name"]:
continue
assert "Vollgremium" in meeting["name"], meeting["name"]
# Exclude the future and the near present
if meeting["start"][0:4] == "2017":
continue
elif meeting["start"][0:4] == "2016" and int(meeting["start"][5:7]) >= 10:
continue
total += 1
for fileurl in meeting["auxiliaryFile"]:
file = cacher.get_from_cache(fileurl)
name = file["name"]
good_words = ["protokol", "Protokoll", "Niederschrift", "Prot"]
bad_words = ["Einladung", "Nachtrag", "nachtrag", "Anwesenheitsliste", "Tagesordnung", "TO ", "to-",
"Ladung"]
if any(x in name for x in good_words): # good
good += 1
break
elif any(x in name for x in bad_words): # bad
pass
else: # ugly
# print("Unklar: {}".format(name))
undecided += 1
break
else:
bad += 1
assert total == good + bad + undecided
line = [ba["shortName"][3:], total, good, bad, undecided, int(good * 100 / total)]
bezirkausschuesse_stats.append(line)
format_string = "{:3} | {:5} | {:4} | {:3} | {:4} | {:4}"
print(format_string.format("BA", "Total", "Good", "Bad", "Ugly", "Score"))
print("-" * 41)
format_string += "%" # The score is in percent
for line in bezirkausschuesse_stats:
print(format_string.format(*line))
if __name__ == '__main__':
main()