-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailGist.py
64 lines (49 loc) · 1.71 KB
/
MailGist.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
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
from abc import ABC, abstractmethod
import asyncio
from clients import gmail, outlook
from utilities import agent, notification
class MailGist(ABC):
def __init__(self, token, endpoint, model_name, credential, client_secret=None):
self.credential = credential
self.client_secret = client_secret
self.agent = agent.Agent(token, endpoint, model_name)
def summarize_email(self, body):
return self.agent.summarize_email(body)
def process_summary(self, summary):
summaryArr = summary.split("\n")
print(summaryArr)
if "low" in summaryArr[0].lower():
urgency = "low"
elif "medium" in summaryArr[0].lower():
urgency = "medium"
elif "high" in summaryArr[0].lower():
urgency = "high"
else:
urgency = "medium"
return [urgency, summaryArr[2]]
def start(self):
pass
def listen(self):
asyncio.run(self.start())
class GmailMailGist(MailGist):
async def start(self):
gmailClient = gmail.Gmail(self.client_secret)
prevBody = None
while True:
sender, body = gmailClient.run()
if body != prevBody:
summary = self.process_summary(self.summarize_email(body))
print(summary)
toast = notification.Notification(
app_id="MailGist",
title=sender,
msg=summary[1],
email_urgency=summary[0],
)
toast.show()
prevBody = body
await asyncio.sleep(5)
class OutlookMailGist(MailGist):
def start(self):
# TODO: Perform outlook methods
pass