-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_wallets.py
More file actions
130 lines (106 loc) · 3.47 KB
/
Copy pathsort_wallets.py
File metadata and controls
130 lines (106 loc) · 3.47 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import csv
import os
from datetime import datetime
from bs4 import BeautifulSoup
import urllib.request
import urllib
import re
import threading
import traceback
class Transaction(object):
"""docstring for Transaction"""
def __init__(self, date, address, amount, trans):
super(Transaction, self).__init__()
self.date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
self.address = address
self.amount = amount
self.trans = trans
def __eq__(self, other):
return self.date == other.date and self.address == other.address and self.amount == other.amount and self.trans == other.trans
def __hash__(self):
return hash(('date', self.date, 'address', self.address, 'amount', self.amount, 'trans', self.trans))
def get_address(date, wallet, amount, txid):
base = 'https://www.walletexplorer.com/txid/'
url = base + txid
j = 0
while True:
try:
soup = BeautifulSoup(urllib.request.urlopen(url).read(), 'html.parser')
break
except Exception:
j = j + 1
if j > 50:
print('Skipping '+url)
return
continue
break
try:
tx_table = soup.find_all('table', class_='tx')[0]
except Exception as e:
print(url)
top = tx_table.find_all('tr')
address = ""
for tr in top[1].find_all('table', class_='empty')[1].find_all('tr'):
link = tr.find_all('td')
text_amount = link[2].text
if '(' in text_amount:
continue
amn = float(re.findall('\d+\.?\d*',text_amount)[0])
if float(amount) == amn:
address = link[0].text
#print(address)
break
trans.append(Transaction(date, address, amount, txid))
pass
path = os.getcwd()
trans = []
threads = []
with open(path+'\..\..\inputs.csv', 'r') as inputfile:
file_contents = inputfile.read().splitlines(True)
content = file_contents[1:]
lines = len(content)
j = 0
inputfile.seek(0)
reader = csv.DictReader(inputfile)
for line in reader:
if line['received_amount']:
while threading.active_count() > 50:
continue
t = threading.Thread(target=get_address, args=(line['date'], line['received_from'], line['received_amount'], line['transaction'], ))
#for line in content:
# line_content = line.split(',')
# if line_content[2]:
# while threading.active_count() > 50:
# continue
#
# t = threading.Thread(target=get_address, args=(line_content[0], line_content[1], line_content[2], line_content[6], ))
threads.append(t)
t.start()
j = j + 1
print(j/lines)
j = 0
for t in threads:
j = j + 1
print('Waiting for: '+str(j)+'/'+str(len(threads)))
t.join()
with open('sorted_input.csv', 'w') as sortedinputfile:
sortedinputfile.write('date,received_amount,address,txid\n')
for t in sorted(list(set(trans)), key=lambda s: s.date, reverse=True):
sortedinputfile.write(str(t.date)+','+str(t.amount)+','+t.address+','+t.trans+'\n')
print('Sorting outputs')
trans = []
with open('outputs.csv', 'r') as outputfile:
reader = csv.DictReader(outputfile)
for line in reader:
trans.append(Transaction(line['date'], line['address'], line['amount'], line['txid']))
#file_contents = outputfile.read().splitlines(True)
#content = file_contents[1:]
#trans = []
#for line in content:
# line_content = line.split(',')
# if line_content[2]:
# trans.append(Transaction(line_content[0], line_content[1], line_content[2], line_content[3]))
with open('sorted_output.csv', 'w') as sortedoutputfile:
sortedoutputfile.write('date,sent_amount,address,txid\n')
for t in sorted(list(set(trans)), key=lambda s: s.date, reverse=True):
sortedoutputfile.write(str(t.date)+','+str(t.amount)+','+t.address+','+t.trans+'\n')