Skip to content

Commit c607efd

Browse files
committed
Merge pull request #56 from milanocookies93/master
Cleaner code and clear instructions for crowdsource
2 parents 8fabca0 + 8aab207 commit c607efd

File tree

2 files changed

+35
-80
lines changed

2 files changed

+35
-80
lines changed

animations/crowdsource/main.py

Lines changed: 34 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import email.header
88
import datetime
99
import random
10-
from random import randint
1110
import time
1211

1312
EMAIL_ACCOUNT = "[email protected]"
@@ -31,109 +30,65 @@
3130
black,black,black,black,black,black,
3231
black,black,black,black,black,black]
3332

33+
out = FadeAnimation()
34+
35+
def pushcolor(color):
36+
time.sleep(1.0)
37+
pixels[0] = color
38+
out.write(pixels)
39+
time.sleep(1.0)
40+
random.shuffle(pixels)
41+
pixels[0] = black
42+
out.write(pixels)
43+
3444
if __name__ == "__main__":
35-
password = "PASSWORD GOES HERE"
36-
out = FadeAnimation()
45+
password = "PASSWORD GOES HERE"
3746
out.start()
3847
out.write(pixels)
3948
while True:
4049
M = imaplib.IMAP4_SSL('imap.gmail.com')
41-
4250
try:
4351
rv, data = M.login(EMAIL_ACCOUNT, password)
4452
except imaplib.IMAP4.error:
4553
sys.exit(1)
46-
47-
print rv, data
48-
4954
rv, mailboxes = M.list()
5055
rv, data = M.select(EMAIL_FOLDER)
51-
5256
if rv == 'OK':
53-
5457
rv, data = M.search(None, "ALL")
5558
if rv != 'OK':
5659
M.close()
5760
sys.exit(1)
58-
61+
numcolors = 0
5962
for num in data[0].split():
63+
numcolors = numcolors + 1
6064
rv, data = M.fetch(num, '(RFC822)')
6165
if rv != 'OK':
6266
M.close()
6367
sys.exit(1)
64-
6568
msg = email.message_from_string(data[0][1])
6669
decode = email.header.decode_header(msg['Subject'])[0]
6770
subject = unicode(decode[0])
6871
if subject == "red":
69-
time.sleep(1.0)
70-
pixels[0] = red
71-
out.write(pixels)
72-
time.sleep(1.0)
73-
random.shuffle(pixels)
74-
pixels[0] = black
75-
out.write(pixels)
76-
if subject == "blue":
77-
time.sleep(1.0)
78-
pixels[0] = blue
79-
out.write(pixels)
80-
time.sleep(1.0)
81-
random.shuffle(pixels)
82-
pixels[0] = black
83-
out.write(pixels)
84-
if subject == "green":
85-
time.sleep(1.0)
86-
pixels[0] = green
87-
out.write(pixels)
88-
time.sleep(1.0)
89-
random.shuffle(pixels)
90-
pixels[0] = black
91-
out.write(pixels)
92-
if subject == "black":
93-
time.sleep(1.0)
94-
pixels[0] = black
95-
out.write(pixels)
96-
time.sleep(1.0)
97-
random.shuffle(pixels)
98-
pixels[0] = black
99-
out.write(pixels)
100-
if subject == "orange":
101-
time.sleep(1.0)
102-
pixels[0] = orange
103-
out.write(pixels)
104-
time.sleep(1.0)
105-
random.shuffle(pixels)
106-
pixels[0] = black
107-
out.write(pixels)
108-
if subject == "yellow":
109-
time.sleep(1.0)
110-
pixels[0] = yellow
111-
out.write(pixels)
112-
time.sleep(1.0)
113-
random.shuffle(pixels)
114-
pixels[0] = black
115-
out.write(pixels)
116-
if subject == "purple":
117-
time.sleep(1.0)
118-
pixels[0] = purple
119-
out.write(pixels)
120-
time.sleep(1.0)
121-
random.shuffle(pixels)
122-
pixels[0] = black
123-
out.write(pixels)
124-
if subject == "teal":
125-
time.sleep(1.0)
126-
pixels[0] = teal
127-
out.write(pixels)
128-
time.sleep(1.0)
129-
random.shuffle(pixels)
130-
pixels[0] = black
131-
out.write(pixels)
132-
72+
pushcolor(red)
73+
elif subject == "blue":
74+
pushcolor(blue)
75+
elif subject == "green":
76+
pushcolor(green)
77+
elif subject == "black":
78+
pushcolor(black)
79+
elif subject == "orange":
80+
pushcolor(orange)
81+
elif subject == "yellow":
82+
pushcolor(yellow)
83+
elif subject == "purple":
84+
pushcolor(purple)
85+
elif subject == "teal":
86+
pushcolor(teal)
13387
M.store(num, '+FLAGS', '\\Deleted')
88+
if numcolors == 0:
89+
time.sleep(1.0)
90+
random.shuffle(pixels)
91+
out.write(pixels)
13492
M.expunge()
13593
M.close()
136-
time.sleep(1.0)
137-
random.shuffle(pixels)
138-
out.write(pixels)
139-
M.logout()
94+
M.logout()

animations/crowdsource/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name":"Crowdsource",
3-
"description":"Email [email protected] to change the lights!",
3+
"description":"Email [email protected] with the subject 'red','orange','yellow','green','blue','purple','teal', or 'black' to add colors",
44
"creator":"Milan Dasgupta"
55
}

0 commit comments

Comments
 (0)