-
Notifications
You must be signed in to change notification settings - Fork 3
/
5-make-tsv.py
31 lines (27 loc) · 998 Bytes
/
5-make-tsv.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
import json
from pdb import set_trace
from model import Registration, Renewal
import unicodecsv
class Spreadsheet(object):
def __init__(self, output):
self.out = unicodecsv.writer(
open(output, "wb"), dialect="excel-tab",
encoding="utf-8"
)
def convert(self, input_file):
self.out.writerow(Registration.csv_row_labels + Renewal.csv_row_labels)
for line in open(input_file):
registration = Registration.from_json(json.loads(line))
self.out.writerow(registration.csv_row)
spreadsheets = {
"renewed" : ["renewed", "probably-renewed", "possibly-renewed"],
"not-renewed": ["not-renewed"],
"foreign": ["foreign"],
"previously-published": ["previously-published"],
}
for name, inputs in spreadsheets.items():
output = "output/FINAL-%s.tsv" % name
spreadsheet = Spreadsheet(output)
for i in inputs:
filename = "output/FINAL-%s.ndjson" % i
spreadsheet.convert(filename)