-
Notifications
You must be signed in to change notification settings - Fork 0
/
reports.py
75 lines (66 loc) · 2.78 KB
/
reports.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
import datetime, time
from smtp import mail
from mysql import Sql
from Format import store_trans, time_zone
from maintain_price import MaintainPrice
class Reports():
def __init__(self):
db_test = {'host': 'www.veatao.com', 'port': 3306, 'user': 'test', 'password': 'sz123456', 'db': 'test'}
self.sql_element = Sql(**db_test)
def reports_in(self, fromStore, price):
reports = {}
reports['reports_type'] = '订单爬虫报告'
reports['store_name'] = store_trans(fromStore)
reports['reports_date'] = datetime.date.today()
temp = reports.copy()
res = self.sql_element.select_data("spider_reports", 1, *['count', 'price'], **reports)
if res:
reports['count'] = res[0][0] + 1
reports['price'] = res[0][1] + price
self.sql_element.update_old_data("spider_reports", reports, temp)
else:
reports['count'] = 1
reports['price'] = price
self.sql_element.insert_new_data("spider_reports", **reports)
def reports_mail(self):
# results = self.sql_element.select_dict("""select * from spider_reports
# where reports_date='%s'
# """ % (str(datetime.date.today())))
# string = ""
# for result in results:
# if result['reports_type'] == '订单爬虫报告':
# string += str(result['reports_date']) + " "
# string += result['store_name'] + " " + result['reports_type'] + ":\n"
# string += "今日共爬取新订单数:" + str(result['count']) + " 条\n"
# string += "订单总金额:" + str(result['price']) + " 元\n"
# elif result['reports_type'] == '优惠差额报告':
# string += str(result['reports_date']) + " "
# string += result['store_name'] + " " + result['reports_type'] + ":\n"
# string += "今日导入修正订单优惠价格数量:" + str(result['count']) + " 条\n"
# string += "总优惠金额:" + str(result['price']) + " 元\n"
# print(result)
# print(string)
# mail('订单爬虫报告', string, ['[email protected]', '[email protected]'])
mail('订单爬虫报告', "abc", ['[email protected]'])
def run():
t = time_zone(["23:00", "23:10"])
t1, t2 = t[0], t[1]
while True:
now = datetime.datetime.now()
if t1 < now < t2:
r = Reports()
m = MaintainPrice()
m.report_mail()
r.reports_mail()
break
print(">", end="", flush=True)
time.sleep(1)
while True:
now = datetime.datetime.now()
if now > t2:
break
print(">", end="", flush=True)
time.sleep(1)
run()
if __name__ == '__main__':
run()