Untitled
unknown
plain_text
a year ago
2.4 kB
12
Indexable
Never
import requests from urllib.parse import urlencode import json from time import gmtime, strftime cache = {} def get_ranking(region, category): if (region, category) in cache: return cache[(region, category)] url = 'https://web.np.playstation.com/api/graphql/v1//op?operationName=categoryGridRetrieve&variables={"id":"28c9c2b2-cecc-415c-9a08-482a605cb104","pageArgs":{"size":%s,"offset":0},"sortBy":{"name":"%s","isAscending":false},"filterBy":[],"facetOptions":["ageRating","conceptGenres","conceptReleaseDate","conceptVrCompatibility","webBasePrice","productGenres","productReleaseDate","productVrCompatibility","storeDisplayClassification","targetPlatforms"],"maxResults":null}&extensions={"persistedQuery":{"version":1,"sha256Hash":"4ce7d410a4db2c8b635a48c1dcec375906ff63b19dadd87e073f8fd0c0481d35"}}' url = url % (500, category) headers = {'x-psn-store-locale-override': region} data = json.loads(requests.get(url, headers=headers).text) namelist = [x["name"] for x in data["data"]["categoryGridRetrieve"]["concepts"]] cache[(region, category)] = namelist return namelist def download_ranking(name, region): namelist = get_ranking(region, "downloads30") if name in namelist: return namelist.index(name) else: return "圈外( >500 )" def sell_ranking(name, region): namelist = get_ranking(region, "sales30") if name in namelist: return namelist.index(name) else: return "圈外( >500 )" print(strftime("%Y-%m-%d %H:%M:%S UTC", gmtime())) for name in ["Forspoken", "FINAL FANTASY XVI"]: print("\n\n", name) print("\n按销售排名") print("日本:", sell_ranking(name, "ja-JP")) print("美国:", sell_ranking(name, "en-US")) print("德国:", sell_ranking(name, "de-DE")) print("英国:", sell_ranking(name, "en-GB")) print("加拿大:", sell_ranking(name, "en-CA")) print("法国:", sell_ranking(name, "fr-FR")) print("新西兰:", sell_ranking(name, "en-NZ")) print("\n按下载排名") print("日本:", download_ranking(name, "ja-JP")) print("美国:", download_ranking(name, "en-US")) print("德国:", download_ranking(name, "de-DE")) print("英国:", download_ranking(name, "en-GB")) print("加拿大:", download_ranking(name, "en-CA")) print("法国:", download_ranking(name, "fr-FR")) print("新西兰:", download_ranking(name, "en-NZ"))