-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_TestSecondCheck.py
169 lines (152 loc) · 7.89 KB
/
stream_TestSecondCheck.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import requests
import time
import json
import datetime
from threading import Thread
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()
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"
}
non_checked_acc = []
def second_check():
print('Thread has been started.')
while True:
if len(non_checked_acc) > 0:
st = time.time()
print(f'проверка не сработаных акков: {len(non_checked_acc)}')
for n,i in enumerate(non_checked_acc):
res = requests.get(f'https://tonapi.io/v2/blockchain/accounts/{i[0]}/methods/get_sale_data', headers=headers)
if res.status_code == 200:
response = res.json()
try:
if response['decoded']['royalty_address'] == '0:ed53bc999e5a4af69a3f9c3de5376f7d90c487e1528f331e716dbe85903d5112':
non_checked_acc.pop(n)
created_at = response['decoded']['created_at']
price = int(response['decoded']['full_price'])/1e9
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'Account CHECK OK: {i[0]}')
# print(dt)
# print(timeNow)
# if created_at < int(time.time()) + 10 and price < 7:
if price < 8:
# 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'[Thread]\nPrice: {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)
i[1] += 1
if i[1] > 1:
non_checked_acc.pop(n)
# print(f'Success pop #{n}')
pass
else:
i[1] += 1
# print('res.status_code')
if i[1] > 1:
non_checked_acc.pop(n)
# print(f'Success pop #{n}')
end = time.time() - st
print('Threads cycle: ', end)
time.sleep(6)
thr = Thread(target=second_check)
thr.start()
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)
# print(event_data['accounts'])
for i in event_data['accounts']:
Sale_addr = i
#NFT SALE CONTRACT info with price
res = requests.get(f'https://tonapi.io/v2/blockchain/accounts/{Sale_addr}/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
# print(f'Account OK: {i}')
# 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)
# print('Status code: ',res.status_code)
# print(f'Account False: {i}')
# print(str(datetime.datetime.now())[:-7])
non_checked_acc.append([i,0])
pass
else:
# print('Status code: ',res.status_code)
# print(f'Account False: {i}')
# print(str(datetime.datetime.now())[:-7])
non_checked_acc.append([i,0])
print([i[0][:7] for i in non_checked_acc])
thr.join()