lt_api.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import eikon as ek
  2. import hug
  3. from bottle import route, run
  4. import json
  5. import pandas as pd
  6. import urllib.parse
  7. hug.API(__name__).http.output_format = hug.output_format.json
  8. # 填写路透的key
  9. key = ""
  10. @hug.get('/hz_server')
  11. def hello():
  12. return 'ek true'
  13. @hug.get('/edbInfo/ek')
  14. def GetEdbDataFromEk(EdbCode, StartDate, EndDate):
  15. EdbCode = urllib.parse.unquote(EdbCode)
  16. print("EdbCode")
  17. print(EdbCode)
  18. print(StartDate)
  19. print(EndDate)
  20. print("req start")
  21. data = ek.get_timeseries(EdbCode, fields='*', start_date=StartDate, end_date=EndDate)
  22. print("result start")
  23. print(data)
  24. print("是否唯一索引:", data.index.is_unique)
  25. if data.index.is_unique ==False:
  26. print("开始去重")
  27. data = data.groupby(data.index).first()
  28. print("结束去重")
  29. print(data)
  30. print("result end")
  31. dataJson = data.to_json()
  32. result = json.loads(dataJson)
  33. return result
  34. if __name__ == "__main__":
  35. ek.set_app_key(key)
  36. app = __hug__.http.server()
  37. run(app=app, reloader=True, port=7002)