From c20c3c10635ce78db4a86ce9c0bb1d02e90f525d Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期二, 08 八月 2023 17:40:42 +0800 Subject: [PATCH] 单例+缓存优化 --- third_data/kpl_api.py | 36 +++++++++++++++++++++++++++++++++--- 1 files changed, 33 insertions(+), 3 deletions(-) diff --git a/third_data/kpl_api.py b/third_data/kpl_api.py index ea86177..05eae55 100644 --- a/third_data/kpl_api.py +++ b/third_data/kpl_api.py @@ -23,9 +23,11 @@ raise Exception("璇锋眰鍑洪敊") result = response.text result = json.loads(result) + print(result) if int(result["errcode"]) != 0: return None - return result["ListJX"] + return result["ListJX"] if result["ListJX"] else result["List"] + # 鑾峰彇姒傚康浠g爜 def getCodesByPlate(plate_code): @@ -48,7 +50,7 @@ # 甯傚満琛屾儏-琛屼笟 def getMarketIndustryRealRankingInfo(orderJingE_DESC=True): - data = f"Order={ 1 if orderJingE_DESC else 0}&a=RealRankingInfo&st=80&apiv=w32&Type=5&c=ZhiShuRanking&PhoneOSNew=1&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&VerSion=5.8.0.2&Index=0&ZSType=4&" + data = f"Order={1 if orderJingE_DESC else 0}&a=RealRankingInfo&st=80&apiv=w32&Type=5&c=ZhiShuRanking&PhoneOSNew=1&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&VerSion=5.8.0.2&Index=0&ZSType=4&" response = __base_request("https://apphq.longhuvip.com/w1/api/index.php", data=data) if response.status_code != 200: @@ -58,10 +60,38 @@ # 甯傚満琛屾儏-绮鹃�� def getMarketJingXuanRealRankingInfo(orderJingE_DESC=True): - data = f"Order={ 1 if orderJingE_DESC else 0}&a=RealRankingInfo&st=80&apiv=w32&Type=5&c=ZhiShuRanking&PhoneOSNew=1&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&VerSion=5.8.0.2&Index=0&ZSType=7&" + data = f"Order={1 if orderJingE_DESC else 0}&a=RealRankingInfo&st=80&apiv=w32&Type=5&c=ZhiShuRanking&PhoneOSNew=1&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&VerSion=5.8.0.2&Index=0&ZSType=7&" response = __base_request("https://apphq.longhuvip.com/w1/api/index.php", data=data) if response.status_code != 200: raise Exception("璇锋眰鍑洪敊") return response.text + +# 鑾峰彇浠g爜鐨勭簿閫夋澘鍧� +# 杩斿洖鏍煎紡锛歔(鏉垮潡浠g爜,鏉垮潡鍚嶇О,娑ㄥ箙鐧惧垎姣�)] +def getCodeJingXuanBlocks(code): + data = f"a=GetStockIDPlate&apiv=w32&Type=2&c=StockL2Data&StockID={code}&PhoneOSNew=1&UserID=0&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&VerSion=5.8.0.2&Token=0&" + response = __base_request("https://apphq.longhuvip.com/w1/api/index.php", data=data) + if response.status_code != 200: + raise Exception("璇锋眰鍑洪敊") + result = response.text + result = json.loads(result) + return result.get("ListJX") + + +# 鑾峰彇鑷敱娴侀�氬競鍊� +def getZYLTAmount(code): + data = f"a=GetStockPanKou_Narrow&apiv=w32&c=StockL2Data&VerSion=5.8.0.2&State=1&PhoneOSNew=1&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&StockID={code}&" + response = __base_request("https://apphq.longhuvip.com/w1/api/index.php", data=data) + if response.status_code != 200: + raise Exception("璇锋眰鍑洪敊") + result = response.text + result = json.loads(result) + if "real" in result: + return result["real"].get("actualcirculation_value") + return None + + +if __name__ == "__main__": + print(getZYLTAmount("000333")) -- Gitblit v1.8.0