This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw_transfers.py
117 lines (94 loc) · 4.45 KB
/
raw_transfers.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import decimal
from universal_functions import wallet_short_name, decimal_number_formatter, \
format_coins, format_dollars, format_dollars_longer, format_coins_longer
def raw_transfer_format_timestamp(timestamp):
try:
from datetime import datetime, date
full_date = datetime.fromtimestamp(timestamp)
first_txn_full_date = full_date.strftime("%d/%m/%Y %I:%M:%S %p")
first_txn_full_date = str(first_txn_full_date) + ' BST'
# calculating days since
date_format = "%m/%d/%Y"
# today
today = date.today()
today = today.strftime("%m/%d/%Y")
today = datetime.strptime(today, date_format)
# first txn
first_txn_date = full_date.strftime("%m/%d/%Y")
first_txn_date = datetime.strptime(first_txn_date, date_format)
# calculating days_since since
delta = today - first_txn_date
days_since = delta.days
if days_since == 0:
day_message = '(today)'
elif days_since == 1:
day_message = '(1 day ago)'
else:
day_message = '({} days ago)'.format(days_since)
return {'first_txn_full_date': first_txn_full_date, 'days_since': day_message}
except IndexError:
return {'first_txn_full_date': '-', 'days_since': '-'}
def rawTransfers(all_deposits, all_withdrawals, coin_price, network):
deposit_transfers = []
for i in all_deposits['all_deposits']:
display_name = wallet_short_name(i['from'])
try:
if i['from_account_display']['display'] != '':
display_name = i['from_account_display']['display']
except:
pass
full_wallet_address = i['from']
coin_amount = i['amount']
coin_worth_dollar = float(coin_amount) * float(coin_price)
gas = decimal_number_formatter(i['fee'])
gas_dollar_worth = decimal.Decimal(gas) * decimal.Decimal(coin_price)
txn_time = raw_transfer_format_timestamp(i['block_timestamp'])
days_since = txn_time['days_since']
txn_time = txn_time['first_txn_full_date']
# formatting dollars
coin_worth_dollar = format_dollars(coin_worth_dollar)
gas_dollar_worth = format_dollars_longer(gas_dollar_worth)
# formatting coins
coin_amount = format_coins(coin_amount, network)
gas = format_coins_longer(gas, network)
deposit_transfers.append([f'{display_name} ({full_wallet_address}) deposited {coin_amount} (',
coin_worth_dollar,
f') on {txn_time} {days_since} with a fee of {gas} (',
gas_dollar_worth,
')'])
if deposit_transfers == []:
deposit_transfers.append('-')
withdraw_transfers = []
for i in all_withdrawals['all_withdraws']:
withdraw_withdrew = 'withdrew'
if i['success'] != True:
withdraw_withdrew = 'TRIED to withdraw'
display_name = wallet_short_name(i['to'])
try:
if i['to_account_display']['display'] != '':
display_name = i['to_account_display']['display']
except:
pass
full_wallet_address = i['to']
coin_amount = i['amount']
coin_worth_dollar = float(coin_amount) * float(coin_price)
gas = decimal_number_formatter(i['fee'])
gas_dollar_worth = decimal.Decimal(gas) * decimal.Decimal(coin_price)
txn_time = raw_transfer_format_timestamp(i['block_timestamp'])
days_since = txn_time['days_since']
txn_time = txn_time['first_txn_full_date']
# formatting dollars
coin_worth_dollar = format_dollars(coin_worth_dollar)
gas_dollar_worth = format_dollars_longer(gas_dollar_worth)
# formatting coins
coin_amount = format_coins(coin_amount, network)
gas = format_coins_longer(gas, network)
withdraw_transfers.append([f'You {withdraw_withdrew} {coin_amount} (',
coin_worth_dollar,
f') to {display_name} ({full_wallet_address}) on {txn_time} {days_since} with a fee of {gas} (',
gas_dollar_worth,
')'])
if withdraw_transfers == []:
withdraw_transfers.append('-')
return dict({'raw_transfers': {'deposit_transfers': deposit_transfers,
'withdraw_transfers': withdraw_transfers}})