Comments (5)
class Xls(BaseStrategy):
"""
通过将 Grid 另存为 xls 文件再读取的方式获取 grid 内容
"""
def __init__(self, tmp_folder: Optional[str] = None):
"""
:param tmp_folder: 用于保持临时文件的文件夹
"""
super().__init__()
self.tmp_folder = tmp_folder
def get(self, control_id: int) -> List[Dict]:
grid = self._get_grid(control_id)
# ctrl+s 保存 grid 内容为 xls 文件
self._set_foreground(grid) # setFocus buggy, instead of SetForegroundWindow
grid.type_keys("^s", set_foreground=False)
# count = 10
# while count > 0:
# if self._trader.is_exist_pop_dialog():
# break
# self._trader.wait(0.2)
# count -= 1
if (self._trader.app.top_window().window(class_name="Static", title_re="验证码").exists(timeout=1)): #检查是否有验证码输入Window
file_path = "tmp.png"
count = 5
found = False
while count > 0:
self._trader.app.top_window().window(
control_id=0x965, class_name="Static"
).capture_as_image().save(
file_path
) # 保存验证码
captcha_num = captcha_recognize(file_path).strip() # 识别验证码
captcha_num = "".join(captcha_num.split())
logger.info("captcha result-->" + captcha_num)
if len(captcha_num) == 4:
editor = self._trader.app.top_window().window(
control_id=0x964, class_name="Edit")
editor.select()
editor.type_keys(captcha_num)
self._trader.app.top_window().set_focus()
pywinauto.keyboard.SendKeys("{ENTER}") # 模拟发送enter,点击确定
if self._trader.app.window(title='另存为').exists(timeout=1):
found = True
break
logger.info(f"captcha result:{captcha_num} error")
count -= 1
self._trader.wait(0.1)
self._trader.app.top_window().window(
control_id=0x965, class_name="Static"
).click()
if not found:
self._trader.app.top_window().Button2.click() # 点击取消
temp_path = tempfile.mktemp(suffix=".xls", dir=self.tmp_folder)
self._set_foreground(self._trader.app.top_window())
# alt+s保存,alt+y替换已存在的文件
self._trader.app.top_window().Edit1.set_edit_text(temp_path)
self._trader.wait(0.1)
self._trader.app.top_window().type_keys("%{s}%{y}", set_foreground=False)
# Wait until file save complete otherwise pandas can not find file
self._trader.wait(0.2)
if self._trader.is_exist_pop_dialog():
self._trader.app.top_window().Button2.click()
self._trader.wait(0.2)
return self._format_grid_data(temp_path)
def _format_grid_data(self, data: str) -> List[Dict]:
with open(data, encoding="gbk", errors="replace") as f:
content = f.read()
df = pd.read_csv(
StringIO(content),
delimiter="\t",
dtype=self._trader.config.GRID_DTYPE,
na_filter=False,
)
return df.to_dict("records")
from easytrader.
方便给一份完整代码我吗
from easytrader.
您好,可以给我一份完整代码吗?
from easytrader.
推送pr啊
from easytrader.
Tesseract 使用参考这两文章https://blog.csdn.net/u010454030/article/details/80515501 和 https://blog.csdn.net/wang_hugh/article/details/80760940
from easytrader.
Related Issues (20)
- 安装easytrder过程提示ValueError: check_hostname requires server_hostname,如何解决 HOT 2
- 请问之后会加入市价委托吗,目前都是限价委托 HOT 1
- Could not create the process "c:\\ths\\xiadan.exe"如何解决? HOT 1
- 无法撤单 HOT 1
- 用同花顺跟单聚宽,提示TypeError: '<=' not supported between instances of 'str' and 'int'怎么解决
- balance HOT 1
- 提交委托有时候能运行有时候不运行
- 如何解决“TypeError: 'dict' object is not callable”错误?
- 求物理机,最佳运行环境 HOT 1
- 推荐一个券商可 股票 可转债 ETF 交易接口(python),easytrader已经不更新了
- 撤不了单:执行到进入撤单窗口--选中委托单后就停止了 ,而程序运行完毕 没有报错 HOT 2
- 大数据AI推荐
- perf_clock 程序建议不要修改原方法的参数说明
- 各位大佬,接聚宽,不支持对应市场类型,无法下单是啥情况 HOT 1
- cannot import name 'SetForegroundWindow' from 'pywinauto.win32functions' HOT 1
- prepare执行时弹出异常
- 无法使用命令行模式 HOT 1
- 国金全能行自动交易时不能识别验证码,求解 HOT 2
- 怎样用entrust_no撤单?我总是撤不了单。比如:rul=buy('600519',price=2000.00,amount=100),获取的entrust_no是{'entrust_no':'12345678'}撤单源码应该怎样写 HOT 1
- 国金客户端(全能行证券交易终端PC版)登录报错
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easytrader.