-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistreader.py
More file actions
30 lines (21 loc) · 807 Bytes
/
histreader.py
File metadata and controls
30 lines (21 loc) · 807 Bytes
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
from datetime import datetime
def readHistoryFile(filename, **kw):
# Read in history.txt and insert into a list
lines = [line.rstrip('\n') for line in open(filename)]
# Remove title line
title = [line.strip() for line in lines.pop(0).split("|")]
# Transform to tuples
def transform(lineStr):
d = {}
l = [line.strip() for line in lineStr.split("|")]
for idx, item in enumerate(l):
colName = title[idx]
if "plaintext" in kw:
d[title[idx]] = item
else:
d[title[idx]] = datetime.strptime(item, "%m/%d/%Y").date() if colName == "Date" else item
return d
objs = list(map(transform, lines))
return objs;
if __name__ == "__main__":
print(readHistoryFile("history.txt"))