-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (26 loc) · 925 Bytes
/
main.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
import threading
import time
from dotenv import dotenv_values
from email_checker import get_emails, send_email
from gpt_bot import generate_response
config = dotenv_values(".env")
def main():
while True:
emails = get_emails()
for email in emails:
thread = threading.Thread(target=handle_message, args=(email["sender"], email["subject"], email["body"]))
thread.start()
time.sleep(60)
def handle_message(sender, subject, body):
try:
print(f"Generowanie odpowiedzi dla: {sender}")
response = generate_response(body)
send_email(sender, f"Odpowiedź: {subject}", response)
except Exception as e:
print(f"Błąd podczas obsługi wiadomości od {sender}: {e}")
if __name__ == "__main__":
email_thread = threading.Thread(target=main)
email_thread.daemon = True
email_thread.start()
while True:
time.sleep(1)