-
Notifications
You must be signed in to change notification settings - Fork 0
/
BWG.py
46 lines (36 loc) · 1.38 KB
/
BWG.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from BWG_DB import BWGProductDao
import BWG_Spider
from common import Config
from common.Mail import Email_Test_Sender
from common import HtmlUtil
import time
if __name__ == "__main__":
count = 1
while(True):
print "--------------------------------"
print "第 {0} 次爬取数据".format(count)
pruductList = BWG_Spider.getProductListFromHomePage()
# 保存数据库到数据库
bwgProductDao = BWGProductDao()
for key in pruductList:
if bwgProductDao.exicts(key):
bwgProductDao.update(pruductList[key])
else:
bwgProductDao.save(pruductList[key])
# 检查是否能预订,如果能预订加入到可预订列表
bwgProductDao = BWGProductDao()
wantList = {}
for pName in Config.PRODUCTS_WANT_ORDER:
if bwgProductDao.canOrder(pName):
wantList[pName] = bwgProductDao.get(pName)
print "\tCan order:" + pName
if len(wantList) > 0:
# 构建邮件
text = HtmlUtil.getMailHtml(wantList)
# 发送邮件
mailSender = Email_Test_Sender(Config.MAIL_USERNAME, Config.MAIL_PASSWORD)
mailSender.sendMsg(Config.MAIL_USERNAME, "Bandwagonhost", text)
count = count + 1
time.sleep(Config.SPACE_TIME)