-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.py
78 lines (64 loc) · 2 KB
/
main.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
# -*- coding: utf-8 -*-
# @Author: wujiyu
# @Date: 2017-02-26 22:49:03
# @Last Modified by: wujiyu
# @Last Modified time: 2017-03-27 12:25:07
import requests
import logging
# requests.packages.urllib3.disable_warnings()
import datetime
import time
import os
import traceback
from util.configutil import ConfigUtil
from util.mylog import install_log, info, critical
from util.cookie_util import has_cookies
from util.date_util import DateUtil
from util.utils import clear_output
import schedule
from src.meican import MeiCan
from src.errcode import desc as Desc
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def order(meican):
try:
order_week = ConfigUtil.instance().order_week
cur_week = str(DateUtil.curr_week())
if cur_week not in order_week:
critical("meican | order week not in config!!!!!!!!!!!!, cur_week:<%s>"%cur_week)
return
info("meican |begin order")
meican.order()
except Exception as e:
info(traceback.format_exc())
def do_job():
try:
info("I'm working on : <%s>"%datetime.datetime.now())
except Exception as e:
info(traceback.format_exc())
if __name__ == '__main__':
install_log()
info("start meican robot")
meican = None
login_ok = False
if has_cookies():
meican = MeiCan('','')
login_ok = meican.login()
else:
while not login_ok:
username = raw_input('[ Enter meican email ]:')
password = raw_input('[ Enter meican password ]:')
meican = MeiCan(username,password)
login_ok = meican.login()
clear_output()
limit_lst = meican.get_order_time_lst()
for time_item in limit_lst:
time_str = "%s:%s"%(time_item.hour, time_item.minute)
schedule.every(1).day.at(time_str).do(order, meican)
info("meican | next order time: | [[%s]]"%schedule.next_run())
# meican.order()
# schedule.every(1).hour.do(do_job)
while True:
schedule.run_pending()
time.sleep(1)