-
Notifications
You must be signed in to change notification settings - Fork 0
/
netsurfp_parser.py
43 lines (29 loc) · 1.03 KB
/
netsurfp_parser.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
# Copyright (c) 2021 Christian Balbin
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
import csv
def NETSURFPparser(path):
with open(path) as csvfile:
reader = csv.DictReader(csvfile)
seq_dict = {}
for field in reader.fieldnames:
seq_dict[field] = []
first_row = next(reader)
title = first_row["id"]
for field in reader.fieldnames:
seq_dict[field] = [first_row[field]]
for row in reader:
if row["id"] == title:
for field in reader.fieldnames:
seq_dict[field].append(row[field])
else:
yield seq_dict
for field in reader.fieldnames:
seq_dict[field] = [row[field]]
title = row["id"]
#
yield seq_dict
if __name__ == "__main__":
for x in NETSURFPparser("netsurfp/616DCFBD0000188B0F41494C.csv"):
print(x["id"], x["rsa"])
break