Browse Source

新增同花顺日志

hongze 9 months ago
parent
commit
8ccbb5fa4a
1 changed files with 21 additions and 0 deletions
  1. 21 0
      ths_api.py

+ 21 - 0
ths_api.py

@@ -3,12 +3,24 @@ from bottle import route, run,NORUN
 import iFinDPy as THS
 import json
 import time
+import logging
+
+logger = logging.getLogger('ths_api')
+logger.setLevel(logging.DEBUG)  # 设置日志级别
 
 hug.API(__name__).http.output_format = hug.output_format.json
 
 username = ""
 password = ""
 
+file_handler = logging.FileHandler('ths_api.log')
+file_handler.setLevel(logging.DEBUG)
+
+formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+file_handler.setFormatter(formatter)
+
+logger.addHandler(file_handler)
+
 @hug.get('/hz_server')
 def hello():
     return 1
@@ -21,15 +33,19 @@ def thslogin():
     print(thsLogin)
     if (thsLogin == 0 or thsLogin == -201):
         print('ths 登录成功')
+        logger.info('ths login success')
     else:
         print('ths 登录失败')
+        logger.info('ths login fail')
 
 
 @hug.get('/edbInfo/ths')
 def GetEdbDataByThs(EdbCode, StartDate, EndDate):
     print("GetEdbDataByThs")
+    logger.info('GetEdbDataByThs')
     thsEDBDataQuery = THS.THS_EDBQuery(EdbCode, StartDate, EndDate, True)
     print(thsEDBDataQuery)
+    logger.info(thsEDBDataQuery)
     
 
     print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":start GetEdbDataByThs")
@@ -44,10 +60,12 @@ def GetEdbDataByThs(EdbCode, StartDate, EndDate):
         thsLogin = THS.THS_iFinDLogin(username, password)
         print("登录一次")
         print(thsLogin)
+        logger.info("ths login")
         if (thsLogin == 0 or thsLogin == -201):
            thsEDBDataQuery = THS.THS_EDBQuery(EdbCode, StartDate, EndDate, True)
            thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")
            result = json.loads(thsEDBDataQuery)
+           logger.info("login success")
     else:
         print("已登录")
         
@@ -56,6 +74,7 @@ def GetEdbDataByThs(EdbCode, StartDate, EndDate):
 @hug.get('/edbInfo/ths/future_good')
 def GetFutureGoodEdbDataByThs(EdbCode, StartDate, EndDate):
     print("THS_HistoryQuotes start")
+    logger.info('THS_HistoryQuotes get')
     filed = 'lastclose,open,high,low,close,avgprice,change,changeper,volume,amount,hsl,lastsettlement,settlement,zdsettlement,zdfsettlement,ccl,ccbd,zf,zjlx,zjcd'
     # filed = 'open,high,low,close,volume,amount,settlement,ccl,zjlx'
     params = 'Interval:D,CPS:1,baseDate:1900-01-01,Currency:YSHB,fill:Previous'
@@ -67,12 +86,14 @@ def GetFutureGoodEdbDataByThs(EdbCode, StartDate, EndDate):
     print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":start GetFutureGoodEdbDataByThs")
     print("THS_HistoryQuotes end")
     print(thsEDBDataQuery)
+    logger.info(thsEDBDataQuery)
     thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")
     result = json.loads(thsEDBDataQuery)
     if result["errorcode"]==-1010:
         thsLogin = THS.THS_iFinDLogin(username, password)
         print("登录一次")
         print(thsLogin)
+        logger.info('THS_HistoryQuotes login')
         if (thsLogin == 0 or thsLogin == -201):
            thsEDBDataQuery = THS.THS_HistoryQuotes(EdbCode, filed, params, StartDate, EndDate, True)
            thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")