-
Notifications
You must be signed in to change notification settings - Fork 8
/
filter_activity.py
68 lines (51 loc) · 2.18 KB
/
filter_activity.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
#!/usr/bin/python
# filter_activity.py
import argparse
import arrow
import csv
import datetime
import logging
import os.path
from pprint import pprint
import re
import sys
# -----------------------------------------------------------------------------
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Filter input file")
parser.add_argument('--output', dest='csv_file_output', default=None, help="Output CSV file (STDOUT if None)");
group1 = parser.add_argument_group('required arguments')
group1.add_argument('--input', dest='csv_file_input', required=True, help="Input CSV file");
args = parser.parse_args()
if args.csv_file_output:
if os.path.exists(args.csv_file_output) and os.path.samefile(args.csv_file_input, args.csv_file_output):
print("Error, input and output file cannot be the same")
sys.exit(-1)
reader = csv.DictReader(open(args.csv_file_input))
if args.csv_file_output:
f = open(args.csv_file_output, 'w', newline='', encoding='utf-8')
w = csv.writer(f)
else:
w = csv.writer(sys.stdout)
w.writerow(reader.fieldnames)
for row in reader:
# TODO: add your filtering and processing here
# pprint(row)
# Example: omit row if phase in ['RELEASED', 'ARCHIVED']
# if row['phase'] in ['RELEASED', 'ARCHIVED']:
# continue
# Example: omit row if createdAt is within 100 days
# if arrow.now() - arrow.get(row['createdAt']) < datetime.timedelta(days=int(100)):
# continue
# Example: omit row if createdAt is after 2019-03
# if arrow.get(row['createdAt']) > arrow.get("2019-03"):
# continue
# Example: omit row if latestSummary or latestScanEvent is after 2019-11-01
# cutoff = arrow.get("2019-11-01")
# if row['latestSummary'] and arrow.get(row['latestSummary']) > cutoff:
# continue
# if row['latestScanEvent'] and arrow.get(row['latestScanEvent']) > cutoff:
# continue
# Example: omit row if latestNotableActivity is not empty
# if row['latestNotableActivity']:
# continue
w.writerow(row.values())