فهرست منبع

Merge branch 'master' of http://8.136.199.33:3000/eta_server/eta_python

317699326@qq.com 1 هفته پیش
والد
کامیت
5c1170b9da
8فایلهای تغییر یافته به همراه643 افزوده شده و 9 حذف شده
  1. 4 1
      .gitignore
  2. 187 0
      kpler/rpa_kpler_refresh.py
  3. 2 1
      pb_api.py
  4. 3 2
      pscg_bloomberg/main.py
  5. 169 0
      rpa_radish_research_refresh.py
  6. 247 0
      ths_wind.py
  7. 30 4
      wind_api.py
  8. 1 1
      yongyi_pig/yongyi_pig_manual.py

+ 4 - 1
.gitignore

@@ -1,2 +1,5 @@
 /.idea
-/venv
+/venv
+/html2img/html
+/html2img/img
+/html2img/.idea

+ 187 - 0
kpler/rpa_kpler_refresh.py

@@ -0,0 +1,187 @@
+import hug
+from bottle import route, run
+import pyautogui
+import random
+import time
+import os
+import win32gui
+import autoit
+import datetime
+
+hug.API(__name__).http.output_format = hug.output_format.json
+
+# exePath = r"C:\Program Files (x86)\Kingsoft\WPS Office\11.8.2.12085\office6\et"
+# exePath = exePath = r"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE"
+# exePath = exePath = r"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"
+exePath = r"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"
+
+# 顶部Kpler按钮的x,y位置
+kp_button_x = 920
+kp_button_y = 100
+
+# Kpler选项卡下面的table选择按钮的x,y位置
+kp_table_select_button_x = 760
+kp_table_select_button_y = 345
+
+# Kpler选项卡下面的flow选择按钮的x,y位置
+kp_flow_select_button_x = 760
+kp_flow_select_button_y = 435
+
+
+
+# Kpler选项卡下面的刷新按钮的x,y位置
+kp_refresh_button_x = 850
+kp_refresh_button_y = 300
+
+
+
+
+# 获取数据的超时时间(单位:s)
+get_data_timeout_time = 30
+
+# 随机点击的按钮范围
+pointMinX = 200
+pointMaxX = 650
+pointMinY = 300
+pointMaxY = 550
+
+@hug.get('/kpler/server')
+def kpler_server():
+    return 1
+
+@hug.get('/kpler/refresh')
+def kpler_refresh(FilePath):
+    screen_width, screen_height = pyautogui.size()
+    print("屏幕分辨率:{} x {}".format(screen_width, screen_height))
+
+    pyautogui.FAILSAFE = False
+    FilePath = FilePath.replace('"', '')
+
+    pyautogui.hotkey('win', 'd')
+    
+    try:
+        fileFullPath = FilePath
+        print("fileFullPath start")
+
+        fileFullPath = fileFullPath.replace("\\\\", "\\")
+
+        print(fileFullPath)
+
+        if os.path.exists(fileFullPath) and ".xlsx" in fileFullPath \
+                and fileFullPath.find("~$") < 0 \
+                and fileFullPath.find("template") < 0:
+
+            # 获取文件名和扩展名
+            file_name, file_ext = os.path.splitext(os.path.basename(fileFullPath))
+            file_name_ext = file_name + file_ext
+            print(file_name_ext)
+            print(datetime.datetime.now())
+
+            try:
+                # 启动程序
+                code = exePath + " " + fileFullPath
+                autoit.run(code)
+                autoit.win_wait_active(file_name_ext, timeout=20)  # 等待窗口激活
+                autoit.win_move(file_name_ext, 0, 0, 1024, 768)
+
+                print("监听成功了")
+
+            except Exception as e:
+                print("打开", fileFullPath, "失败:", e)
+
+                ## 失败的话,截图记录下原因
+                screenshot = pyautogui.screenshot()
+                imgPath = datetime.datetime.now().strftime("%Y%m%d%H%M%S")+"_screenshot_img.png"
+                screenshot.save(imgPath)
+
+                hwnd = win32gui.GetForegroundWindow()
+                found_title = win32gui.GetWindowText(hwnd)
+                print("窗口名称:", found_title)
+                if found_title == "":
+                    print("窗口未打开")
+                    return
+                if found_title.startswith(file_name_ext) == False:
+                    print("窗口与excel不一致,当前窗口:", found_title, ";excel:", file_name_ext)
+                    #return
+                autoit.win_move_by_handle(hwnd, 0, 0, 1024, 768)
+
+
+            ### 随机2-3次点击 单元格区域(每次点击停留1s)
+            r = random.randint(2, 3)
+            for i in range(r):
+                pointX = random.randint(pointMinX, pointMaxX)
+                pointY = random.randint(pointMinY, pointMaxY)
+                print("随机点击", i + 1, "下;", "点击X:", pointX, ";Y:", pointY)
+                pyautogui.moveTo(pointX, pointY, 0.5)
+                pyautogui.click()
+                time.sleep(1)
+
+            print("start dataBtn")
+            pyautogui.moveTo(kp_button_x, kp_button_y, 0.5)
+            pyautogui.click()
+            time.sleep(5)
+            print("end dataBtn")
+
+            pointX = random.randint(pointMinX, pointMaxX)
+            pointY = random.randint(pointMinY, pointMaxY)
+            pyautogui.moveTo(pointX, pointY)
+            pyautogui.click()
+            print("点击X:", pointX, ";Y:", pointY)
+
+            # 停留随机秒数
+            sleepSec = random.randint(1, 3)
+            time.sleep(sleepSec)
+
+            pointX = random.randint(pointMinX, pointMaxX)
+            pointY = random.randint(pointMinY, pointMaxY)
+            pyautogui.moveTo(pointX, pointY)
+            pyautogui.click()
+            print("点击X:", pointX, ";Y:", pointY)
+            # 停留随机秒数
+            sleepSec = random.randint(1, 3)
+            time.sleep(sleepSec)
+
+            print("start tableSelect")
+            pyautogui.moveTo(kp_table_select_button_x, kp_table_select_button_y, 1)
+            pyautogui.click()
+            time.sleep(1)
+            print("end tableSelect")
+
+            print("start flowSelect")
+            pyautogui.moveTo(kp_flow_select_button_x, kp_flow_select_button_y, 1)
+            pyautogui.click()
+            time.sleep(1)
+            print("end flowSelect")
+
+            print("start getCurrentPageData")
+            pyautogui.moveTo(kp_refresh_button_x, kp_refresh_button_y, 1)
+            pyautogui.click()
+            time.sleep(1)
+
+            print("end getCurrentPageData")
+
+            pointX = random.randint(pointMinX, pointMaxX)
+            pointY = random.randint(pointMinY, pointMaxY)
+            pyautogui.moveTo(pointX, pointY, 0.5)
+            pyautogui.click()
+            print("点击X:", pointX, ";Y:", pointY)
+            # 停留等待数据更新
+            time.sleep(get_data_timeout_time)
+
+            pyautogui.hotkey('ctrl', 's')
+            time.sleep(1)
+            pyautogui.hotkey('ctrl', 'w')
+
+            return True
+        else:
+            print("ext err:" + fileFullPath)
+        return True
+    except Exception as e:
+        print("Exception:")
+        print(str(e))
+        return False
+
+
+if __name__ == "__main__":
+    app = __hug__.http.server()
+    run(app=app, reloader=True, port=8007)  # 使用不同的端口号,避免和mysteel冲突

+ 2 - 1
pb_api.py

@@ -19,7 +19,8 @@ def GetEdbDataByPb(EdbCode, StartDate, EndDate):
     bbg.start()
     try:
         rst = bbg.bdh(EdbCode,
-                      ['PX_LAST', 'PE_RATIO', 'PX_TO_BOOK_RATIO', 'EQY_DVD_YLD_12M', 'TURNOVER', 'CUR_MKT_CAP'],
+                      # ['PX_LAST', 'PE_RATIO', 'PX_TO_BOOK_RATIO', 'EQY_DVD_YLD_12M', 'TURNOVER', 'CUR_MKT_CAP'],
+                      ['PX_LAST'],
                       StartDate, EndDate, longdata=True).to_json()
     except:
         rst = pd.DataFrame().to_json()

+ 3 - 2
pscg_bloomberg/main.py

@@ -74,7 +74,8 @@ task_key_dir_dict = {
     "IDpcsgDailyRunHist2": "data/hist2", "IDpcsgDailyRunHistV1": "data/histv1", "IDpcsgDailyRun4": "data/run4",
     "IDpcsgDailyRun6": "data/run6", "IDpcsgDailyRun7": "data/run7", "IDpcsgDailyRun8": "data/run8",
     "IDpcsgDailySnap0000": "data/snap0000", "IDpcsgDailySnap0330": "data/snap0330",
-    "IDpcsgDailySnap0345": "data/snap0345", "IDpcsgDailyRun10": "data/day10"
+    "IDpcsgDailySnap0345": "data/snap0345", "IDpcsgDailyRun10": "data/day10", "IDpcsgDailyRun11": "data/run11",
+    "IDpcsgDailyRunHistU3": "data/histu3", "IDpcsgDailyRun12": "data/run12", "IDpcsgMonthRun2": "data/month2"
 }
 
 
