-
Notifications
You must be signed in to change notification settings - Fork 3
/
tabichain-faucet.py
59 lines (47 loc) · 1.9 KB
/
tabichain-faucet.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
import os
import random
import string
import time
from loguru import logger
import requests
def get_proxy(nstproxy_channel="XXX", nstproxy_password="XXX"):
session = ''.join(random.choice(string.digits + string.ascii_letters) for _ in range(10))
return f"http://{nstproxy_channel}-residential-country_ANY-r_5m-s_{session}:{nstproxy_password}@gw-us.nstproxy.com:24125"
def parse_txt_file(file_path):
if not os.path.exists(file_path):
logger.error(f"file '{file_path}' not found.")
exit(1)
with open(file_path, 'r', encoding='utf-8') as file:
datas = file.readlines()
datas = [data.strip() for data in datas if data.strip()]
if len(datas) == 0:
raise Exception("file data not found.")
return datas
if __name__ == '__main__':
address_list = parse_txt_file("./add.txt")
for address in address_list:
logger.info(f"加载钱包:{address} .....")
try:
proxy_url = get_proxy()
proxies = {
"http": proxy_url,
"https": proxy_url,
}
data = {
"address": address.strip()
}
url = f"https://faucet-api.testnet.tabichain.com/api/faucet"
resp = requests.post(url=url, json=data, proxies=proxies , timeout=30)
resp.raise_for_status()
if resp.ok:
resp_text = resp.text
if "success" in resp_text:
tx_id = resp_text.split(" ")[0]
logger.success(
f"地址:{address} 领取成功,txId:{tx_id}")
continue
logger.error(f"地址:{address} 领取失败,原因:{resp_text}")
else:
logger.error(f"地址:{address} 发送领取请求失败,原因: {resp.text}")
except Exception as e:
logger.error(f"发生异常:{e}")