Skip to content

Instantly share code, notes, and snippets.

@ypwhs
Last active September 19, 2023 05:56
Show Gist options
  • Save ypwhs/b93086e748f8c8551521d67dcf3fa9f9 to your computer and use it in GitHub Desktop.
Save ypwhs/b93086e748f8c8551521d67dcf3fa9f9 to your computer and use it in GitHub Desktop.
检查 iPhone 是否有货,有货则语音播报,适用于 macOS
# 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)
# 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)
# 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
Copy link
Author

ypwhs commented Nov 3, 2017

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

@ypwhs
Copy link
Author

ypwhs commented Oct 23, 2020

iPhone 12 Pro 256G 石墨黑色 型号:MGLE3CH/A

@ypwhs
Copy link
Author

ypwhs commented Oct 23, 2020

苹果预约短信号码:10690300496001‬
106930586088001‬

@pudgyLu
Copy link

pudgyLu commented Sep 18, 2022

【2022年版】 iPhone 14 Pro/Pro Max检查官网是否有货

2022年,检查官网 iPhone 14 Pro/Pro Max 是否有货

  • 有货则语音播报
  • 适用于 macOS
  • 需修改 product, store
    • store: 线下取货苹果商店的编号, 参考网址,或参考教程获取商店编号
    • product:手机型号,从苹果商店官网对应的手机型号的网址获取,或参考教程获取设备型号
# 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)

@maxwell5885
Copy link

您好,在google上有看到您的分享,這是僅限mac os下使用嗎?我嘗試用win來執行,似乎不可以

@ypwhs
Copy link
Author

ypwhs commented Sep 19, 2023

您好,在google上有看到您的分享,這是僅限mac os下使用嗎?我嘗試用win來執行,似乎不可以

你好,查询的接口不限制,但是查到了之后的 say 命令仅限 macOS 使用。如果是在 Windows 上,需要使用对应的命令来获得相应的提示。

由于此脚本已经写了多年了,所以接口可能会有变化,请自行调试与修改。

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