-
Notifications
You must be signed in to change notification settings - Fork 1
/
datadump.py
executable file
·78 lines (69 loc) · 2.39 KB
/
datadump.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import filedict
import json
from data import unis_dict
def pp(items):
fields = ['id', 'ip', 'first_name', 'last_name', 'email', 'nick_name', 'confirmed', 'time', 'university', 'university_alt', 'exkursion1', 'exkursion2', 'exkursion3', 'tshirt', 'food', 'arbeitskreise', 'notes']
pp_string = u"# " + u", ".join(fields) + u"\n"
for item in items:
key, item = item
try:
entries = []
for field in fields:
try:
entries.append(unicode(item[field]))
except KeyError:
entries.append(u'')
entries = [clean_csv_entry(entry) for entry in entries]
pp_string += u", ".join(entries) + u'\n'
except:
raise
#print "# Invalid entry with id " + key
#print "# " + json.dumps(item)
return pp_string
def registrants_by_university(items):
rbu = dict()
for item in items:
key, item = item
uni = item['university']
if uni and uni != u'n-i-l' and uni != u'b-w':
uni_code = item['university']
uni_name = unis_dict[uni_code]
elif item['university_alt']:
uni_code = item['university_alt']
uni_name = item['university_alt']
elif item['university']:
uni_code = u'-'
uni_name = u'ohne Uni'
try:
rbu[uni_name]
except:
rbu[uni_name] = []
rbu[uni_name].append(item)
return rbu
def pp_rbu(rbu):
pp_string = u"Anmeldungen pro Uni"
for key in rbu.keys():
print u"\nUni: {0}\n".format(key)
for item in rbu[key]:
print u"{0} {1}.".format(item['first_name'], item['last_name'][0])
def clean_csv_entry(text):
return text.replace(u',', u' ').replace(u'\n', u' ').replace(u'\r',' ')
def clean(dic):
for item in dic.items():
key, item = item
try:
item['id']
item['first_name']
item['last_name']
item['confirmed']
item['email']
except:
print u"missing field for entry with id " + key
print u"# " + json.dumps(item)
del dic[key]
if __name__ == "__main__":
d = filedict.FileDict(filename="data/anmeldungen.dict.sqlite")
print pp(d.items())
print pp_rbu(registrants_by_university(d.items()))