-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.py
executable file
·100 lines (69 loc) · 2.75 KB
/
result.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from GmailConnector import GmailConnector, CrawlUtil
from GmailConnector import get_members
from GmailConnector import get_account
import random, imaplib, datetime, time
if __name__ == "__main__":
members = get_members()
account, passwd = get_account()
M = imaplib.IMAP4_SSL("imap.gmail.com", 993)
print account, passwd
M.login("%s" % account, "%s" % passwd)
exit()
M.select()
typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetch(num, '(BODY[HEADER])')
email_data = data[0][1]
pattern_list = [ 'Date:(?P<date>.*?) \+'
, 'From:.*?<(?P<from>.*?)>'
]
app_data = CrawlUtil.extractData(email_data, pattern_list)[0]
today = datetime.date.today()
mail_day = time.strptime(app_data['date'],"%a, %d %b %Y %H:%M:%S")
if today.year == mail_day.tm_year:
if today.month == mail_day.tm_mon:
if today.day == mail_day.tm_mday:
ignore = app_data['from']
for people in members:
if people["email"] == ignore or people["name"].lower() == ignore.split("@")[0].lower():
print "ignored:",people["name"]
people["status"] = False
M.close()
M.logout()
peoples_leader = []
peoples_male = []
peoples_female = []
for temp_people in members:
if temp_people["status"] == True:
if temp_people["commander"] == True:
peoples_leader.append([temp_people["email"],temp_people["name"]])
elif temp_people["gender"] == True:
peoples_male.append([temp_people["email"],temp_people["name"]])
else:
peoples_female.append([temp_people["email"],temp_people["name"]])
random.shuffle(peoples_leader)
random.shuffle(peoples_male)
random.shuffle(peoples_female)
peoples = [[],[]]
for i in range(0, len(peoples_leader)):
peoples[i%2].append(peoples_leader[i])
for i in range(0, len(peoples_male)):
peoples[i%2].append(peoples_male[i])
for i in range(0, len(peoples_female)):
peoples[i%2].append(peoples_female[i])
random.shuffle(peoples[0])
random.shuffle(peoples[1])
content = """
버즈니 점심 팀
================================\n"""
for team in peoples:
content += "\t%s 팀\n" % team[0][1]
content += "\t---------\n"
for people in team:
content += "\t%s\n" % people[1]
content += "\t---------\n"
a = GmailConnector()
a.send(["pgonee@buzzni.com"], "result", content)
# a.send([ a["email"] for a in get_members() ], "result", content)