-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
91 lines (76 loc) · 3.11 KB
/
Copy pathparse.py
File metadata and controls
91 lines (76 loc) · 3.11 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
import requests
import re
import time
import winsound # работает только на Windows
# НАСТРОЙКИ
START_I = 77775 # с какого номера подарка начинать парсить
REQUEST_TIMEOUT = 2 # таймаут HTTP-запроса (сек)
SLEEP_OK = 0.1 # пауза между успешными запросами (сек)
SLEEP_RETRY = 0.1 # пауза при ошибке/ретрае (сек)
BASE_URL = "https://t.me/nft/holidaydrink" # ссылка на подарок без номера
BEEP_ENABLED = True # включить/выключить звук
BEEP_AT = 77776 # после какого i пищать
def extract_row_cell(html, field):
pattern = rf'<tr><th>{re.escape(field)}</th><td>(.+?)</td></tr>'
m = re.search(pattern, html, re.DOTALL)
return m.group(1) if m else None
def clean_cell_text(cell_html):
if not cell_html:
return None
text = re.sub(r'<.*?>', '', cell_html)
return ' '.join(text.split())
i = START_I
print(
f"{'i':>7} | {'Quantity':<22} | "
f"{'Owner':<15} | {'Username':<16} | "
f"{'Model':<18} | {'Backdrop':<14} | {'Symbol':<10} | "
f"{'HTTP':<4} | Time"
)
print("-" * 140)
while True:
url = f"{BASE_URL}-{i}"
while True:
try:
resp = requests.get(url, timeout=REQUEST_TIMEOUT)
if not resp.text.strip():
raise Exception("Empty response")
break
except Exception as e:
print(f"[retry] i={i} | error: {e}")
time.sleep(SLEEP_RETRY)
try:
html_text = resp.text
owner_cell = extract_row_cell(html_text, "Owner")
owner_nick = clean_cell_text(owner_cell) or "-"
owner_username = "-"
if owner_cell:
m_user = re.search(r'href="https://t.me/([^"/\?]+)"', owner_cell)
if m_user:
owner_username = "@" + m_user.group(1)
model = clean_cell_text(extract_row_cell(html_text, "Model")) or "-"
backdrop = clean_cell_text(extract_row_cell(html_text, "Backdrop")) or "-"
symbol = clean_cell_text(extract_row_cell(html_text, "Symbol")) or "-"
quantity = clean_cell_text(extract_row_cell(html_text, "Quantity")) or "-"
ts = time.strftime("%Y-%m-%d %H:%M:%S")
if [model, backdrop, symbol, quantity] == ["-", "-", "-", "-"]:
i -= 1
print(
f"{i:7d} | "
f"{quantity[:22]:<22} | "
f"{owner_nick[:15]:<15} | "
f"{owner_username[:16]:<16} | "
f"{model[:18]:<18} | "
f"{backdrop[:14]:<14} | "
f"{symbol[:10]:<10} | "
f"{resp.status_code:<4} | "
f"{ts}"
)
if BEEP_ENABLED and i >= BEEP_AT:
winsound.Beep(1000, 300)
winsound.Beep(1500, 300)
i += 1
time.sleep(SLEEP_OK)
except Exception as e:
print(f"[parse error] i={i} | {e} -> step back")
i -= 1
time.sleep(SLEEP_OK)