1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import eikon as ek
- import hug
- from bottle import route, run
- import json
- import pandas as pd
- import urllib.parse
- hug.API(__name__).http.output_format = hug.output_format.json
- # 填写路透的key
- key = ""
- @hug.get('/hz_server')
- def hello():
- ek_port = ek.get_port_number()
- if ek_port is None:
- # 如果检测不到路透终端的端口,那么就返回检测失败(可能电脑重启了)
- return "ek false"
- return 'ek true'
- @hug.get('/edbInfo/ek')
- def GetEdbDataFromEk(EdbCode, StartDate, EndDate ,Frequency="daily"):
- EdbCode = urllib.parse.unquote(EdbCode)
- # print("EdbCode:", EdbCode, ";StartDate:", StartDate, ";EndDate:", EndDate, ";Frequency:", Frequency)
- # print("req start")
- if Frequency == "":
- Frequency = "daily"
- data = ek.get_timeseries(EdbCode, fields='*', start_date=StartDate, end_date=EndDate, interval=Frequency)
- # print("result start\n", data)
- if data is None:
- print("数据查询失败:", data)
- return False
- # print("是否唯一索引:", data.index.is_unique)
- if data.index.is_unique is False:
- # print("开始去重")
- data = data.groupby(data.index).first()
- # print("结束去重")
- # print(data)
-
- # print("result end")
- data_json = data.to_json()
- result = json.loads(data_json)
- return result
- if __name__ == "__main__":
- ek.set_app_key(key)
- ek.set_timeout(120)
- app = __hug__.http.server()
- run(app=app, reloader=True, host='0.0.0.0', port=7002)
|