123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import hug
- from bottle import route, run, NORUN
- from WindPy import w
- import json
- 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
- @hug.get('/hz_server')
- def hello():
- return 1
-
- @hug.get('/edbInfo/wind')
- def GetEdbDataByWind(EdbCode, StartDate, EndDate):
- print("GetEdbDataByWind:", EdbCode)
- isConnected = w.isconnected()
- print("isconnected")
- print(isConnected)
- if isConnected == False:
- print("re isconnected")
- w.start()
- isConnected = w.isconnected()
- if isConnected == False:
- return "{'ErrMsg':'启动Wind接口失败'}"
- print("getdata")
- option = "Fill=Previous"
-
- data = w.edb(EdbCode, StartDate, EndDate, option)
- print("wind data")
- print(data)
- df = pd.DataFrame()
- if data.ErrorCode != 0:
- os._exit(0)
- return "a"
- if data.ErrorCode != 0:
- os._exit(0)
- return "b"
- df['DT'] = data.Times
- df['CLOSE'] = data.Data[0]
- df['ErrorCode'] = data.ErrorCode
- df = df[['DT', 'CLOSE', 'ErrorCode']]
- df = df.dropna()
- json_data = df.to_json()
-
- print("wind data end")
- result = json.loads(json_data)
- return result
- @hug.get('/edbInfo/wind/wsd')
- def GetEdbDataWindWsd(StockCode, EdbCode, StartDate, EndDate):
- print("GetEdbDataByWind:", EdbCode)
- isConnected = w.isconnected()
- print("isconnected")
- print(isConnected)
- if isConnected == False:
- print("re isconnected")
- w.start()
- isConnected = w.isconnected()
- if isConnected == False:
- return "{'ErrMsg':'启动Wind接口失败'}"
- option = "Fill=Previous"
- wsd_data = w.wsd(StockCode, EdbCode, StartDate, EndDate, option)
- if wsd_data.ErrorCode != 0:
- os._exit(0)
- return "a"
- fm = pd.DataFrame(wsd_data.Data, index=wsd_data.Fields, columns=wsd_data.Times)
- json_data = fm.to_json()
- result = json.loads(json_data)
- return result
- if __name__ == "__main__":
-
- wStart = w.start(waitTime=60)
- print(wStart)
- if wStart.ErrorCode != 0:
- print("启动万得API接口失败")
- os._exit(0)
-
- app = __hug__.http.server()
- run(app=app, reloader=True, host='0.0.0.0', port=7000)
|