-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckmail.py
More file actions
94 lines (73 loc) · 1.91 KB
/
checkmail.py
File metadata and controls
94 lines (73 loc) · 1.91 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
from imapclient import IMAPClient
import time
import RPi.GPIO as GPIO
HOSTNAME = 'imap.gmail.com'
USERNAME = '@gmail.com'
PASSWORD = ''
MAILBOX = 'Inbox'
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
buzzerpin = 2
GPIO.setup(buzzerpin, GPIO.OUT) #buzzer
GPIO.setup(18, GPIO.OUT) #LEDs
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
server = IMAPClient(HOSTNAME, use_uid=True, ssl=True)
server.login(USERNAME, PASSWORD)
print('Logging in as ' + USERNAME)
def buzz():
#Dot Dot Dot
GPIO.output(buzzerpin,GPIO.HIGH)
time.sleep(.1)
GPIO.output(buzzerpin,GPIO.LOW)
time.sleep(.1)
GPIO.output(buzzerpin,GPIO.HIGH)
time.sleep(.1)
GPIO.output(buzzerpin,GPIO.LOW)
time.sleep(.1)
GPIO.output(buzzerpin,GPIO.HIGH)
time.sleep(.1)
#Dash Dash Dah
GPIO.output(buzzerpin,GPIO.LOW)
time.sleep(.2)
GPIO.output(buzzerpin,GPIO.HIGH)
time.sleep(.2)
GPIO.output(buzzerpin,GPIO.LOW)
time.sleep(.2)
GPIO.output(buzzerpin,GPIO.HIGH)
time.sleep(.2)
GPIO.output(buzzerpin,GPIO.LOW)
time.sleep(.2)
GPIO.output(buzzerpin,GPIO.HIGH)
time.sleep(.2)
GPIO.output(buzzerpin,GPIO.LOW)
time.sleep(.7)
def blink():
for i in range (0, 3):
GPIO.output(24, GPIO.HIGH)
time.sleep(.2)
GPIO.output(24, GPIO.LOW)
time.sleep(.2)
try:
while True:
blink()
select_info = server.select_folder(MAILBOX)
print('%d messages in INBOX' % select_info['EXISTS'])
folder_status = server.folder_status(MAILBOX, 'UNSEEN')
newmails = int(folder_status['UNSEEN'])
print "You have", newmails, "new emails!"
if newmails > 0:
GPIO.output(18, True)
GPIO.output(23, False)
buzz()
else:
GPIO.output(18, False)
GPIO.output(23, True)
time.sleep(3)
except KeyboardInterrupt:
print "\nYou quit the program"
except:
print "\nAn error has occurred"
finally:
GPIO.cleanup()