-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanchrousdparser.py
More file actions
46 lines (35 loc) · 2.02 KB
/
anchrousdparser.py
File metadata and controls
46 lines (35 loc) · 2.02 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from datetime import datetime
from typing import Dict
def get_date(time_stamp: str) -> str:
strp_time: datetime = datetime.strptime(time_stamp, '%Y-%m-%d %H:%M:%S')
utc_from_timestamp = datetime.fromtimestamp(strp_time.timestamp())
return str(datetime.strptime(str(utc_from_timestamp), '%Y-%m-%d %H:%M:%S'))
transactions = ['bank_deposit', 'bank_withdrawal', 'blockchain_deposit', 'blockchain_withdrawal', 'interest_earnings',
'trade_buy', 'trade_sell']
def translate(date: str, transaction: str, currency: str, amount: str, account: str, base_currency,
base_amount) -> str:
account = '' + '\n'
switcher: Dict[str, str] = {
"bank_deposit": ',{0},{1},,,,'.format(amount, currency),
'bank_withdrawal': ',,,{0},{1},,'.format(amount, currency),
'blockchain_deposit': ',{0},{1},,,,'.format(amount, currency),
'blockchain_withdrawal': ',,,{0},{1},,'.format(amount, currency),
'interest_earnings': ',{0},{1},,,,'.format(amount, currency),
'trade_buy': ',{0},{1},{2},{3},,,'.format(amount, currency, base_amount, base_currency),
'trade_sell': ',{0},{1},{2},{3},,,'.format(base_amount, base_currency, amount, currency),
}
return get_date(date) + switcher[transaction] + ',{0}'.format(account)
with open('sample/cointracker_csv_import_v4 (3).csv', 'r', newline='') as cointracker:
with open('inputs/anchorusd_transactions.csv', 'r', newline='') as anchorcsv:
with open('output/translated.csv', 'w+') as newFile:
anchorRead: str = anchorcsv.readline()
output = [
'Date,Received Quantity,Received Currency,Sent Quantity,Sent Currency,Fee Amount,Fee Currency,Tag\n']
for row in anchorcsv:
items = row.split(',')
output += translate(items[0].replace(" UTC", ""), items[1], items[2], items[3], items[8], items[6],
items[7])
newFile.writelines(output)
newFile.close()
anchorcsv.close()
cointracker.close()