This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmangler.py
executable file
·48 lines (42 loc) · 1.55 KB
/
mangler.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
#!/usr/bin/env python3
import csv
import pprint
def main():
register = []
prepositions = {}
with open('postal-name-prepositions.txt', 'r') as prepositionfile:
prepositionreader = csv.reader(prepositionfile, delimiter='=')
for row in prepositionreader:
if len(row) >= 2:
prepositions[row[0]] = row[1].capitalize()
with open('Postnummerregister-utf8.txt', 'r') as registerfile:
registerreader = csv.reader(registerfile, delimiter='\t')
for row in registerreader:
prep = prepositions.get(row[1], "Ukjent")
register.append({
'postnummer': row[0],
'poststed': row[1],
'kommunekode': row[2],
'kommunenavn': row[3],
'kategori': row[4],
'preposisjon': prep,
})
print("module Stedsdata where\n\nimport Sted\n\nsteder :: [Sted]\nsteder = [")
outputlines = []
for s in register:
text = " Sted {postnummer} \"{poststed}\" {kommunekode} \"{kommunenavn}\" {kategori} {preposisjon},".format(
postnummer=s['postnummer'],
poststed=s['poststed'],
kommunekode=s['kommunekode'],
kommunenavn=s['kommunenavn'],
kategori=s['kategori'],
preposisjon=s['preposisjon'],
)
outputlines.append(text)
outputlines[-1] = outputlines[-1][:-1]
for i in outputlines:
print(i)
print(" ]")
# pprint.pprint(prepositions)
if __name__ == '__main__':
main()