xinxin
This commit is contained in:
parent
de432dfdab
commit
fb88fcbbf8
@ -7,8 +7,7 @@ Created on Fri Aug 5 15:29:12 2022
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import pyautogui
|
import pyautogui
|
||||||
import pywinauto
|
import pywinauto
|
||||||
from pywinauto import clipboard
|
from pywinauto import clipboard,keyboard
|
||||||
from pywinauto import keyboard
|
|
||||||
from skimage import io
|
from skimage import io
|
||||||
import io as mio
|
import io as mio
|
||||||
import pytesseract
|
import pytesseract
|
||||||
@ -16,16 +15,13 @@ import datetime
|
|||||||
from tools import reset_proxy_to_default
|
from tools import reset_proxy_to_default
|
||||||
reset_proxy_to_default()
|
reset_proxy_to_default()
|
||||||
from tools import *
|
from tools import *
|
||||||
from connect_wifi import connect_wifi
|
|
||||||
from iptest import get_proxy_ip,set_global_proxy,get_ip_data
|
|
||||||
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
|
||||||
|
|
||||||
from sqlalchemy import text
|
|
||||||
|
|
||||||
path = r'C:\trade_software1\trade_software\东吴证券金融终端独立下单\xiadan.exe'
|
path = r'C:\东吴证券金融终端独立下单\xiadan.exe'
|
||||||
global engine
|
global engine
|
||||||
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/',
|
||||||
|
@ -8,8 +8,7 @@ import pandas as pd
|
|||||||
import pyautogui
|
import pyautogui
|
||||||
import pywinauto
|
import pywinauto
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab
|
||||||
from pywinauto import clipboard
|
from pywinauto import clipboard,keyboard
|
||||||
from pywinauto import keyboard
|
|
||||||
from skimage import io
|
from skimage import io
|
||||||
import time
|
import time
|
||||||
import io as mio
|
import io as mio
|
||||||
@ -17,8 +16,6 @@ import pytesseract
|
|||||||
import warnings
|
import warnings
|
||||||
import datetime
|
import datetime
|
||||||
from tools import *
|
from tools import *
|
||||||
from connect_wifi import connect_wifi
|
|
||||||
from iptest import get_proxy_ip,set_global_proxy,get_ip_data
|
|
||||||
warnings.filterwarnings('ignore')
|
warnings.filterwarnings('ignore')
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -203,25 +200,8 @@ class HLClientTrader:
|
|||||||
#设置主窗口及菜单窗口
|
#设置主窗口及菜单窗口
|
||||||
self.main_wnd = self._app.window(title_re='通达信网上交易*')
|
self.main_wnd = self._app.window(title_re='通达信网上交易*')
|
||||||
self.left_wnd = self.main_wnd.window(class_name='SysTreeView32', control_id=0xE900)
|
self.left_wnd = self.main_wnd.window(class_name='SysTreeView32', control_id=0xE900)
|
||||||
# ##使用的ip mac入库
|
|
||||||
# ip = get_ip()
|
|
||||||
# mac_info = subprocess.check_output('GETMAC /v /FO list', stderr=subprocess.STDOUT)
|
|
||||||
# mac_info = mac_info.decode('gbk')
|
|
||||||
# # 想要匹配的连接名
|
|
||||||
# target_connection_name = "WLAN 2"
|
|
||||||
#
|
|
||||||
# # 构建正则表达式模式
|
|
||||||
# pattern = re.compile(
|
|
||||||
# r"连接名:\s+" + re.escape(target_connection_name) + r".*?物理地址:\s+([0-9A-Fa-f-]+)",
|
|
||||||
# re.DOTALL
|
|
||||||
# )
|
|
||||||
# # 执行搜索
|
|
||||||
# mac = pattern.search(mac_info).group(1)
|
|
||||||
# data = {'As_Of_Date': datetime.datetime.now(), 'Account_Name': account_name, 'Broker': broker, 'MAC': mac,
|
|
||||||
# 'IP': ip}
|
|
||||||
# aaa = pd.DataFrame([data])
|
|
||||||
# aaa.to_sql('trade_mac_ip', engine, schema='auth_center', index=False, if_exists='append')
|
|
||||||
# self.log.info('IP:' + ip + ' MAC:' + mac)
|
|
||||||
def _turn_off_advertising(self):
|
def _turn_off_advertising(self):
|
||||||
'''
|
'''
|
||||||
关闭弹窗
|
关闭弹窗
|
||||||
|
149
tools.py
149
tools.py
@ -1,4 +1,3 @@
|
|||||||
import socket
|
|
||||||
import warnings
|
import warnings
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
|
||||||
@ -9,12 +8,9 @@ import logging
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import smtplib
|
import smtplib
|
||||||
from email.header import Header
|
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.image import MIMEImage
|
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.application import MIMEApplication
|
from email.mime.application import MIMEApplication
|
||||||
import getpass
|
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import redis
|
import redis
|
||||||
@ -24,8 +20,6 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import winreg
|
import winreg
|
||||||
import random
|
import random
|
||||||
project_name = 'zhitou_trade'
|
|
||||||
from hashlib import md5
|
|
||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
@ -40,13 +34,7 @@ import requests
|
|||||||
import requests
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
# from alibabacloud_tea_openapi import models as open_api_models
|
|
||||||
# from alibabacloud_credentials.client import Client as CredentialClient
|
|
||||||
# from alibabacloud_credentials.models import Config as CredentialConfig
|
|
||||||
# from alibabacloud_ocr_api20210707.client import Client as OcrClient
|
|
||||||
# from alibabacloud_ocr_api20210707 import models as ocr_models
|
|
||||||
# from alibabacloud_tea_util import models as util_models
|
|
||||||
# from alibabacloud_tea_util.client import Client as StreamClient
|
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
root_path = Path(__file__).parent
|
root_path = Path(__file__).parent
|
||||||
@ -466,45 +454,6 @@ def tranTicker(tick):
|
|||||||
tick = 'SZ' + num * '0' + tick
|
tick = 'SZ' + num * '0' + tick
|
||||||
|
|
||||||
return tick
|
return tick
|
||||||
def ocr_image(image_path):
|
|
||||||
"""
|
|
||||||
传入图片路径,返回识别到的文字内容
|
|
||||||
"""
|
|
||||||
|
|
||||||
access_key_id = 'LTAI5tA4dy591hCgEBfsxZei'
|
|
||||||
access_key_secret = 'edYHXSVYda8HomlEsnsyQzw1QGu1EN'
|
|
||||||
|
|
||||||
if not os.path.exists(image_path):
|
|
||||||
raise FileNotFoundError(f"图片文件不存在: {image_path}")
|
|
||||||
|
|
||||||
# 第一步:用新版 credential 初始化
|
|
||||||
credential_config = CredentialConfig(
|
|
||||||
type='access_key',
|
|
||||||
access_key_id=access_key_id,
|
|
||||||
access_key_secret=access_key_secret
|
|
||||||
)
|
|
||||||
credential = CredentialClient(credential_config)
|
|
||||||
|
|
||||||
# 第二步:openapi config
|
|
||||||
config = open_api_models.Config(
|
|
||||||
credential=credential,
|
|
||||||
endpoint='ocr-api.cn-hangzhou.aliyuncs.com'
|
|
||||||
)
|
|
||||||
|
|
||||||
# 第三步:初始化 OCR client
|
|
||||||
client = OcrClient(config)
|
|
||||||
|
|
||||||
# 第四步:准备请求参数
|
|
||||||
body_stream = StreamClient.read_from_file_path(image_path)
|
|
||||||
request = ocr_models.RecognizeAllTextRequest(
|
|
||||||
body=body_stream,
|
|
||||||
type='Advanced'
|
|
||||||
)
|
|
||||||
runtime = util_models.RuntimeOptions()
|
|
||||||
|
|
||||||
# 第五步:发起请求
|
|
||||||
response = client.recognize_all_text_with_options(request, runtime)
|
|
||||||
return response.body.data.content
|
|
||||||
|
|
||||||
def get_price(tick, level='1', op="buy"):
|
def get_price(tick, level='1', op="buy"):
|
||||||
level = int(level)
|
level = int(level)
|
||||||
@ -932,19 +881,6 @@ class SetMac(object):
|
|||||||
# 28-CD-C4-CB-FD-CF
|
# 28-CD-C4-CB-FD-CF
|
||||||
|
|
||||||
def randomMAC(self):
|
def randomMAC(self):
|
||||||
# mac = [ 0x52, 0x54, 0x00,
|
|
||||||
# random.randint(0x00, 0x7f),
|
|
||||||
# random.randint(0x00, 0xff),
|
|
||||||
# random.randint(0x00, 0xff) ]
|
|
||||||
#
|
|
||||||
# while True:
|
|
||||||
# one_mac = ''.join(map(lambda x: "%02x" % x, mac)).upper()
|
|
||||||
# used_mac = redis_lget('Mac', -1)
|
|
||||||
# used_mac = [i.decode() for i in used_mac]
|
|
||||||
#
|
|
||||||
# if one_mac not in used_mac:
|
|
||||||
# r.rpush('Mac',one_mac)
|
|
||||||
# break
|
|
||||||
while True:
|
while True:
|
||||||
first_byte = 0x02
|
first_byte = 0x02
|
||||||
# 从 UUIDv4 获取后 5 个字节,随机性极高
|
# 从 UUIDv4 获取后 5 个字节,随机性极高
|
||||||
@ -1059,6 +995,8 @@ def get_ip():
|
|||||||
except:
|
except:
|
||||||
return '60.162.69.53'
|
return '60.162.69.53'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def reset_proxy_to_default():
|
def reset_proxy_to_default():
|
||||||
"""恢复系统代理为默认(关闭)"""
|
"""恢复系统代理为默认(关闭)"""
|
||||||
key = winreg.OpenKey(
|
key = winreg.OpenKey(
|
||||||
@ -1076,8 +1014,89 @@ def reset_proxy_to_default():
|
|||||||
internet_set_option(0, 37, 0, 0)
|
internet_set_option(0, 37, 0, 0)
|
||||||
internet_set_option(0, 39, 0, 0)
|
internet_set_option(0, 39, 0, 0)
|
||||||
|
|
||||||
|
def set_global_proxy(proxy_ip, proxy_port, enable=True):
|
||||||
|
"""设置/关闭全局代理"""
|
||||||
|
key = None
|
||||||
|
try:
|
||||||
|
if ctypes.windll.shell32.IsUserAnAdmin() == 0:
|
||||||
|
logging.error("需要管理员权限来修改系统代理设置")
|
||||||
|
return False
|
||||||
|
|
||||||
|
key = winreg.OpenKey(
|
||||||
|
winreg.HKEY_CURRENT_USER,
|
||||||
|
r"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
|
||||||
|
0, winreg.KEY_WRITE | winreg.KEY_READ
|
||||||
|
)
|
||||||
|
|
||||||
|
# 备份当前设置
|
||||||
|
try:
|
||||||
|
old_proxy = winreg.QueryValueEx(key, "ProxyServer")[0]
|
||||||
|
old_enable = winreg.QueryValueEx(key, "ProxyEnable")[0]
|
||||||
|
old_override = winreg.QueryValueEx(key, "ProxyOverride")[0]
|
||||||
|
except WindowsError:
|
||||||
|
old_proxy = ""
|
||||||
|
old_enable = 0
|
||||||
|
old_override = "<local>"
|
||||||
|
|
||||||
|
if enable:
|
||||||
|
proxy_string = f"{proxy_ip}:{proxy_port}"
|
||||||
|
winreg.SetValueEx(key, "ProxyServer", 0, winreg.REG_SZ, proxy_string)
|
||||||
|
winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, 1)
|
||||||
|
bypass = "<local>;" + ";".join(["/api", "/static"])
|
||||||
|
winreg.SetValueEx(key, "ProxyOverride", 0, winreg.REG_SZ, bypass)
|
||||||
|
else:
|
||||||
|
winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, 0)
|
||||||
|
|
||||||
|
# 刷新系统设置
|
||||||
|
internet_set_option = ctypes.windll.Wininet.InternetSetOptionW
|
||||||
|
internet_set_option(0, 37, 0, 0) # INTERNET_OPTION_REFRESH
|
||||||
|
internet_set_option(0, 39, 0, 0) # INTERNET_OPTION_SETTINGS_CHANGED
|
||||||
|
|
||||||
|
logging.info("代理设置已" + ("启用" if enable else "关闭"))
|
||||||
|
if enable:
|
||||||
|
logging.info(f"代理服务器: {proxy_ip}:{proxy_port}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"设置代理时发生错误: {str(e)}")
|
||||||
|
if key is not None:
|
||||||
|
try:
|
||||||
|
winreg.SetValueEx(key, "ProxyServer", 0, winreg.REG_SZ, old_proxy)
|
||||||
|
winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, old_enable)
|
||||||
|
winreg.SetValueEx(key, "ProxyOverride", 0, winreg.REG_SZ, old_override)
|
||||||
|
logging.info("已恢复原始代理设置")
|
||||||
|
except:
|
||||||
|
logging.warning("警告:无法恢复原始代理设置")
|
||||||
|
return False
|
||||||
|
finally:
|
||||||
|
if key:
|
||||||
|
winreg.CloseKey(key)
|
||||||
|
|
||||||
|
|
||||||
|
def get_ip_data():
|
||||||
|
"""从API获取代理IP和端口"""
|
||||||
|
url = "http://api.tianqiip.com/getip"
|
||||||
|
params = {
|
||||||
|
"secret": "d8wqfdf0qhrnxgne", # 替换为你的提取秘钥
|
||||||
|
"num": 1,
|
||||||
|
"yys": "电信",
|
||||||
|
"type": "json",
|
||||||
|
"lb": "\n",
|
||||||
|
# "region": "1,2,3",
|
||||||
|
"port": 1,
|
||||||
|
"time": 5,
|
||||||
|
"ts": 1,
|
||||||
|
"ys": 1,
|
||||||
|
"cs": 1,
|
||||||
|
"sign": "386ff88188185bc6070ec011266745b3", # 用户签名
|
||||||
|
"mr": 1
|
||||||
|
}
|
||||||
|
response = requests.get(url,params)
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
if data.get("code") == 1000:
|
||||||
|
logging.info("获取代理IP成功")
|
||||||
|
return data.get("data")[0]
|
||||||
|
|
||||||
def reset_wlan():
|
def reset_wlan():
|
||||||
warnings.filterwarnings('ignore')
|
warnings.filterwarnings('ignore')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user