background
I recently encountered a need to export a large amount of data, but I did not write the data export program. The most important is that the manufacturer to the program can only support a maximum of seven days (must spit bad), which light waiting to write local time is about ten minutes. I roughly calculate, the average day more than 1,000 data, let me guide three years of data, if manual operation, the construction period is estimated to take about 10 days, so I decided to use python tool class PyWinAuto to achieve.
(1) Ideas
I need the program to PC exe file system automatically fill in the start time and end time, and then click the export button starts automatically performing export, then 10 minutes after the start time = end time + 1, + 6 = end time, end time to set the maximum time, when the maximum time less than end time, end of the mission.
(2) Environment construction
(1) python3.6Copy the code
(3) Code implementation
StatusBar: StatusBar Static content: Static Button: Button CheckBOX: RadioButton GroupBOX: GroupBOX GroupBOX: ComboxBox dialog box (window) : PopupMenu: PopupMenu TabControl: TabControl Toolbar: Toolbar tooltip: ToolTips tree view: Tree View Menu, Menultem, Pane Pane "" from PywinAuto Import Application Import time Import Datetime import ConfigParser # os.system(" Pause ") Navicat # app = Application("uia").start(r"F:\exportData\ realBasetopostGRE.exe ") cf = configparser.ConfigParser() cf.read("config.ini",encoding='utf-8-sig') secs = cf.sections() # Secs = cf.sections() secs = cf.sections() secs = cf.sections() Mailbox-specific configuration, # each section is wrapped by [], i.e. [section]), Get ("info","path") sleepTime =cf. Get ("info"," sleep") initime =cf. Get ("info"," sleep") "Initime ") app = Application("uia"). Start (r""+path) print(' wait :',initime,' second program initialization complete ') endDate=cf.get("info","endDate") id=cf.get("info","id") maxDate = cf.get('info','maxDate') maxDate = (datetime.datetime.strptime(str(maxDate), "%Y-%m-%d") + datetime.timedelta(days=0)).strftime("%Y-%m-%d") print(maxDate) count = 0 #print('1:',startDate,endDate) While (True): if (endDate >= maxDate): endDate = maxDate print(' endDate >= maxDate ') ') print('The count is:', DLG = app["TN8000 "] edit = DLG [' edit '] edit2 = DLG ['Edit1'] Edit1 = dlg['Edit2'] edit3 = dlg['Edit3'] # edit.type_keys('edit') # send_keys(Keys.SPACE) edit1.type_keys(startDate+"{SPACE}00:00:00") edit2.type_keys(endDate+"{SPACE}23:59:59") edit3.type_keys(id) button1 = DLG [" start exporting "] button1.click() print(' Have clicked the export button, now wait :', sleepTime, 'second! ') time. Sleep (int (sleepTime)) + 1 # # # dormancy x seconds start time mStartDate = (datetime. Datetime. Strptime (STR (endDate), "Y - m - % d % %") + datetime. Timedelta (days = 1)). Strftime (" % % m - Y % d ") # # mEndate = 7 days end time (datetime.datetime.strptime(str(endDate), "%Y-%m-%d") + datetime.timedelta(days=1)).strftime("%Y-%m-%d") startDate=mStartDate # endDate=startDate endDate=mEndate #print('2:', startDate, endDate) if(startDate>maxDate): print(' startDate exceeded the maximum date, ready to end...... ') break # datetime.datetime.strptime(str(startDate), "%Y-%m-%d") + datetime.timedelta(days=1).strftime("%Y-%m-%d") # endDate=datetime.datetime.strptime(str(startDate), "%Y-%m-%d")+datetime.timedelta(days=1).strftime("%Y-%m-%d") # print (endDate) print("Good bye!" # # print all the controls in the window # dlG.print_control_IDENTIfiers () # # print(dlg.print_control_identifiers())Copy the code
Thinking on
1. Start xx.exe with Application and use exe to select window controls by window title to get DLG.print_control_identifiers ().
(4) the config. Ini configuration
[info] path=F:\exportData\xx.exe startDate=2018-01-01 endDate=2018-01-06 #maxDate=2021-05-01 maxDate=2021-05-01 id=1 Max =4 sleep=120 # Program initialization time iniTime = 10 configPath=config.iniCopy the code
(5) Effect
(5) Compile and package as.exe file
Cx-freeze: cX-freeze: cX-freeze: cX-freeze: cX-freeze: CX-freeze: CX-freeze: CX-freeze: CX-freeze: CX-freeze: CX-freeze: CX-freeze: CX-freeze: CX-freeze: CX-freeze
(1) Install the CX-Freeze plug-in
(2) Pack
CMD to project directory.\venv\Scripts.. For example, F:\PythonWorkSpace\ Untitled3 \venv\Scripts\ cxfreex.exe
Open in Terminal and enter:
F:\PythonWorkSpace\untitled3\venv\Scripts\cxfreeze.exe winauto.py --target-dir dist
Copy the code
Among themtarget-dir distIs to store the packaged file in the current directory dist, the effect is as follows:
End: Double-click exe file to run.