-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (34 loc) · 1016 Bytes
/
main.py
File metadata and controls
44 lines (34 loc) · 1016 Bytes
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
from app.gmail_service import get_messages
from app.processor import process_email
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s"
)
def main():
service, messages = get_messages()
if not messages:
logging.info("No new emails.")
return
total_emails = 0
total_tasks = 0
for msg in messages:
try:
created_tasks = process_email(service, msg)
total_emails += 1
total_tasks += created_tasks
# mark as read
service.users().messages().modify(
userId='me',
id=msg['id'],
body={'removeLabelIds': ['UNREAD']}
).execute()
except Exception as e:
logging.error(f"Error processing email: {e}")
logging.info(
"Run complete. Processed %s email(s) and created %s task(s).",
total_emails,
total_tasks,
)
if __name__ == "__main__":
main()