-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprocess-events.py
executable file
·137 lines (123 loc) · 3.94 KB
/
process-events.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
import re
import json
bands_add_the = [
'Adobe Brothers', 'Avant Gardeners', 'Canote Brothers',
'Contrarians', 'Dam Beavers', 'Engine Room', 'Faux Paws',
'Figments', 'Free Raisins', 'Gaslight Tinkers', 'JEMS',
'Latter Day Lizards', 'Mean Lids', 'Moving Violations',
"O'Schraves", 'Offbeats', 'Quarks',
'Red Mountain Yellowhammers', 'Rhythm Raptors', 'Ripples',
'Stringrays', 'Stuff', 'Syncopaths', 'Turning Stile', 'Whoots']
records = []
for year, fname in [
(2016, "events-raw-2016.tsv"),
(2017, "events-raw-2017.tsv"),
(2018, "events-raw-2018.tsv"),
(2019, "events-raw-2019.tsv"),
(2023, "events-raw-2023.tsv"),
(2024, "events-raw-2024.tsv"),
(2025, "events-raw-2025.tsv"),
]:
with open(fname) as inf:
for n, line in enumerate(inf):
try:
if n == 0:
continue
if year <= 2023:
(typical_month,
name,
caller1,
caller2,
caller3,
caller4,
caller5,
caller6,
band1,
band2,
band3,
band4,
band5,
band6,
roles,
date,
location,
url,
*_) = line.split("\t")
date_end = ""
else:
(typical_month,
name,
caller1,
caller2,
caller3,
caller4,
caller5,
caller6,
band1,
band2,
band3,
band4,
band5,
band6,
roles,
date,
date_end,
location,
url,
*_) = line.split("\t")
if not name:
continue
if name == "end of active list":
break
callers = [x for x in (caller1,
caller2,
caller3,
caller4,
caller5,
caller6)
if x.strip()]
bands = [re.sub("^The ", "the ", x)
for x in (band1,
band2,
band3,
band4,
band5,
band6)
if x.strip() and x.lower() != "unnamed"]
bands = [
"the " + band if band in bands_add_the else band
for band in bands]
rec = {
"typical_month": typical_month,
"name": name,
"callers": callers,
"bands": bands,
"roles": roles,
"date": date,
"location": location,
"url": url,
"year": year,
}
if date_end:
rec["date_end"] = date_end
if name == "continued":
records[-1]["callers"].extend(callers)
records[-1]["bands"].extend(bands)
else:
records.append(rec)
except Exception:
print(line)
raise
with open("events.json") as inf:
old_records = json.load(inf)
loc_to_ll = {}
for record in old_records:
if record.get("latlng","") and record.get("location", ""):
loc_to_ll[record["location"]] = record["latlng"]
for record in records:
if record.get("location", ""):
if record["location"] in loc_to_ll:
record["latlng"] = loc_to_ll[record["location"]]
with open("events.json", "w") as outf:
json.dump(records, outf, indent=2)