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

Commit 8a724e0

Browse files
committed
添加监测站点库存更新情况,添加支持命令行运行
添加监测站点库存更新情况,添加支持命令行运行,支持仅监测自定义分类的商品
1 parent f2afc2b commit 8a724e0

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ddmc.monitor
2-
叮咚买菜运力监控。监控叮咚站点首页信息和购物车预约时间信息,通过Bark app通知到手机。
2+
叮咚买菜运力监控,站点库存监控。监控叮咚站点首页信息购物车预约时间信息及站点库存存在日间随机更新的情况,通过Bark app通知到手机。
33

44
## 使用说明
55

@@ -9,7 +9,7 @@
99

1010
### 运行
1111

12-
本脚本提供了两种监控方式
12+
本脚本提供了三种监控方式,修改 run_type 切换
1313

1414
1. **站点首页关键字监控**(免登陆,不会封号但可能封ip,默认使用)
1515
- 抓包获取站点id,填写**station_id**即可
@@ -18,6 +18,9 @@
1818
2. **购物车预约时间监控**(需要登录,有封号风险,谨慎使用)
1919
- 需要填写UA等信息作为header
2020
- 然后`raw_body`填Fiddler里面请求信息的Raw tab最下面的一串url格式的字符串(类似`uid=xxx&longitude=xxx`,购物车点结算-预约时间就有了)
21+
3. **自己站点菜品库存和更新提醒**
22+
- 需要填写 **station_id,longitude, latitude**
23+
- 可以自己从 name_of_all_categories 中挑选并添加或修改自己关心的分类的菜品到 name_of_categories_i_care 中。
2124

2225
执行main.py即可
2326

config.py

+9
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@
1818
api_version = '9.49.2' # ddmc-api-version
1919
build_version = '2.82.0' # ddmc-build-version
2020
raw_body = ''
21+
22+
name_of_all_categories = [
23+
"预制菜", "蔬菜豆制品", "肉禽蛋", "水产海鲜", "水果鲜花", "叮咚特供", "乳品烘焙", "速食冻品", "粮油调味", "酒水饮料", "火锅到家", "熟食卤味",
24+
"休闲零食", "日用百货", "方便食品", "营养早餐", "宝妈严选", "轻养星球", "在家烧烤", "云仓快送"
25+
]
26+
name_of_categories_i_care = [
27+
'预制菜', '蔬菜豆制品', '肉禽蛋', '水产海鲜', '水果鲜花', '叮咚特供', '乳品烘焙', '速食冻品',
28+
"火锅到家", "熟食卤味", "休闲零食", "日用百货", "方便食品", "营养早餐"
29+
]

get_categories.py

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import requests
55
import config
6-
import extract_categories
76

87

98
def send_msg_bark(msg):
@@ -88,7 +87,6 @@ def get_menu_with_category_id(category_id):
8887
r.encoding = 'utf-8'
8988
res = r.json()
9089
menu = {'sub_category_name': res['data']['category_name'], 'products': []}
91-
# menu['count'] = 0
9290
if 'cate' in res['data']:
9391
foods = []
9492
for sub_category in res['data']['cate']:
@@ -97,7 +95,6 @@ def get_menu_with_category_id(category_id):
9795
for product in sub_category['products']:
9896
foods.append(product['name'])
9997
menu['products'] = foods
100-
# menu['count'] = len(foods)
10198
return menu
10299

103100

main.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import requests
22
import time
3+
import sys
34
import config
4-
5-
bark_msg_url = 'https://api.day.app/' + config.bark_id + '/'
5+
from get_categories import check_stock, send_msg_bark
66

77

88
# 检查主页公告 无需cookie
@@ -25,7 +25,7 @@ def check_home():
2525
print('还没有运力!', time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
2626
else:
2727
txt = '叮咚买菜有运力啦!!!'
28-
requests.get(bark_msg_url + txt, params=params)
28+
send_msg_bark(txt)
2929

3030

3131
# 检查购物车 需要cookie
@@ -65,7 +65,7 @@ def check_cart():
6565
all_full = all_full and reserve_time['fullFlag']
6666
if not all_full:
6767
txt = '叮咚买菜可以预约啦!!!最早可预约时间:' + reserve_time['select_msg']
68-
requests.get(bark_msg_url + txt, params=params)
68+
send_msg_bark(txt)
6969
else:
7070
print('还没有可预约时间!')
7171
else:
@@ -76,10 +76,17 @@ def run():
7676
while True:
7777
if config.run_type == 1:
7878
check_home()
79-
else:
79+
elif config.run_type == 2:
8080
check_cart()
81+
else:
82+
check_stock()
8183
time.sleep(config.duration)
8284

8385

8486
if __name__ == '__main__':
87+
# 给在服务器后台执行使用
88+
if len(sys.argv) > 1:
89+
run_type = int(sys.argv[1])
90+
if run_type in [1, 2, 3]:
91+
config.run_type = run_type
8592
run()

0 commit comments

Comments
 (0)