Instantly share code, notes, and snippets.

Embed
What would you like to do?
检查 iPhone 是否有货,有货则语音播报,适用于 macOS
# coding: utf-8
import requests
import time
import os
store = 'https://reserve-cn.apple.com/CN/zh_CN/reserve/iPhone/stores.json'
target = [('R388', '西单'), ('R448', '王府井')]
black = 'MNFP2CH/A'
availability = 'https://reserve-cn.apple.com/CN/zh_CN/reserve/iPhone/availability.json?t='
i = 0
while True:
try:
state = requests.get(availability + str(time.time())).json()
i += 1
for t in target:
print state[t[0]][black],
if state[t[0]][black] != 'NONE':
os.system('say ' + t[1])
if i % 15 == 0:
print ''
time.sleep(1)
except:
print '还没开始'
# coding: utf-8
import requests
import time
import os
store_url = 'https://reserve-prime.apple.com/CN/zh_CN/reserve/iPhoneX/stores.json'
stores = [('R388', '西单'), ('R448', '王府井')]
product = 'MQA82CH/A'
availability_url = 'https://reserve-prime.apple.com/CN/zh_CN/reserve/iPhoneX/availability.json'
s = requests.Session()
s.headers['User-Agent'] = 'Mozilla/5.0'
i = 0
while True:
try:
availability = s.get(availability_url).json()
i += 1
for store in stores:
iphone_state = availability['stores'][store[0]][product]['availability']['unlocked']
print i, '\t', store[1], '\t', availability['stores'][store[0]][product]
if iphone_state:
os.system('say ' + store[1])
except:
print '还没开始'
time.sleep(1)
@ypwhs

This comment has been minimized.

Owner

ypwhs commented Nov 3, 2017

iPhone X 256G 深空灰色 型号:MQA82CH/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment