xinxin
This commit is contained in:
parent
7a67ea345d
commit
61ca5e1fd7
@ -41,6 +41,8 @@ class DongWuClientTrader:
|
|||||||
self.account_name = account_name
|
self.account_name = account_name
|
||||||
self.log = Logger(f'{root_path}/logs',self.account_name)
|
self.log = Logger(f'{root_path}/logs',self.account_name)
|
||||||
|
|
||||||
|
# 加载WiFi配置文件
|
||||||
|
self.wifi_configs = self._load_wifi_config()
|
||||||
|
|
||||||
reset_proxy_to_default()
|
reset_proxy_to_default()
|
||||||
self.log.info('初始化代理IP成功')
|
self.log.info('初始化代理IP成功')
|
||||||
@ -51,6 +53,28 @@ class DongWuClientTrader:
|
|||||||
self.securities_name = str(df_count['securities_username'].tolist()[0])
|
self.securities_name = str(df_count['securities_username'].tolist()[0])
|
||||||
self.securities_password = str(df_count['securities_password'].tolist()[0])
|
self.securities_password = str(df_count['securities_password'].tolist()[0])
|
||||||
self.communication_password = str(df_count['communication_password'].tolist()[0])
|
self.communication_password = str(df_count['communication_password'].tolist()[0])
|
||||||
|
|
||||||
|
def _load_wifi_config(self):
|
||||||
|
"""加载WiFi配置文件"""
|
||||||
|
config_path = os.path.join(root_path, 'wifi_config.txt')
|
||||||
|
try:
|
||||||
|
with open(config_path, 'r', encoding='utf-8') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
wifi_configs = []
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
if line and not line.startswith('#'):
|
||||||
|
parts = line.split(',')
|
||||||
|
if len(parts) == 2:
|
||||||
|
wifi_configs.append({'ssid': parts[0].strip(), 'password': parts[1].strip()})
|
||||||
|
self.log.info(f"WiFi配置加载成功,共{len(wifi_configs)}个配置")
|
||||||
|
return wifi_configs
|
||||||
|
except FileNotFoundError:
|
||||||
|
self.log.warn(f"WiFi配置文件 {config_path} 不存在,使用默认配置")
|
||||||
|
return [{'ssid': 'ZTE_A5DA76', 'password': '1234567890'}]
|
||||||
|
except Exception as e:
|
||||||
|
self.log.error(f"WiFi配置文件读取错误: {e}")
|
||||||
|
return [{'ssid': 'ZTE_A5DA76', 'password': '1234567890'}]
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
'''
|
'''
|
||||||
@ -94,10 +118,24 @@ class DongWuClientTrader:
|
|||||||
# 重置mac
|
# 重置mac
|
||||||
set_mac = SetMac()
|
set_mac = SetMac()
|
||||||
set_mac.run()
|
set_mac.run()
|
||||||
if not connect_wifi('ZTE_A5DA76','1234567890'): # 'Redmi K40','123456789'
|
# 尝试连接WiFi
|
||||||
|
connected = False
|
||||||
|
for i, wifi_config in enumerate(self.wifi_configs):
|
||||||
|
wifi_ssid = wifi_config['ssid']
|
||||||
|
wifi_password = wifi_config['password']
|
||||||
|
|
||||||
|
if i == 0:
|
||||||
|
self.log.info(f"尝试连接主WiFi: {wifi_ssid}")
|
||||||
|
else:
|
||||||
|
self.log.info(f"尝试连接备用WiFi: {wifi_ssid}")
|
||||||
|
|
||||||
|
if connect_wifi(wifi_ssid, wifi_password):
|
||||||
|
self.log.info(f"网络已就绪(WiFi: {wifi_ssid})")
|
||||||
|
connected = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not connected:
|
||||||
self.log.error("无法建立网络连接,请检查配置")
|
self.log.error("无法建立网络连接,请检查配置")
|
||||||
else:
|
|
||||||
self.log.info("网络已就绪")
|
|
||||||
|
|
||||||
get_ip_times = 0
|
get_ip_times = 0
|
||||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||||
|
@ -15,13 +15,14 @@ import io as mio
|
|||||||
import pytesseract
|
import pytesseract
|
||||||
import warnings
|
import warnings
|
||||||
import datetime
|
import datetime
|
||||||
|
import os
|
||||||
from tools import *
|
from tools import *
|
||||||
warnings.filterwarnings('ignore')
|
warnings.filterwarnings('ignore')
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
root_path = Path(__file__).parent.parent
|
root_path = Path(__file__).parent.parent
|
||||||
|
|
||||||
path = os.path.join(root_path,'broker_xiadan','华龙证券','Tc.exe')
|
path = os.path.join(root_path,'broker_xiadan','hualong','Tc.exe')
|
||||||
|
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
'mysql+pymysql://cn_ainvest_db:cn_ainvest_sd3a1@rm-2zewagytttzk6f24xno.mysql.rds.aliyuncs.com:3306/',
|
'mysql+pymysql://cn_ainvest_db:cn_ainvest_sd3a1@rm-2zewagytttzk6f24xno.mysql.rds.aliyuncs.com:3306/',
|
||||||
@ -35,12 +36,38 @@ class HLClientTrader:
|
|||||||
self.path = exe_path
|
self.path = exe_path
|
||||||
self.account_name = account_name
|
self.account_name = account_name
|
||||||
self.log = Logger(f'{root_path}/logs',self.account_name)
|
self.log = Logger(f'{root_path}/logs',self.account_name)
|
||||||
|
|
||||||
|
# 加载WiFi配置文件
|
||||||
|
self.wifi_configs = self._load_wifi_config()
|
||||||
|
|
||||||
# 用户券商信息
|
# 用户券商信息
|
||||||
sql = f"select * from ainvest_usercount where username='{account_name}'"
|
sql = f"select * from ainvest_usercount where username='{account_name}'"
|
||||||
df_count = download_data_from_db(sql, 'ai_strategy_update_iddb')
|
df_count = download_data_from_db(sql, 'ai_strategy_update_iddb')
|
||||||
self.securities_name = str(df_count['securities_username'].tolist()[0])
|
self.securities_name = str(df_count['securities_username'].tolist()[0])
|
||||||
self.securities_password = str(df_count['securities_password'].tolist()[0])
|
self.securities_password = str(df_count['securities_password'].tolist()[0])
|
||||||
self.communication_password = str(df_count['communication_password'].tolist()[0])
|
self.communication_password = str(df_count['communication_password'].tolist()[0])
|
||||||
|
|
||||||
|
def _load_wifi_config(self):
|
||||||
|
"""加载WiFi配置文件"""
|
||||||
|
config_path = os.path.join(root_path, 'wifi_config.txt')
|
||||||
|
try:
|
||||||
|
with open(config_path, 'r', encoding='utf-8') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
wifi_configs = []
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
if line and not line.startswith('#'):
|
||||||
|
parts = line.split(',')
|
||||||
|
if len(parts) == 2:
|
||||||
|
wifi_configs.append({'ssid': parts[0].strip(), 'password': parts[1].strip()})
|
||||||
|
self.log.info(f"WiFi配置加载成功,共{len(wifi_configs)}个配置")
|
||||||
|
return wifi_configs
|
||||||
|
except FileNotFoundError:
|
||||||
|
self.log.warn(f"WiFi配置文件 {config_path} 不存在,使用默认配置")
|
||||||
|
return [{'ssid': 'ZTE_A5DA76', 'password': '1234567890'}]
|
||||||
|
except Exception as e:
|
||||||
|
self.log.error(f"WiFi配置文件读取错误: {e}")
|
||||||
|
return [{'ssid': 'ZTE_A5DA76', 'password': '1234567890'}]
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
'''
|
'''
|
||||||
@ -90,10 +117,24 @@ class HLClientTrader:
|
|||||||
# 重置mac
|
# 重置mac
|
||||||
set_mac = SetMac()
|
set_mac = SetMac()
|
||||||
set_mac.run()
|
set_mac.run()
|
||||||
if not connect_wifi('ZTE_A5DA76', '1234567890'): # 'Redmi K40','123456789'
|
# 尝试连接WiFi
|
||||||
|
connected = False
|
||||||
|
for i, wifi_config in enumerate(self.wifi_configs):
|
||||||
|
wifi_ssid = wifi_config['ssid']
|
||||||
|
wifi_password = wifi_config['password']
|
||||||
|
|
||||||
|
if i == 0:
|
||||||
|
self.log.info(f"尝试连接主WiFi: {wifi_ssid}")
|
||||||
|
else:
|
||||||
|
self.log.info(f"尝试连接备用WiFi: {wifi_ssid}")
|
||||||
|
|
||||||
|
if connect_wifi(wifi_ssid, wifi_password):
|
||||||
|
self.log.info(f"网络已就绪(WiFi: {wifi_ssid})")
|
||||||
|
connected = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not connected:
|
||||||
self.log.error("无法建立网络连接,请检查配置")
|
self.log.error("无法建立网络连接,请检查配置")
|
||||||
else:
|
|
||||||
self.log.info("网络已就绪")
|
|
||||||
|
|
||||||
get_ip_times = 0
|
get_ip_times = 0
|
||||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||||
|
@ -19,6 +19,11 @@ from email.mime.application import MIMEApplication
|
|||||||
# from voice_notification import call_user
|
# from voice_notification import call_user
|
||||||
import uuid
|
import uuid
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# 获取根路径
|
||||||
|
root_path = Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
def setup_logging():
|
def setup_logging():
|
||||||
@ -64,6 +69,50 @@ class auto_trade:
|
|||||||
self.op = op
|
self.op = op
|
||||||
self.users = users
|
self.users = users
|
||||||
self.order_id = order_id
|
self.order_id = order_id
|
||||||
|
# 加载WiFi配置文件
|
||||||
|
self.wifi_configs = self._load_wifi_config()
|
||||||
|
|
||||||
|
def _load_wifi_config(self):
|
||||||
|
"""加载WiFi配置文件"""
|
||||||
|
config_path = os.path.join(root_path, 'wifi_config.txt')
|
||||||
|
try:
|
||||||
|
with open(config_path, 'r', encoding='utf-8') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
wifi_configs = []
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
if line and not line.startswith('#'):
|
||||||
|
parts = line.split(',')
|
||||||
|
if len(parts) == 2:
|
||||||
|
wifi_configs.append({'ssid': parts[0].strip(), 'password': parts[1].strip()})
|
||||||
|
logger.info(f"WiFi配置加载成功,共{len(wifi_configs)}个配置")
|
||||||
|
return wifi_configs
|
||||||
|
except FileNotFoundError:
|
||||||
|
logger.warning(f"WiFi配置文件 {config_path} 不存在,使用默认配置")
|
||||||
|
return [{'ssid': 'ZTE_A5DA76', 'password': '1234567890'}]
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"WiFi配置文件读取错误: {e}")
|
||||||
|
return [{'ssid': 'ZTE_A5DA76', 'password': '1234567890'}]
|
||||||
|
|
||||||
|
def _connect_wifi(self):
|
||||||
|
"""尝试连接WiFi"""
|
||||||
|
connected = False
|
||||||
|
for i, wifi_config in enumerate(self.wifi_configs):
|
||||||
|
wifi_ssid = wifi_config['ssid']
|
||||||
|
wifi_password = wifi_config['password']
|
||||||
|
|
||||||
|
if i == 0:
|
||||||
|
logger.info(f"尝试连接主WiFi: {wifi_ssid}")
|
||||||
|
else:
|
||||||
|
logger.info(f"尝试连接备用WiFi: {wifi_ssid}")
|
||||||
|
|
||||||
|
if connect_wifi(wifi_ssid, wifi_password):
|
||||||
|
logger.info(f"网络已就绪(WiFi: {wifi_ssid})")
|
||||||
|
connected = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not connected:
|
||||||
|
logger.error("无法建立网络连接,请检查配置")
|
||||||
|
|
||||||
def trade_main(self,user):
|
def trade_main(self,user):
|
||||||
user_main = trade_logic.Trade(user, self.op,self.order_id)
|
user_main = trade_logic.Trade(user, self.op,self.order_id)
|
||||||
@ -77,10 +126,7 @@ class auto_trade:
|
|||||||
try:
|
try:
|
||||||
self.trade_main(user)
|
self.trade_main(user)
|
||||||
reset_proxy_to_default()
|
reset_proxy_to_default()
|
||||||
if not connect_wifi('ZTE_A5DA76','1234567890'):
|
self._connect_wifi()
|
||||||
logger.info("无法建立网络连接,请检查配置")
|
|
||||||
else:
|
|
||||||
logger.info("网络已就绪")
|
|
||||||
writer = ExcelDataWriter()
|
writer = ExcelDataWriter()
|
||||||
writer.update_latest_record(
|
writer.update_latest_record(
|
||||||
status='成功',
|
status='成功',
|
||||||
@ -91,10 +137,7 @@ class auto_trade:
|
|||||||
|
|
||||||
except Exception as er:
|
except Exception as er:
|
||||||
reset_proxy_to_default()
|
reset_proxy_to_default()
|
||||||
if not connect_wifi('ZTE_A5DA76','1234567890'): # "4G-UFI-18C8", "1234567890" 'Redmi K40','123456789'
|
self._connect_wifi()
|
||||||
logger.info("无法建立网络连接,请检查配置")
|
|
||||||
else:
|
|
||||||
logger.info("网络已就绪")
|
|
||||||
ip_address = get_host_ip()
|
ip_address = get_host_ip()
|
||||||
try:
|
try:
|
||||||
send_email('auto trade error',(ip_address+' '+user))
|
send_email('auto trade error',(ip_address+' '+user))
|
||||||
@ -138,6 +181,49 @@ class auto_trade:
|
|||||||
# return ip
|
# return ip
|
||||||
|
|
||||||
|
|
||||||
|
def load_wifi_config():
|
||||||
|
"""加载WiFi配置文件"""
|
||||||
|
config_path = os.path.join(root_path, 'wifi_config.txt')
|
||||||
|
try:
|
||||||
|
with open(config_path, 'r', encoding='utf-8') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
wifi_configs = []
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
if line and not line.startswith('#'):
|
||||||
|
parts = line.split(',')
|
||||||
|
if len(parts) == 2:
|
||||||
|
wifi_configs.append({'ssid': parts[0].strip(), 'password': parts[1].strip()})
|
||||||
|
logger.info(f"WiFi配置加载成功,共{len(wifi_configs)}个配置")
|
||||||
|
return wifi_configs
|
||||||
|
except FileNotFoundError:
|
||||||
|
logger.warning(f"WiFi配置文件 {config_path} 不存在,使用默认配置")
|
||||||
|
return [{'ssid': 'ZTE_A5DA76', 'password': '1234567890'}]
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"WiFi配置文件读取错误: {e}")
|
||||||
|
return [{'ssid': 'ZTE_A5DA76', 'password': '1234567890'}]
|
||||||
|
|
||||||
|
def connect_wifi_from_config():
|
||||||
|
"""从配置文件连接WiFi"""
|
||||||
|
wifi_configs = load_wifi_config()
|
||||||
|
connected = False
|
||||||
|
for i, wifi_config in enumerate(wifi_configs):
|
||||||
|
wifi_ssid = wifi_config['ssid']
|
||||||
|
wifi_password = wifi_config['password']
|
||||||
|
|
||||||
|
if i == 0:
|
||||||
|
logger.info(f"尝试连接主WiFi: {wifi_ssid}")
|
||||||
|
else:
|
||||||
|
logger.info(f"尝试连接备用WiFi: {wifi_ssid}")
|
||||||
|
|
||||||
|
if connect_wifi(wifi_ssid, wifi_password):
|
||||||
|
logger.info(f"网络已就绪(WiFi: {wifi_ssid})")
|
||||||
|
connected = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not connected:
|
||||||
|
logger.error("无法建立网络连接,请检查配置")
|
||||||
|
|
||||||
def get_userlist(order_id):
|
def get_userlist(order_id):
|
||||||
today = str(datetime.date.today())
|
today = str(datetime.date.today())
|
||||||
|
|
||||||
@ -296,10 +382,7 @@ if __name__ == '__main__':
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.info("程序启动")
|
logger.info("程序启动")
|
||||||
reset_proxy_to_default()
|
reset_proxy_to_default()
|
||||||
if not connect_wifi('ZTE_A5DA76','1234567890'): # "4G-UFI-18C8", "1234567890" 'Redmi K40','123456789'
|
connect_wifi_from_config()
|
||||||
logger.info("无法建立网络连接,请检查配置")
|
|
||||||
else:
|
|
||||||
logger.info("网络已就绪")
|
|
||||||
logger.info('初始化全局代理成功')
|
logger.info('初始化全局代理成功')
|
||||||
trade_instruction_monitor(0)
|
trade_instruction_monitor(0)
|
||||||
# trade_instruction_monitor(115138)
|
# trade_instruction_monitor(115138)
|
||||||
|
5
wifi_config.txt
Normal file
5
wifi_config.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# WiFi配置文件
|
||||||
|
# 格式:WiFi名称,密码
|
||||||
|
# 第一行是主WiFi,第二行是备用WiFi(可选)
|
||||||
|
ZTE_A5DA76,1234567890
|
||||||
|
Redmi K40,123456789
|
Loading…
x
Reference in New Issue
Block a user