-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_reader.py
More file actions
108 lines (87 loc) · 3.75 KB
/
debug_reader.py
File metadata and controls
108 lines (87 loc) · 3.75 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""
Debug script for internal RSS reader troubleshooting
"""
import sys
import email
import hashlib
from common import config
import database as db
def debug_info():
print("=" * 60)
print("Internal RSS Reader Debug Information")
print("=" * 60)
# Check configuration
print("\n[1] Configuration Check:")
print(f" enable_internal_reader: {config.get('enable_internal_reader')}")
print(f" data_dir: {config.get('data_dir')}")
print(f" server_baseurl: {config.get('server_baseurl')}")
# Check database
print("\n[2] Database Check:")
entry_count = db.get_entry_count()
print(f" Total emails in database: {entry_count}")
if entry_count == 0:
print(" ⚠️ Database is empty! Fetch some emails first.")
return
# List all senders
print("\n[3] Senders in Database:")
senders = db.get_senders()
for idx, sender in enumerate(senders, 1):
emails = db.get_email(sender)
print(f" {idx}. {sender} ({emails.count()} emails)")
# Check specific sender if provided
if len(sys.argv) > 1:
target_sender = sys.argv[1]
print(f"\n[4] Checking emails from: {target_sender}")
emails = db.get_email(target_sender)
email_count = emails.count()
if email_count == 0:
print(f" ⚠️ No emails found from {target_sender}")
print(f" Available senders: {', '.join(senders)}")
return
print(f" Found {email_count} emails")
print("\n[5] Email Details with GUIDs:")
for idx, email_record in enumerate(emails, 1):
try:
msg = email.message_from_bytes(email_record.content)
# Calculate GUID
unique_string = msg["subject"] + msg["date"] + msg["from"]
guid = hashlib.md5(unique_string.encode()).hexdigest()
# Extract subject
subject = email.header.make_header(email.header.decode_header(msg["subject"]))
# Generate sanitized feed name
email_addr = target_sender
sanitized = email_addr.replace("@", "_").replace(".", "_")
# Generate internal link
internal_link = f"/article/{sanitized}/{guid}"
print(f"\n Email #{idx}:")
print(f" Subject: {subject}")
print(f" Date: {msg['date']}")
print(f" GUID: {guid}")
print(f" Internal URL: {internal_link}")
except Exception as e:
print(f" ⚠️ Error processing email #{idx}: {e}")
# Test GUID lookup if provided
if len(sys.argv) > 2:
target_guid = sys.argv[2]
print(f"\n[6] Testing GUID Lookup: {target_guid}")
target_sender = sys.argv[1]
email_record = db.get_email_by_guid(target_sender, target_guid)
if email_record:
print(f" ✅ Email found!")
msg = email.message_from_bytes(email_record.content)
subject = email.header.make_header(email.header.decode_header(msg["subject"]))
print(f" Subject: {subject}")
print(f" Sender: {email_record.sender}")
print(f" Timestamp: {email_record.timestamp}")
else:
print(f" ❌ No email found with GUID: {target_guid}")
print(f" Sender searched: {target_sender}")
if __name__ == "__main__":
if len(sys.argv) == 1:
print("Usage:")
print(" python debug_reader.py # Show all senders")
print(" python debug_reader.py <sender_email> # Show emails and GUIDs for sender")
print(" python debug_reader.py <sender> <guid> # Test GUID lookup")
print("\nRunning basic check...\n")
debug_info()