"""
@author : v_jiaohaicheng@baidu.com
@des :
"""
from sdk.utils.util_network import NetWorkRequests
from sdk.utils.util_times import TimeProcess
import time
import win32com.client
import random
class GetApples():
def __init__(self):
self.req = NetWorkRequests()
self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
self.time = TimeProcess()
def check_status(self):
headers = {
"authority": "securemetrics.apple.com.cn",
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9",
"content-type": "application/x-www-form-urlencoded",
"dnt": "1",
"modelversion": "v2",
"origin": "https://secure5.www.apple.com.cn",
"referer": "https://secure5.www.apple.com.cn/",
"sec-ch-ua": "\"Chromium\";v=\"118\", \"Google Chrome\";v=\"118\", \"Not=A?Brand\";v=\"99\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "no-cors",
"sec-fetch-site": "same-site",
"syntax": "graviton",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"x-aos-model-page": "checkoutPage",
"x-aos-stk": "9NF6vlZlwU9_uPff8B14WbqbA7s",
"x-requested-with": "Fetch",
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.9",
"Connection": "keep-alive",
"DNT": "1",
"Origin": "https://secure5.www.apple.com.cn",
"Referer": "https://secure5.www.apple.com.cn/",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "cross-site",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"content-length": "0"
}
cookies = {
"dssf": "1",
"dssid2": "7c1cb882-4115-459c-a41f-d15c2a878057",
"as_sfa": "Mnxjbnxjbnx8emhfQ058Y29uc3VtZXJ8aW50ZXJuZXR8MHwwfDE",
"as_pcts": "9yD6PUMobdDlBE4nSDSBxeLLAdmlTSPh:Hnj74:4D2LY3zpmT09nUovI9DerILs55pL93ceRf:97HX3qDpsfsCvhH21xPAcoSUeU-j:hGmTCX:LMcb1GaHzKwkgJ+BwsbgULtVYHRz9VZng",
"s_fid": "434AC41E069DFBBE-2D9F7C1E195D47F5",
"s_cc": "true",
"as_uct": "2",
"as_dc": "ucp2",
"s_vi": "[CS]v1|3295DC95FB770DA6-40000E3AD00F2D15[CE]",
"as_ltn_cn": "AAQEAMB6h6M1A0qOcJX9EqA4spju_oy5w-cVTzQ7DBx74LgpdPd6qxJ3-vVO54NxLUv4KChSVdkzRkizxd4juDgDyslm3JUHrLg",
"s_sq": "%5B%5BB%5D%5D"
}
url = "https://secure5.www.apple.com.cn/shop/checkoutx"
params = {
"_a": "search",
"_m": "checkout.fulfillment.pickupTab.pickup.storeLocator"
}
data = {
"checkout.fulfillment.pickupTab.pickup.storeLocator.showAllStores": "false",
"checkout.fulfillment.pickupTab.pickup.storeLocator.selectStore": "",
"checkout.fulfillment.pickupTab.pickup.storeLocator.searchInput": "北京 东城区",
"checkout.fulfillment.pickupTab.pickup.storeLocator.address.stateCitySelectorForCheckout.city": "北京",
"checkout.fulfillment.pickupTab.pickup.storeLocator.address.stateCitySelectorForCheckout.state": "北京",
"checkout.fulfillment.pickupTab.pickup.storeLocator.address.stateCitySelectorForCheckout.provinceCityDistrict": "北京 东城区",
"checkout.fulfillment.pickupTab.pickup.storeLocator.address.stateCitySelectorForCheckout.countryCode": "",
"checkout.fulfillment.pickupTab.pickup.storeLocator.address.stateCitySelectorForCheckout.district": "东城区"
}
proxies = {
"http": "http://127.0.0.1:1080",
"https": "http://127.0.0.1:1080",
}
response = self.req._requests(url=url, headers=headers, cookies=cookies, params=params, data=data, proxies=proxies)
return response
def anlise_result(self, result):
for info in \
result["body"]["checkout"]["fulfillment"]["pickupTab"]["pickup"]["storeLocator"]["searchResults"]["d"]["retailStores"]:
name, status = info["storeName"], 0 if info["availability"]["storeAvailability"] == "目前不可取货" else 1
print(self.time.get_normal_date(), name, status)
if status == 1:
self.speaker.Speak(name + "有现货")
time.sleep(random.randint(50, 70))
def run(self):
while True:
response = self.check_status()
if response["status"] == 0:
print(response["msg"].status_code)
if response["msg"].status_code == 200:
self.anlise_result(response["msg"].json())
if __name__ == '__main__':
ga = GetApples()
ga.run()