@@ -165,4 +166,4 @@ def write_data_to_file(json_data, dir_path=None):
 
 
 if __name__ == "__main__":
-    app.run(host='0.0.0.0', port=server_port, debug=True)
+    app.run(host='0.0.0.0', port=server_port, debug=True)

+ 169 - 0
rpa_radish_research_refresh.py

@@ -0,0 +1,169 @@
+import hug
+from bottle import run
+import pyautogui
+import random
+import time
+import os
+import win32gui
+import win32con
+import autoit
+import datetime
+
+# 配置参数
+CONFIG = {
+    "exe_path": r"C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE",
+    "no_auth_button": {"x": 1150, "y": 481},
+    "source_button": {"x": 495, "y": 37},
+    "refresh_icon_button": {"x": 583, "y": 112},
+    "refresh_all_button": {"x": 616, "y": 157},
+    "random_click_range": {"min_x": 450, "max_x": 650, "min_y": 450, "max_y": 650},
+    "get_data_timeout_time": 20,
+    "screen_resolution": {"width": 1920, "height": 1080},  # 默认分辨率
+}
+
+hug.API(__name__).http.output_format = hug.output_format.json
+
+
+def scale_coordinates(x, y):
+    """根据屏幕分辨率动态缩放坐标"""
+    screen_width, screen_height = pyautogui.size()
+    scale_x = screen_width / CONFIG["screen_resolution"]["width"]
+    scale_y = screen_height / CONFIG["screen_resolution"]["height"]
+    return int(x * scale_x), int(y * scale_y)
+
+
+def random_click(min_x, max_x, min_y, max_y, duration=0.5):
+    """随机点击指定范围内的坐标"""
+    point_x = random.randint(min_x, max_x)
+    point_y = random.randint(min_y, max_y)
+    pyautogui.moveTo(point_x, point_y, duration)
+    pyautogui.click()
+    print(f"随机点击:X={point_x}, Y={point_y}")
+    return point_x, point_y
+
+
+def open_excel_file(file_path):
+    """使用 Excel 打开文件,并动态等待窗口激活"""
+    try:
+        file_name_ext = os.path.basename(file_path)
+        print(f"尝试打开文件:{file_name_ext}")
+
+        # 启动 Excel 并打开文件
+        autoit.run(f'{CONFIG["exe_path"]} "{file_path}"')
+
+        time.sleep(15)
+
+        # 动态等待窗口激活,最多等待 20 秒
+        # if not autoit.win_wait_active(file_name_ext, timeout=20):
+        #     print(f"窗口激活超时:{file_name_ext}")
+        #     return False
+
+        # 最大化窗口
+        hwnd = win32gui.GetForegroundWindow()
+        win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
+        time.sleep(1)  # 短暂等待窗口最大化完成
+
+        print(f"成功打开并最大化窗口:{file_name_ext}")
+    except Exception as e:
+        print(f"打开文件失败:{e}")
+        return False
+    return True
+
+
+@hug.get('/radish_research/server')
+def radish_research_server():
+    return 1
+
+
+@hug.get('/radish_research/refresh')
+def radish_research_refresh(FilePath):
+    pyautogui.FAILSAFE = False
+    FilePath = FilePath.replace('"', '')
+
+    # 检查文件路径
+    if not os.path.exists(FilePath) or ".xlsx" not in FilePath \
+            or "~$" in FilePath or "template" in FilePath:
+        print(f"文件无效:{FilePath}")
+        return False
+
+    # 按钮坐标
+    no_auth_button = CONFIG["no_auth_button"]["x"], CONFIG["no_auth_button"]["y"]
+    source_button = CONFIG["source_button"]["x"], CONFIG["source_button"]["y"]
+    refresh_icon_button = CONFIG["refresh_icon_button"]["x"], CONFIG["refresh_icon_button"]["y"]
+    refresh_all_button = CONFIG["refresh_all_button"]["x"], CONFIG["refresh_all_button"]["y"]
+
+    # 打开桌面并点击空白区域
+    pyautogui.hotkey('win', 'd')
+    move_x, move_y = scale_coordinates(1100, 600)
+    pyautogui.moveTo(move_x, move_y, 0.5)
+    pyautogui.click(move_x, move_y)
+
+    try:
+        # 打开文件
+        if not open_excel_file(FilePath):
+            return False
+
+        # 随机点击单元格区域
+        for _ in range(random.randint(2, 3)):
+            random_click(
+                CONFIG["random_click_range"]["min_x"],
+                CONFIG["random_click_range"]["max_x"],
+                CONFIG["random_click_range"]["min_y"],
+                CONFIG["random_click_range"]["max_y"]
+            )
+            time.sleep(1)
+
+        # 处理无权限弹框
+        print("开始点击无权限按钮")
+        pyautogui.moveTo(*no_auth_button, 0.5)
+        pyautogui.click()
+        time.sleep(2)
+        print("结束点击无权限按钮")
+
+        # 点击顶部萝卜投研按钮
+        print("开始点击数据按钮")
+        pyautogui.moveTo(*source_button, 0.5)
+        pyautogui.click()
+        time.sleep(2)
+        print("结束点击数据按钮")
+
+        # 点击刷新小箭头
+        print("开始点击刷新小箭头")
+        pyautogui.moveTo(*refresh_icon_button, 1)
+        pyautogui.click()
+        time.sleep(1)
+        print("结束点击刷新小箭头")
+
+        # 点击刷新所有页
+        print("开始点击刷新所有页")
+        pyautogui.moveTo(*refresh_all_button, 1)
+        pyautogui.click()
+        time.sleep(1)
+        print("结束点击刷新所有页")
+
+        # 随机点击
+        random_click(
+            CONFIG["random_click_range"]["min_x"],
+            CONFIG["random_click_range"]["max_x"],
+            CONFIG["random_click_range"]["min_y"],
+            CONFIG["random_click_range"]["max_y"]
+        )
+
+        # 等待数据更新
+        time.sleep(CONFIG["get_data_timeout_time"])
+
+        # 保存并关闭文件
+        pyautogui.hotkey('ctrl', 's')
+        time.sleep(1)
+        pyautogui.hotkey('ctrl', 'w')
+
+        return True
+
+    except Exception as e:
+        print(f"发生异常:{e}")
+        return False
+
+
+if __name__ == "__main__":
+    app = __hug__.http.server()
+    run(app=app, reloader=True, port=7007)

