Skip to content

Commit 8b0c0b0

Browse files
Merge pull request #1883 from Kkoder27/master
Simon says ezgmail example
2 parents e3e1af2 + 104c79f commit 8b0c0b0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

automail.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#find documentation for ezgmail module at https://pypi.org/project/EZGmail/
2+
#simple simon says module that interacts with google API to read the subject line of an email and respond to "Simon says:"
3+
#DO NOT FORGET TO ADD CREDENTIALS.JSON AND TOKEN.JSON TO .GITIGNORE!!!
4+
5+
import ezgmail, re, time
6+
7+
check = True
8+
while check:
9+
recThreads = ezgmail.recent()
10+
findEmail = re.compile(r'<(.*)@(.*)>')
11+
i = 0
12+
for msg in recThreads:
13+
subEval = recThreads[i].messages[0].subject.split(' ')
14+
sender = recThreads[i].messages[0].sender
15+
if subEval[0] == 'Simon' and subEval[1] == 'says:':
16+
subEval.remove('Simon')
17+
subEval.remove('says:')
18+
replyAddress = findEmail.search(sender).group(0).replace('<','').replace('>','')
19+
replyContent = 'I am now doing ' + ' '.join(subEval)
20+
ezgmail.send(replyAddress, replyContent, replyContent)
21+
ezgmail._trash(recThreads[i])
22+
if subEval[0] == 'ENDTASK': #remote kill command
23+
check = False
24+
i += 1
25+
time.sleep(60) #change check frquency; default every minute

0 commit comments

Comments
 (0)