|
@@ -6,6 +6,8 @@ import pandas as pd
|
|
|
import time
|
|
|
import os
|
|
|
import sys
|
|
|
+from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
+import time
|
|
|
|
|
|
hug.API(__name__).http.output_format = hug.output_format.json
|
|
|
|
|
@@ -31,14 +33,15 @@ def GetEdbDataByWind(EdbCode, StartDate, EndDate):
|
|
|
|
|
|
print("getdata")
|
|
|
option = "Fill=Previous"
|
|
|
+
|
|
|
data = w.edb(EdbCode, StartDate, EndDate, option)
|
|
|
print("wind data")
|
|
|
print(data)
|
|
|
df = pd.DataFrame()
|
|
|
- if data.ErrorCode == -40521010: # Internet Timeout 超时退出
|
|
|
+ if data.ErrorCode != 0: # Internet Timeout 超时退出
|
|
|
os._exit(0)
|
|
|
return "a"
|
|
|
- if data.ErrorCode == -40521009: # corrupted response. 错误响应也重启
|
|
|
+ if data.ErrorCode != 0: # corrupted response. 错误响应也重启
|
|
|
os._exit(0)
|
|
|
return "b"
|
|
|
df['DT'] = data.Times
|
|
@@ -69,7 +72,7 @@ def GetEdbDataWindWsd(StockCode, EdbCode, StartDate, EndDate):
|
|
|
option = "Fill=Previous"
|
|
|
wsd_data = w.wsd(StockCode, EdbCode, StartDate, EndDate, option)
|
|
|
|
|
|
- if wsd_data.ErrorCode == -40521010: # Internet Timeout 超时退出
|
|
|
+ if wsd_data.ErrorCode != 0: # Internet Timeout 超时退出
|
|
|
os._exit(0)
|
|
|
return "a"
|
|
|
|
|
@@ -78,12 +81,32 @@ def GetEdbDataWindWsd(StockCode, EdbCode, StartDate, EndDate):
|
|
|
result = json.loads(json_data)
|
|
|
return result
|
|
|
|
|
|
+# def check_wind_status():
|
|
|
+# print("check wind login status")
|
|
|
+# # wind 登录
|
|
|
+# wStart = w.start()
|
|
|
+# print(wStart.ErrorCode)
|
|
|
+# if wStart.ErrorCode != 0:
|
|
|
+# print("启动万得API接口失败")
|
|
|
+# os._exit(0)
|
|
|
+
|
|
|
+# scheduler = BackgroundScheduler()
|
|
|
+# scheduler.add_job(check_wind_status, 'interval', seconds=1) # 每60秒执行一次任务
|
|
|
+# scheduler.start()
|
|
|
+
|
|
|
+# try:
|
|
|
+# while True:
|
|
|
+# time.sleep(2)
|
|
|
+# except (KeyboardInterrupt, SystemExit):
|
|
|
+# scheduler.shutdown()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
# wind 登录
|
|
|
- wStart = w.start()
|
|
|
+ wStart = w.start(waitTime=60)
|
|
|
+ print(wStart)
|
|
|
if wStart.ErrorCode != 0:
|
|
|
print("启动万得API接口失败")
|
|
|
- print(wStart)
|
|
|
+ os._exit(0)
|
|
|
+
|
|
|
app = __hug__.http.server()
|
|
|
run(app=app, reloader=True, host='0.0.0.0', port=7000)
|