+ 247 - 0
ths_wind.py

@@ -0,0 +1,247 @@
+import hug
+from bottle import route, run, NORUN
+from WindPy import w
+import iFinDPy as THS
+import json
+import pandas as pd
+import time
+import os
+import logging
+import sys
+
+hug.API(__name__).http.output_format = hug.output_format.json
+
+username = ""
+password = ""
+
+
+@hug.get('/hz_server')
+def hello():
+    return 1
+    # return 'wind true'
+
+
+# 同花顺登录函数
+def thslogin():
+    # 输入用户的帐号和密码
+    thsLogin = THS.THS_iFinDLogin(username, password)
+    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")
+    print("thsEDBDataQuery")
+    print(thsEDBDataQuery)
+    thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")
+
+    result = json.loads(thsEDBDataQuery)
+    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":end GetEdbDataByThs")
+
+    if result["errorcode"] == -1010:
+        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("已登录")
+
+    return result
+
+
+def has_comma(input_string):
+    return isinstance(input_string, str) and ',' in input_string
+
+
+def process_single_edb_code(StockCode, SingleEdbCode, StartDate, EndDate):
+    thsEDBDataQuery = THS.THS_DS(StockCode, SingleEdbCode, '', '', StartDate, EndDate)
+    print(thsEDBDataQuery)
+    result = json.dumps(ths_data_to_dict(thsEDBDataQuery))
+    return result
+
+
+@hug.get('/edbInfo/ths/ds')
+def GetEdbDataByThsDs(StockCode, EdbCode, StartDate, EndDate):
+    print("THS_DataSequence start")
+    print(EdbCode)
+    result_list = []
+
+    if isinstance(EdbCode, list):
+        for SingleEdbCode in EdbCode:
+            result_list.append(process_single_edb_code(StockCode, SingleEdbCode, StartDate, EndDate))
+            print("THS_DS end")
+        print(result_list)
+        return result_list
+    else:
+        # 如果不包含逗号,直接处理
+        result = process_single_edb_code(StockCode, EdbCode, StartDate, EndDate)
+        print(result)
+        return result
+
+
+@hug.get('/edbInfo/ths/future_good')
+def GetFutureGoodEdbDataByThs(EdbCode, StartDate, EndDate):
+    print("THS_HistoryQuotes start")
+    thsLogin = THS.THS_iFinDLogin("hzmd150", "689719")
+
+    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'
+    # params = 'YSHB;Tradedays'
+    # print(params)
+    thsEDBDataQuery = THS.THS_HistoryQuotes(EdbCode, filed, params, StartDate, EndDate, True)
+    # thsEDBDataQuery = THS.THS_HQ(EdbCode, filed, params, StartDate, EndDate)
+    # thsEDBDataQuery = THS.THS_EDBQuery(EdbCode, StartDate, EndDate, True)
+    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":start GetFutureGoodEdbDataByThs")
+    print("THS_HistoryQuotes end")
+    print(thsEDBDataQuery)
+    thsEDBDataQuery = thsEDBDataQuery.decode("unicode_escape")
+    result = json.loads(thsEDBDataQuery)
+    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ":end GetFutureGoodEdbDataByThs")
+    return result
+
+
+@hug.get('/edbInfo/ths/hf')
+def GetEdbDataByThsDs(codes, indicators, function_para, start_time, end_time):
+    print("codes: {}; indicators: {}; function_para: {}; start_time: {}; end_time: {}".format(codes, indicators,
+                                                                                              function_para, start_time,
+                                                                                              end_time))
+    data_query = THS.THS_DF(codes, indicators, function_para, start_time, end_time)
+    print(data_query)
+    result = json.dumps(ths_data_to_dict(data_query))
+    return result
+
+
+@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")
+    df = pd.DataFrame()
+    if data.ErrorCode == -40521010:  # Internet Timeout 超时退出
+        os._exit(0)
+        return "a"
+    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()
+    # w.stop()
+    print("wind data end")
+    result = json.loads(json_data)
+    return result
+
+
+@hug.get('/edbInfo/wind/future_good')
+def GetFutureGoodEdbDataByWind(FutureGoodEdbCode, StartDate, EndDate):
+    print("GetFutureGoodEdbDataByWind:", FutureGoodEdbCode)
+    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(FutureGoodEdbCode, StartDate, EndDate, option)
+    data = w.wsd(FutureGoodEdbCode, "trade_code,open,high,low,close,volume,amt,oi,settle", StartDate, EndDate, option)
+    print("wind data")
+    print(data)
+    df = pd.DataFrame()
+
+    if data.ErrorCode == -40521010:  # Internet Timeout 超时退出
+        os._exit(0)
+        return "a"
+
+    df['DT'] = data.Times
+    df['TRADE_CODE'] = data.Data[0]
+    df['OPEN'] = data.Data[1]
+    df['HIGH'] = data.Data[2]
+    df['LOW'] = data.Data[3]
+    df['CLOSE'] = data.Data[4]
+    df['VOLUME'] = data.Data[5]
+    df['AMT'] = data.Data[6]
+    df['OI'] = data.Data[7]
+    df['SETTLE'] = data.Data[8]
+    df['ErrorCode'] = data.ErrorCode
+    df = df[['DT', 'TRADE_CODE', 'OPEN', 'HIGH', 'LOW', 'CLOSE', 'VOLUME', 'AMT', 'OI', 'SETTLE', 'ErrorCode']]
+    df = df.dropna()
+    json_data = df.to_json()
+    # w.stop()
+    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 == -40521010:  # Internet Timeout 超时退出
+        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__":
+    # wind 登录
+    wStart = w.start()
+    if wStart.ErrorCode != 0:
+        print("启动万得API接口失败")
+    print(wStart)
+
+    # ths登录函数
+    thslogin()
+
+    app = __hug__.http.server()
+    run(app=app, reloader=True, port=7000)

+ 30 - 4
wind_api.py

@@ -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,13 +33,17 @@ 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 != 0:  # corrupted response. 错误响应也重启
+        os._exit(0)
+        return "b"
     df['DT'] = data.Times
     df['CLOSE'] = data.Data[0]
     df['ErrorCode'] = data.ErrorCode
@@ -66,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"
 
@@ -75,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)

+ 1 - 1
yongyi_pig/yongyi_pig_manual.py

@@ -140,7 +140,7 @@ def yongyi_download(dayFlag, weekFlag):
             if file.title().find("涌益咨询日度数据") != -1:
                 if day_file == "":
                     day_file = file
-            if file.title().find("涌益咨询周度数据") != -1:
+            if file.title().find("周度数据") != -1:
                 if week_file == "":
                     week_file = file
             if day_file != "" and week_file != "":