-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstellarCSV.py
More file actions
28 lines (22 loc) · 1.08 KB
/
stellarCSV.py
File metadata and controls
28 lines (22 loc) · 1.08 KB
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
import maya
import csv
def toUTCtimestamp(timestamp):
dt = maya.parse(timestamp).datetime()
return (dt.strftime("%Y-%m-%d %H:%M:%S"))
transaction = ['Sell', 'Buy']
def translate(Datestamp, transaction, Token, Amount, TPXLM):
switcher: Dict[str, str] = {
'Buy': [str(Amount), Token, str(TPXLM),'XLM','','',''],
'Sell': [str(TPXLM),'XLM',str(Amount),Token,'','','']
}
return [toUTCtimestamp(Datestamp)] + switcher[transaction]
with open('stellarx-trade-history-2020-12-31T18_31_27-08_00.csv', "r", newline='') as stellarFile:
csvreader = csv.reader(stellarFile, delimiter=',')
next(csvreader)
rowHeader = ['Date','Received Quantity','Received Currency','Sent Quantity','Sent Currency','Fee Amount','Fee Currency','Tag']
with open('output.csv', 'w', newline='') as csvWritefile:
csvwriter = csv.writer(csvWritefile, delimiter=',')
csvwriter.writerow(rowHeader)
for row in csvreader:
output=translate(row[0], row[1], row[2], row[4], row[7])
csvwriter.writerow(output)