-
Notifications
You must be signed in to change notification settings - Fork 533
/
check.py
60 lines (56 loc) · 1.4 KB
/
check.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
from time import sleep
import requests
import json
from btcaddr import Wallet
from time import sleep
from fake_user_agent import user_agent
def generate_addresses(count):
addresses = {}
for i in range(count):
wallet = Wallet()
pub = wallet.address.__dict__["mainnet"].__dict__["pubaddr1"]
prv = wallet.key.__dict__["mainnet"].__dict__["wif"]
addresses[pub] = prv
return addresses
def check_balance_btc(data=generate_addresses(100)):
try:
addresses = "|".join(data.keys())
headers = {
"User-Agent": user_agent()
}
url = f"https://blockchain.info/multiaddr?active={addresses}"
response = requests.get(url, headers=headers).json()
sleep(0.5)
extract = []
for address in response["addresses"]:
# add all data into a list
extract.append({
"address": address["address"],
"balance": address["final_balance"],
"private": data[address["address"]]
})
return extract
except:
pass
"""def last_seen_bc(address):
try:
address = address
reading_state = 1
while reading_state:
try:
htmlfile = urlopen(
f"https://blockchain.info/q/addressfirstseen/{address}?format=json",
timeout=10,
)
htmltext = htmlfile.read().decode("utf-8")
reading_state = 0
except:
reading_state += 1
sleep(60 * reading_state)
ts = int(htmltext)
if ts == 0:
return 0
return str(datetime.utcfromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S"))
except:
return None
"""