-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (49 loc) · 1.91 KB
/
Copy pathmain.py
File metadata and controls
67 lines (49 loc) · 1.91 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
import time
import logging
from dotenv import load_dotenv
load_dotenv()
from gmail_client import GmailClient
from ai_analyzer import AIAnalyzer
import telegram_client
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(name)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
logger = logging.getLogger(__name__)
CHECK_INTERVAL = 60 # seconds
def main():
logger.info("Mail Tracker starting...")
gmail = GmailClient()
analyzer = AIAnalyzer()
gmail.seed_processed_ids()
telegram_client.send_message("✅ Mail Tracker başlatıldı")
logger.info("Startup message sent to Telegram.")
while True:
try:
logger.info("Checking for new emails...")
emails = gmail.get_new_emails()
if not emails:
logger.info("No new emails found.")
else:
logger.info(f"Found {len(emails)} new email(s). Analyzing...")
for email in emails:
try:
analysis = analyzer.analyze_email(email)
logger.info(
f"Email analyzed — Subject: '{email['subject']}' | "
f"Category: {analysis['kategori_kodu']} | "
f"Score: {analysis['onem_skoru']} | "
f"Notify: {analysis['should_notify']}"
)
if analysis['should_notify']:
telegram_client.send_email_notification(email, analysis)
else:
logger.info(f"Skipped (low importance or spam): {email['subject']}")
except Exception as e:
logger.error(f"Error processing email '{email.get('subject', '?')}': {e}")
except Exception as e:
logger.error(f"Error during email check cycle: {e}")
time.sleep(CHECK_INTERVAL)
if __name__ == '__main__':
main()