Last active
September 19, 2023 05:56
-
-
Save ypwhs/b93086e748f8c8551521d67dcf3fa9f9 to your computer and use it in GitHub Desktop.
检查 iPhone 是否有货,有货则语音播报,适用于 macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import requests | |
import time | |
import os | |
import urllib3 | |
urllib3.disable_warnings() | |
store_url = 'https://reserve-prime.apple.com/CN/zh_CN/reserve/A/stores.json' | |
products = 'https://reserve-prime.apple.com/CN/zh_CN/reserve/A/availability?iUP=N' | |
availability_url = 'https://reserve-prime.apple.com/CN/zh_CN/reserve/A/availability.json' # iPhone 12 Pro | |
# availability_url = 'https://reserve-prime.apple.com/CN/zh_CN/reserve/F/availability.json' # iPhone 12 | |
stores = [('R388', '西单'), ('R448', '王府井'), ('R320', '三里屯')] | |
# stores = [('R320', '三里屯')] | |
product = 'MGLE3CH/A' # iPhone 12 Pro 256G 石墨黑色 | |
# product = 'MGGU3CH/A' # iPhone 12 128GB 黑色 | |
product = 'MGLF3CH/A' # iPhone 12 Pro 256G 银色 | |
product = 'MGL93CH/A' # iPhone 12 Pro 128G 石墨色 | |
product = 'MGLA3CH/A' # iPhone 12 Pro 128G 银色 | |
products = [ | |
('MGL93CH/A', 'iPhone 12 Pro 128G 石墨色'), | |
('MGLA3CH/A', 'iPhone 12 Pro 128G 银色'), | |
('MGLE3CH/A', 'iPhone 12 Pro 256G 石墨黑色'), | |
('MGLF3CH/A', 'iPhone 12 Pro 256G 银色'), | |
] | |
print('店铺:', stores) | |
print('型号:', product) | |
s = requests.Session() | |
s.headers['User-Agent'] = 'Mozilla/5.0' | |
i = 0 | |
while True: | |
i += 1 | |
try: | |
availability = s.get(availability_url, verify=False).json() | |
for store in stores: | |
for product in products: | |
product_availability = availability['stores'][store[0]][product[0]] | |
unlocked_state = product_availability['availability']['unlocked'] | |
print(i, '\t', store[1], '\t', product[1], '\t', product_availability) | |
if unlocked_state: | |
os.system('say ' + store[1] + product[1]) | |
except Exception as e: | |
print(i, '还没开始', e) | |
time.sleep(1) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import requests | |
import time | |
import os | |
import urllib3 | |
import logging | |
logging.basicConfig(format='%(levelname)s:%(name)s:%(asctime)s %(message)s', level=logging.DEBUG) | |
urllib3.disable_warnings() | |
store_url = 'https://reserve-prime.apple.com/CN/zh_CN/reserve/A/stores.json' | |
availability_url = 'https://reserve-prime.apple.com/CN/zh_CN/reserve/A/availability.json' | |
stores = [ | |
('R388', '西单大悦城'), | |
('R448', '王府井'), | |
('R320', '三里屯'), | |
('R645', '朝阳大悦城'), | |
('R479', '华贸购物中心') | |
] | |
products = [ | |
('MQ1R3CH/A', 'iPhone 14 Pro 512G 银色'), | |
('MQ1J3CH/A', 'iPhone 14 Pro 512G 深空黑色'), | |
('MQ263CH/A', 'iPhone 14 Pro 512G 暗紫色'), | |
('MQ0W3CH/A', 'iPhone 14 Pro 256G 银色'), | |
('MQ1C3CH/A', 'iPhone 14 Pro 256 暗紫色'), | |
] | |
s = requests.Session() | |
s.headers['User-Agent'] = 'Mozilla/5.0' | |
i = 0 | |
while True: | |
i += 1 | |
try: | |
availability = s.get(availability_url, verify=False).json() | |
logging.info(f'\n\n') | |
logging.info(f'{i}'.center(64, '=')) | |
for store in stores: | |
for product in products: | |
product_availability = availability['stores'][store[0]][product[0]] | |
unlocked_state = product_availability['availability']['unlocked'] | |
logging.info(f'{store[1]}, {product[1]}: {product_availability}') | |
if unlocked_state: | |
logging.info(f'有!!'.center(64, '=')) | |
logging.info(f'有!!'.center(64, '=')) | |
logging.info(f'有!!'.center(64, '=')) | |
os.system('say ' + store[1] + product[1]) | |
except Exception as e: | |
logging.info(i, '还没开始', e) | |
time.sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 '还没开始' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你好,查询的接口不限制,但是查到了之后的 say 命令仅限 macOS 使用。如果是在 Windows 上,需要使用对应的命令来获得相应的提示。
由于此脚本已经写了多年了,所以接口可能会有变化,请自行调试与修改。