forked from LessYellowFish/imaotai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (51 loc) · 2.12 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
#!/usr/bin/python3
import logging
import sys
import config
import login
import process
DATE_FORMAT = "%m/%d/%Y %H:%M:%S %p"
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(filename)s : %(levelname)s %(message)s', # 定义输出log的格式
stream=sys.stdout,
datefmt=DATE_FORMAT)
# 获取当日session id
process.get_current_session_id()
configs = login.config
if len(configs.sections()) == 0:
logging.error("配置文件未找到配置")
sys.exit(1)
for section in configs.sections():
mobile = section
province = configs.get(section, 'province')
city = configs.get(section, 'city')
token = configs.get(section, 'token')
userId = configs.get(section, 'userid')
lat = configs.get(mobile, 'lat')
lng = configs.get(mobile, 'lng')
p_c_map, source_data = process.get_map(lat=lat, lng=lng)
process.UserId = userId
process.TOKEN = token
process.init_headers(user_id=userId, token=token, lng=lng, lat=lat)
# 根据配置中,要预约的商品ID,城市 进行自动预约
try:
for item in config.ITEM_CODES:
max_shop_id = process.get_location_count(province=province,
city=city,
item_code=item,
p_c_map=p_c_map,
source_data=source_data,
lat=lat,
lng=lng)
print(f'max shop id : {max_shop_id}')
if max_shop_id == '0':
continue
shop_info = source_data.get(str(max_shop_id))
title = config.ITEM_MAP.get(item)
logging.info(f'商品:{title}, 门店:{shop_info["name"]}')
reservation_params = process.act_params(max_shop_id, item)
process.reservation(reservation_params, mobile)
process.getUserEnergyAward(mobile)
except BaseException as e:
print(e)
logging.error(e)