|
| 1 | +import requests |
| 2 | +import time |
| 3 | +import config |
| 4 | + |
| 5 | +bark_msg_url = 'https://api.day.app/' + config.bark_id + '/' |
| 6 | + |
| 7 | + |
| 8 | +# 检查主页公告 无需cookie |
| 9 | +def check_home(): |
| 10 | + url = 'https://maicai.api.ddxq.mobi/homeApi/newDetails' |
| 11 | + payload = {'station_id': config.station_id} |
| 12 | + r = requests.get(url, params=payload) |
| 13 | + if r.status_code == 200: |
| 14 | + r.encoding = 'utf-8' |
| 15 | + res = r.json() |
| 16 | + if res['code'] == 0: |
| 17 | + find = r.text.find(config.key_word) |
| 18 | + params = {'group': '叮咚买菜'} |
| 19 | + print(res) |
| 20 | + if find > 0: |
| 21 | + txt = '叮咚买菜有运力啦!!!' |
| 22 | + requests.get(bark_msg_url + txt, params=params) |
| 23 | + else: |
| 24 | + print('还没有运力!', time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) |
| 25 | + |
| 26 | + |
| 27 | +# 检查购物车 需要cookie |
| 28 | +def check_cart(): |
| 29 | + url = 'https://maicai.api.ddxq.mobi/order/getMultiReserveTime' |
| 30 | + headers = {'Cookie': config.cookie, |
| 31 | + 'Connection': 'keep-alive', |
| 32 | + 'Content-Type': 'application/x-www-form-urlencoded', |
| 33 | + 'User-Agent': config.ua, |
| 34 | + 'ddmc-api-version': '9.49.1', |
| 35 | + 'ddmc-app-client-id': '4', |
| 36 | + 'ddmc-build-version': '2.81.4', |
| 37 | + 'ddmc-channel': 'applet', |
| 38 | + 'ddmc-city-number': config.city_number, |
| 39 | + 'ddmc-device-id': config.device_id, |
| 40 | + 'ddmc-ip': '', |
| 41 | + 'ddmc-latitude': config.latitude, |
| 42 | + 'ddmc-longitude': config.longitude, |
| 43 | + 'ddmc-os-version': '[object Undefined]', |
| 44 | + 'ddmc-station-id': config.station_id, |
| 45 | + 'ddmc-uid': config.uid, |
| 46 | + 'Accept-Encoding': 'gzip,compress,br,deflate', |
| 47 | + 'Referer': 'https://servicewechat.com/wx1e113254eda17715/421/page-frame.html', |
| 48 | + } |
| 49 | + raw = config.raw_body |
| 50 | + r = requests.post(url, headers=headers, data=raw) |
| 51 | + if r.status_code == 200: |
| 52 | + r.encoding = 'utf-8' |
| 53 | + res = r.json() |
| 54 | + print(res) |
| 55 | + if res['code'] == 0: |
| 56 | + reserve_times = res['data'][0]['time'][0]['times'] |
| 57 | + params = {'group': '叮咚买菜'} |
| 58 | + for reserve_time in reserve_times: |
| 59 | + if not reserve_time['fullFlag']: |
| 60 | + txt = '叮咚买菜可以预约啦!!!最早可预约时间:' + reserve_time['select_msg'] |
| 61 | + requests.get(bark_msg_url + txt, params=params) |
| 62 | + break |
| 63 | + else: |
| 64 | + print('还没有可预约时间!') |
| 65 | + |
| 66 | + |
| 67 | +def run(): |
| 68 | + while True: |
| 69 | + if config.run_type == 1: |
| 70 | + check_home() |
| 71 | + else: |
| 72 | + check_cart() |
| 73 | + time.sleep(config.duration) |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == '__main__': |
| 77 | + run() |
0 commit comments