-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotifierTest.py
81 lines (67 loc) · 2.29 KB
/
NotifierTest.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
import IPOCrawler
import IPOHelper
import DBHelper
import DateUtils
import json
def notifyIPOswithMsg(IPOList,message1):
jsonFormat = generateJSONResposneForText(message1)
subscriberList = DBHelper.getUserIdList("1")
for user in subscriberList:
print("Notifying user :"+user[0])
for ipoData in IPOList:
notifyIPO(ipoData)
def notifyIPO(ipoData):
subscriberList = DBHelper.getUserIdList("1")
for user in subscriberList:
jsonFormat = generateJSONResposneForIPO(ipoData)
print(jsonFormat)
def generateJSONResposneForText(responsemsg):
return json.dumps({
"text": responsemsg
})
def generateJSONResposneForIPO(ipoData):
ipoName = ipoData[0]
openDate = DateUtils.formatReadable(ipoData[1])
closeDate = DateUtils.formatReadable(ipoData[2])
price = ipoData[3]
infoURL = ipoData[6]
messageStr = ipoName + '\nOpen : ' + openDate + '\nClose : ' + closeDate + '\nPrice : ' + price
query = 'Test'#urllib.urlencode({'q': ipoName})
googleURL = "http://www.google.com/search?%s" % query
return json.dumps({
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text": messageStr,
"buttons":[
{
"type":"web_url",
"url":infoURL,
"title":"More Info"
},
{
"type":"web_url",
"url":googleURL,
"title":"Google It!"
},
]
}
}
})
newIPOList = IPOCrawler.refreshData()
if newIPOList:
notifyIPOswithMsg(newIPOList,"Hey, Seems New IPOs are listed.")
#notify Opening Today
openList = IPOHelper.getOpeningTodayIPO()
if openList:
notifyIPOswithMsg(openList,"Knock Knock!! Opening Today!")
#notify closing Today
closeList = IPOHelper.getClosingTodayIPO()
if closeList:
notifyIPOswithMsg(closeList,"Hurry up!! Closing Today!")
#notify runningIPO except opening closing
runningList = IPOHelper.getRunningIPO(True)
if runningList:
notifyIPOswithMsg(runningList,"Hola, Have you subscribed these Yet?.")
DBHelper.removeuser("2")