https://www.apple.com.cn/shop/fulfillment-messages?pl=true&parts.0=MLTE3CH/A&location=%E5%B9%BF%E4%B8%9C%20%E5%B9%BF%E5%B7%9E%20%E5%A4%A9%E6%B2%B3%E5%8C%BA
很容易找到供货情况的接口是这个
盲猜是这个 storeSelectionEnabled 字段影响的,因为只有它是 False,当然也有猜过是下面的 pickupDisplay,但从命名来看,第一个才是影响是否可选中的字段
import requests
def get_phone():
res = requests.get(
"https://www.apple.com.cn/shop/fulfillment-messages?pl=true&parts.0=MLTE3CH/A&location=%E5%B9%BF%E4%B8%9C%20%E5%B9%BF%E5%B7%9E%20%E5%A4%A9%E6%B2%B3%E5%8C%BA",
verify=False)
res = res.json()["body"]["content"]["pickupMessage"]["stores"]
for num, item in enumerate(res):
phone = item["partsAvailability"]["MLTE3CH/A"]
storeSelectionEnabled = phone["storeSelectionEnabled"]
storePickupQuote = phone["storePickupQuote"]
pickupSearchQuote = phone["pickupSearchQuote"]
if storeSelectionEnabled:
res = {
"可取货": storeSelectionEnabled,
"取货状态": storePickupQuote,
"供应状态": pickupSearchQuote
}
yield res
https://cloud.tencent.com/developer/article/1902790
import requests
# 获取手机供货信息
def get_phone():
res = requests.get(
"https://www.apple.com.cn/shop/fulfillment-messages?pl=true&parts.0=MLTE3CH/A&location=%E5%B9%BF%E4%B8%9C%20%E5%B9%BF%E5%B7%9E%20%E5%A4%A9%E6%B2%B3%E5%8C%BA",
verify=False)
res = res.json()["body"]["content"]["pickupMessage"]["stores"]
for num, item in enumerate(res):
phone = item["partsAvailability"]["MLTE3CH/A"]
storeSelectionEnabled = phone["storeSelectionEnabled"]
storePickupQuote = phone["storePickupQuote"]
pickupSearchQuote = phone["pickupSearchQuote"]
if storeSelectionEnabled:
res = {
"可取货": storeSelectionEnabled,
"取货状态": storePickupQuote,
"供应状态": pickupSearchQuote
}
yield res
# python 3.8
import time
import hmac
import hashlib
import base64
import urllib.parse
# 加签
timestamp = str(round(time.time() * 1000))
secret = '此处填写 webhook token'
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
def dingmessage():
# 请求的URL,WebHook地址
webhook = f"https://oapi.dingtalk.com/robot/send?access_token={token}×tamp={timestamp}&sign={sign}"
# 构建请求头部
header = {"Content-Type": "application/json", "Charset": "UTF-8"}
# 循环生成器并发送消息
for phone in get_phone():
message = {
"msgtype": "text",
"text": {"content": phone},
"at": {
# @ 所有人
"isAtAll": True
}
}
message_json = json.dumps(message)
info = requests.post(url=webhook, data=message_json, headers=header, verify=False) # 打印返回的结果
print(info.text)
if __name__ == "__main__":
dingmessage()
运行一下
我的是 mac 电脑,所有有自带 crontab,命令行敲
sudo crontab -e
*/1 * * * * /usr/local/opt/python@3.9/bin/python3.9 /Users/test.py
保存,会有成功信息
> sudo crontab -e
crontab: installing new crontab
sudo crontab -l
过一分钟后去看钉钉就可以了!
若遇到定时任务无法运行,可以看看这篇