-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperiodic.py
51 lines (40 loc) · 1.25 KB
/
periodic.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
from all_imports import *
class UtilPeriodicPrice(Thread):
def __init__(self, prod):
Thread.__init__(self)
self.prod = prod
def run(self):
print 'Running Thread for product :' + self.prod.pid
self.prod.updatePrice()
print 'Completed Thread for product :' + self.prod.pid
def buildpidList():
db = DB()
db.cursor.execute('SELECT id FROM tracking')
pidlist = db.cursor.fetchall()
return pidlist
def buildDetailsList():
db = DB()
for pid in pidlist:
t = UtilPeriodicPrice(Product(pid[0]))
t.start()
t.join()
time.sleep(4)
def mailLastEntries(n):
db = DB()
updates = db.lastPriceEntries(n)
mail = Mail()
mail.setSub('Amazon Updates')
msg = ''
for upd in updates:
msg = msg + '<a href="http://www.amazon.in/gp/product/' + \
upd[0] + '" traget="_blank">' + upd[7] + '</a><br>'
msg = msg + \
('Rs. ' + str(upd[1]) + ', Rs. ' + str(
upd[2]) + ', Rs. ' + str(upd[3])) + '<br>'
msg = msg + ('Bookprice : ' + upd[4]) + '<br>'
msg = msg + ('Updated @ ' + upd[5]) + '<br><br>'
mail.setMsg(msg)
mail.send()
pidlist = buildpidList()
buildDetailsList()
mailLastEntries(len(pidlist))