-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvc_daemon.py
executable file
·53 lines (47 loc) · 1.65 KB
/
vc_daemon.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
#!/usr/bin/env python3
import datetime
#import email
from imap_tools import MailBox, AND
import time
import urllib.request
from services import common
# from services import filemail
from services import responses
settings = common.get_config()
# process any pending jobs on startup
responses.process( settings )
# watch the inbox for form submissions (or edits)
# imap host, username & password are stored externally as a json file.
print("imap host:", settings["host"])
print("imap email:", settings["user"])
mailbox = None
connected = False
while True:
if not connected:
mailbox = MailBox(settings["host"])
mailbox.login(settings["user"], settings["password"])
connected = True
now = datetime.datetime.now()
print("Checking for new mail notifications:",
now.strftime("%Y-%m-%d %H:%M:%S"))
try:
mailbox.folder.set("INBOX")
# messages = mailbox.fetch(AND(all=True), headers_only=True)
# messages = mailbox.fetch(AND(seen=False), headers_only=True)
messages = mailbox.fetch(AND(seen=False))
except:
print("imap connection dropped, or fetch failed...")
connected = False
if connected:
form_notification = False
for msg in messages:
print(msg.from_)
print(msg.subject)
if "Virtual Choir" in msg.subject:
form_notification = True
if form_notification:
print("new google form work ...")
responses.fetch( settings["responses"] )
responses.process( settings )
# subjects = [msg.subject for msg in mailbox.fetch(AND(all=True))]
time.sleep(settings["interval"])