-
Notifications
You must be signed in to change notification settings - Fork 0
/
twAlert.py
51 lines (48 loc) · 1.91 KB
/
twAlert.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
import twitterAPI
import twAlertHandler
import emailAPI
import dbAPI
import os
from datetime import date
tclient = twitterAPI.api
userMap, membLastTwitMap = dbAPI.getUsMembLastPostInfo()
if(userMap and membLastTwitMap):
twSendList = []
twUpdateLastTwitt = {}
for member, lasttw in membLastTwitMap.items():
memberTimelineList = twAlertHandler.twitterTimeline(tclient,member,lasttw)
if(memberTimelineList):
twSendList.append(memberTimelineList)
if(twSendList):
for items in twSendList:
# Date of email is sent
date = date.today()
memberName = items[0].name
toemail = userMap.get(items[0].twuser)
content = ""
twUpdateLastTwitt[items[0].idName] = items[0].idStr
for i,itm in enumerate(items):
content += itm.created.date().__str__() + ": \n" + itm.text + "\n \n"
emailAPI.sendEmail(content,date.__str__(), memberName, toemail)
if(twUpdateLastTwitt):
dbAPI.updateLastTwitt(twUpdateLastTwitt)
# function deprecated
#TO-DO delete function
def defaultEmailSend():
twSendList = []
#Get user lists for alert
# lists for alert, those which last character is "_" (just first one for now)
twUserMembersLists = twAlertHandler.getUserLists(tclient,os.environ.get('USER_DEFAULT'))
if(twUserMembersLists):
for twMember in twUserMembersLists:
memberTimelineList = twAlertHandler.twitterTimeline(tclient,twMember,0)
if(memberTimelineList):
twSendList.append(memberTimelineList)
for indx,items in enumerate(twSendList):
# Date of email is sent
date = date.today()
memberName = items[indx].name
content = ""
for itm in items:
content += itm.created.date().__str__() + ": \n" + itm.text + "\n \n"
emailAPI.sendEmail(content,date.__str__(), memberName,"")