-
Notifications
You must be signed in to change notification settings - Fork 0
/
threads_stream_acc.py
111 lines (98 loc) · 4.36 KB
/
threads_stream_acc.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
import requests
import time
import json
import datetime
import threading
import os
TG_BOT_TOKEN = os.getenv('TG_BOT_TOKEN')
TG_ChatID = os.getenv('TG_ChatID')
def tg_sendMsg(
msg: str | list = "no message",
TOKEN=TG_BOT_TOKEN,
chat_id=TG_ChatID,
ps = "",
*,
sep_msg: bool = False,
) -> str:
"""send message via telegram api(url)\n
url = (
f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={msg}"
)"""
# TOKEN = TOKEN
# chat_id = chat_id
_ps = ps
isStr = type(msg) is str
if isStr:
msg = msg + _ps
elif sep_msg and type(msg) == list:
for m in msg:
url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={m + _ps}"
requests.get(url).json()
return True
elif not sep_msg and type(msg) != str:
msg = " \n".join([m for m in msg]) + _ps
url = (
f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={msg}"
)
requests.get(url).json()
def fetch_url(url):
res = requests.get(f'https://tonapi.io/v2/blockchain/accounts/{url}/methods/get_sale_data', headers=headers)
if res.status_code == 200:
response = res.json()
try:
if response['decoded']['royalty_address'] == '0:ed53bc999e5a4af69a3f9c3de5376f7d90c487e1528f331e716dbe85903d5112':
created_at = response['decoded']['created_at']
price = int(response['decoded']['full_price'])/1e9
# if created_at < int(time.time()) + 10 and price < 7:
if price < 8:
nft_addr = response['decoded']['nft']
is_complete = response['decoded']['is_complete']
dt = str(datetime.datetime.fromtimestamp(created_at))
timeNow = str(datetime.datetime.now())[:-7]
# print(f'Price: {price}', f'\nCreated at: {dt:>16}\n Found at: {timeNow:>16}', f'\nNFT ADD: {nft_addr}\nIs_complete: {is_complete}')
# print(response)
#NFT INFO
res = requests.get(f'https://tonapi.io/v2/nfts/{nft_addr}', headers=headers)
nft_res = res.json()
if 'sale' in nft_res:
print(f'Price: {price}', f'\nCreated at: {dt:>16}\n Found at: {timeNow:>16}', f'\nNFT ADD: {nft_addr}\nIs_complete: {is_complete}')
msg = f'Price: {price}\nCreated at: {dt:>16}\n Found at: {timeNow:>16}\nNFT ADD: {nft_addr}\nIs_complete: {is_complete}'
tg_sendMsg(msg, ps='\n\nstream_acc.py')
except Exception as e:
# print("Exception: ", e)
pass
else:
print('Status code: ',res.status_code)
headers = {
"accept": "*/*",
"accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,uk;q=0.6",
"authorization": "Bearer AFPJTKEBPOX3AIYAAAAKA2HWOTRNJP5MUCV5DMDCZAAOCPSAYEYS3CILNQVLF2HWKED6USY",
"content-type": "application/json",
"sec-ch-ua": "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site"
}
url = "https://tonapi.io/v2/sse/accounts/traces?accounts=EQAIFunALREOeQ99syMbO6sSzM_Fa1RsPD5TBoS0qVeKQ-AR&token=AFPJTKEBPOX3AIYAAAAKA2HWOTRNJP5MUCV5DMDCZAAOCPSAYEYS3CILNQVLF2HWKED6USY"
#stream accounts https://tonviewer.com/EQAIFunALREOeQ99syMbO6sSzM_Fa1RsPD5TBoS0qVeKQ-AR
response = requests.get(url, stream=True)
for line in response.iter_lines():
if line.startswith(b'data:'):
# Если строка начинается с 'data:', это строка данных
# Извлеките данные и разберите их как JSON
data_json = line.split(b':', 1)[1].strip()
if data_json:
event_data = json.loads(data_json)
st = time.time()
# print(event_data['accounts'])
urls = [i for i in event_data['accounts']]
threads = [threading.Thread(target=fetch_url, args=(url,)) for url in urls]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
#NFT SALE CONTRACT info with price
end = time.time() - st
print(end)