[Python] 纯文本查看 复制代码
from time import sleep
import requests
import json
from datetime import datetime
from datetime import timedelta
from datetime import timezone
from corpwechatbot import AppMsgSender
# 访问该地址转经纬度地址
# https://lbs.amap.com/tools/picker
#按关键字搜索栏目下填入你的地址 如 上海黄浦区人名广场
# 默认通知使用的是企业微信接口,如果您有企业微信接口填入您的信息即可使用
# 通知方式可以是邮箱、微信接口或是qq接口,请自行添加,可以搜索todo,在todo之后适合地方添加即可
def appMsgSender(content):
app = AppMsgSender(corpid='', # 你的企业id
corpsecret='', # 你的应用凭证密钥
agentid='') # 你的应用id
app.send_text(content)
def btime():
SHA_TZ = timezone(
timedelta(hours=8),
name='Asia/Shanghai',
)
# 协调世界时
utc_now = datetime.utcnow().replace(tzinfo=timezone.utc)
# print(utc_now, utc_now.tzname())
# 北京时间
beijing_now = utc_now.astimezone(SHA_TZ)
# print(beijing_now, beijing_now.tzname())
# 系统默认时区
local_now = utc_now.astimezone()
# print(local_now, local_now.tzname())
return beijing_now
def checkkfcinit():
url = "https://m.4008823823.com.cn/taroapi/base/v2/initial"
payload = json.dumps({
"body": {},
"portalType": "kfc_delivery_h5",
"portalSource": "KFC_WEB",
"appVerParams": {
"hotUpdateLabel": "updateLabel"
},
})
headers = {
'Content-Type': 'application/json',
'Accept': '*/*',
'host': 'm.4008823823.com.cn',
}
response = requests.request("POST", url, headers=headers, data=payload.encode(), timeout=10000)
resjson = json.loads(response.text)
# print(resjson['userUniqueId'])
# print(response.text)
if len(resjson['userUniqueId']) == 36:
uuid = str(resjson['userUniqueId'])
else:
print(f"{btime()} : unable get uuid")
# [i]todo Notify you of status changes
[/i][i] [/i]appMsgSender(f"{btime()} : unable get uuid")
return uuid
def checkkfcstatus(city,longitude,latitude,uuid):
url = "https://m.4008823823.com.cn/taroapi/misc/v2/getNearestStore"
if city == 'shanghai':
citycode = "00010"
elif city == 'nanjing':
citycode = "00008"
else:
return None
payload = json.dumps({
# "body": {
# "webValidateCustomerAddress": {
# "cityCode": "00008",
# "longitude": "",
# "latitude": "",
# "mainAddress": "1",
# "supplementalAddress": "1"
# }
"body": {
"webValidateCustomerAddress": {
"cityCode": citycode,
"longitude": longitude,
"latitude": latitude,
"mainAddress": "1",
"supplementalAddress": "1"
}
},
"portalType": "kfc_delivery_h5",
"portalSource": "KFC_WEB",
"userUniqueId": uuid,
"appVerParams": {
"hotUpdateLabel": "updateLabel"
},
})
headers = {
'Content-Type': 'application/json',
'Accept': '*/*',
'host': 'm.4008823823.com.cn',
}
responseall = requests.request("POST", url, headers=headers, data=payload.encode(), timeout=10000)
resjson = json.loads(responseall.text)
print(responseall.text)
# print(resjson["data"]["webNearestStore"])
if resjson["data"]["webNearestStore"] != None:
print(f"{btime()},{city},{longitude},{latitude},status : True")
print("快去打开app点餐吧!")
# [i]todo Notify you of status changes
[/i][i] [/i]appMsgSender(f"{btime()} : success!!!!!!!!!!")
# Stop after notify you
return True
else:
print(f"{btime()},{city},{longitude},{latitude},status : False")
print("没开门呢!")
return False
if __name__ == '__main__':
# [i]todo Notify you of status changes
[/i][i] [/i]appMsgSender(f"{btime()} : task begin")
# 要改的参数就三个值 城市名 上海 = shanghai 南京 = nanjing,其他城市不支持,经纬度自己填,先是精度再是纬度。
# Stop after notify you
# while checkkfcstatus("shanghai",121.627531,31.181985,checkkfcinit()) == False:
# Always check
while 1 == 1:
checkkfcstatus("shanghai",121.627531,31.181985,checkkfcinit())
#300秒一次,自行修改,不要小于60秒
sleep(300)