Skip to content
This repository was archived by the owner on Oct 31, 2022. It is now read-only.

Commit 351abc5

Browse files
committed
init repo
1 parent 010d060 commit 351abc5

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
.idea/

README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
11
# ddmc.monitor
2-
叮咚买菜 运力监控
2+
叮咚买菜运力监控。监控叮咚站点首页信息和购物车预约时间信息,通过Bark app通知到手机。
3+
4+
## 使用说明
5+
6+
### 抓包
7+
8+
首先需要自己使用Fiddler等工具对叮咚买菜小程序抓包(PC小程序比较方便),获取`config.py`中需要的参数。
9+
10+
### 运行
11+
12+
本脚本提供了两种监控方式:
13+
14+
1. **站点首页关键字监控**(免登陆,不会封号但可能封ip,默认使用)
15+
- 抓包获取站点id,填写**station_id**即可
16+
- 关键词不存在时则提醒(关键词为`由于近期疫情问题,配送运力紧张,本站点当前运力已约满`)
17+
- 可能相比购物车有延迟
18+
2. **购物车预约时间监控**(需要登录,有封号风险,谨慎使用)
19+
- 需要填写UA等信息作为header
20+
- 然后`raw_body`填Fiddler里面请求信息的Raw tab最下面的一串url格式的字符串(类似`uid=xxx&longitude=xxx`)
21+
22+
执行main.py即可
23+
24+
## 依赖
25+
- python3
26+
- requests
27+
28+
## 声明
29+
30+
仅供学习交流使用,请勿用于非法用途。

config.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
station_id = '' # 站点id
2+
bark_id = '' # bark app通知id
3+
duration = 15 # 执行间隔时间秒
4+
run_type = 1 # 监控类型 1首页监控 2购物车监控
5+
key_word = '由于近期疫情问题,配送运力紧张,本站点当前运力已约满'
6+
7+
# 以下参数是购物车监控需要填的
8+
ua = '' # User-Agent
9+
cookie = 'DDXQSESSID=XXXXX' # 账号cookie 类似:DDXQSESSID=XXXXX
10+
city_number = '0101' # ddmc-city-number 0101上海
11+
device_id = '' # ddmc-device-id
12+
longitude = '' # ddmc-longitude
13+
latitude = '' # ddmc-latitude
14+
uid = '' # ddmc-uid
15+
16+
raw_body = ''
17+

main.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)