-
Notifications
You must be signed in to change notification settings - Fork 36
/
filter_ati.py
executable file
·44 lines (34 loc) · 1000 Bytes
/
filter_ati.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
#!/usr/bin/env python3
"""
Script that takes csv on stdin with Year, Month as the first two columns
and outputs the header row and all rows within the past two years on stdout
"""
import csv
import sys
start_year_month = 2020, 1 # publicly accessible records
REMOVE_COLUMNS = [
'record_created',
'record_modified',
'user_modified',
]
BOM = "\N{bom}"
def main():
bom = sys.stdin.read(1) # first code point
if not bom:
# empty file -> empty file
return
assert bom == BOM
sys.stdout.write(BOM)
reader = csv.DictReader(sys.stdin)
outnames = [f for f in reader.fieldnames if f not in REMOVE_COLUMNS]
writer = csv.DictWriter(sys.stdout, outnames)
writer.writeheader()
for row in reader:
try:
for rem in REMOVE_COLUMNS:
del row[rem]
if (int(row['year']), int(row['month'])) >= start_year_month:
writer.writerow(row)
except ValueError:
pass
main()