-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_table.py
More file actions
57 lines (48 loc) · 1.86 KB
/
debug_table.py
File metadata and controls
57 lines (48 loc) · 1.86 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
"""Debug - show raw text for table parsing."""
import imaplib
import email
from email.header import decode_header
import sys
sys.path.insert(0, 'src')
from parsers import parse_html
HOST = "imap.gmail.com"
USER = "lovelykimura832@gmail.com"
PASSWORD = "ztrv pndd qslg jtsh"
FROM_FILTERS = ["s1963@yandex.ru", "nsv11061992@gmail.com"]
def decode_header_str(header):
if not header:
return ""
decoded = []
for part, enc in decode_header(header):
if isinstance(part, bytes):
decoded.append(part.decode(enc or "utf-8", errors="replace"))
else:
decoded.append(part)
return " ".join(decoded)
mail = imaplib.IMAP4_SSL(HOST)
mail.login(USER, PASSWORD)
mail.select("INBOX")
for sender in FROM_FILTERS:
_, messages = mail.search(None, f'(FROM "{sender}")')
for num in messages[0].split():
_, msg_data = mail.fetch(num, "(RFC822)")
raw = msg_data[0][1]
msg = email.message_from_bytes(raw)
for part in msg.walk():
ctype = part.get_content_type()
try:
payload = part.get_payload(decode=True)
if not payload:
continue
charset = part.get_content_charset() or "utf-8"
if ctype == "text/html":
text = parse_html(payload.decode(charset, errors="replace"))
# Find lines with "Товар" or prices
lines = text.split('\n')
print("Строки с таблицей:")
for i, line in enumerate(lines):
if '|' in line or 'Товар' in line or 'КАРВЕД' in line or 'МЕТФОРМ' in line:
print(f"{i}: {line[:100]}")
except Exception as e:
print(f"Error: {e}")
mail.logout()