③用configparser解析配置文件

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
[family]
; 家族人员名单,亲属顺序根据微信’随申码‘的顺序,本人在最后,根据钉钉的设置,最多5个人
familyList=爸爸, 大宝, 二宝, 妈妈
ddMain=二宝
xhbMain=大宝
[time]
; 定义等待间隔时间
pyautoguiPAUSE = 2
generalWaitTime = 2
generalWaitTime_speed_high = 0.2
generalTimeAdjust = 3
generalTimeAdjust_speed_high = 1
generalTimeAdjust_speed_low = 5
[log]
; 定义日志参数,0表示控制台输出,1表示文件输出,2表示同时输出
basicLogFileName = logger.log
logFileName = log.txt
logMode = 2
level = DEBUG
[password]
passwordFile = password
[weixin-ssm]
; 微信随申码相关的控制参数
; 定义微信安装位置
wxAppName = C:\\Program Files (x86)\\Tencent\\WeChat\\WeChat.exe
; 定义微信登录窗口
wxLoginWindowClass = WeChatLoginWndForPC
wxLoginWindowName = 登录
wxLoginBtnPic = img/weixin/wxLogin.png
; 定义微信主窗口
wxWindowClass = WeChatMainWndForPC
wxWindowName = 微信
; 定义微信小程序面板窗口
wxMicroPgWindowClass = AppletPanelWnd
wxMicroPgWindowName =
wx_xcxPic = img/weixin/wx_xcx.png
; 定义随申办的窗口
ssbWindowClass=Chrome_WidgetWin_0
ssbWindowName=随申办
wx_ssbPic = img/weixin/wx_ssb.png
; 定义一些鼠标移动的相对常量
; 0. 微信登录窗口的登录按钮位置
wxLoginBtn_x = 138
wxLoginBtn_y = 279
; 1. 微信主窗口位置
left = 0
top = 0
width = 800
height = 600
repaint = 1
; 2. 搜索框
searchBox_x = 150
searchBox_y = 37
; 3. 小程序面板
microPg_x = 30
microPg_y = 490
; 4. 查找小程序
s_microPg_x = 300
s_microPg_y = 450
; 5. 随申办定位
ssb_x = 115
ssb_y = 320
; 6. 随申码定位
ssm_x = 235
ssm_y = 280
; 7. 亲属随申码主链接
ssm_main_link_x = 347
ssm_main_link_y = 191
; 8. 亲属随申码定位(x不变,y从310开始,以93位间隔增长)
ssm_family_x = 347
ssm_family_start_y = 310
ssm_family_interval_y = 93
; 亲属随申码返回的时候需要调整位置
ssm_family_adjust_y = 10
; 定义搜索内容
wxSearch =
; 截图区域
imgLeft = 5
imgTop = 62
imgRight = 405
imgBottom = 675
[Dingding]
; 钉钉相关控制参数
; 定义钉钉安装位置
ddAppName = C:\\Program Files (x86)\\DingDing\\DingtalkLauncher.exe
ddLoginWindowClass = StandardFrame_Loging
ddLoginWindowName = 钉钉
ddPasswordLoginPic = img/dingding/ddPasswordLogin.png
ddPasswordLogin_x = 210
ddPasswordLogin_y = 70
ddInputPassword = img/dingding/inputPassword.png
ddInputPassword_x = 200
ddInputPassword_y = 316
ddInputPhoneNumber = img/dingding/inputPhoneNumber.png
ddInputPhoneNumber_x = 215
ddInputPhoneNumber_y = 272
ddLoginBtn = img/dingding/loginBtn.png
ddLoginBtn_x = 257
ddLoginBtn_y = 316
ddLoginPhone = 钉钉登录手机号
; 定义钉钉主窗口
ddWindowClass = StandardFrame_DingTalk
ddWindowName = 钉钉
ddWidth = 960
ddHeight = 640
; 获得省的列表并取得相应的省
sheng_pullPosition_x = 363
sheng_pullPosition_y = 246
sheng_scroll = -100
sheng_scroll_from_x = 350
sheng_scroll_from_y = 250
; 获得市的列表并取得相应的市
shi_pullPosition_x = 472
shi_pullPosition_y = 246
shi_scroll = -150
shi_scroll_from_x = 450
shi_scroll_from_y = 300
; 获得区的列表并取得相应的区
qu_pullPosition_x = 585
qu_pullPosition_y = 246
qu_scroll = -150
qu_scroll_from_x = 550
qu_scroll_from_y = 300
; 上传随申码确认按钮距离边界的差值
uploadConfirmBtn_x = 70
uploadConfirmBtn_y = 30
; 工作窗口图标
workWindowSign_x = 30
workWindowSign_y = 220
; 选择工作单位
workOrgSelect_x = 500
workOrgSelect_y = 53
confirmWorkOrg_x = 500
confirmWorkOrg_y = 202
; OA工作台首页
oaHomepage_x = 140
oaHomepage_y = 93
oaRefresh_x = 187
oaRefresh_y = 52
; 每日填报
mrtb_scroll_from_x = 150
mrtb_scroll_from_y = 150
mrtb_scroll = -400
mrtb_default_x = 550
mrtb_default_y = 225
; 寻找表格
mrtb_table_x = 273
mrtb_table_y = 584
; 处理表格
table_scroll = -250
table_uploade_scroll = -50
table_upload_scroll_adjust = 67
table_small_scroll = -80
; 日期
currentDate_x = 240
currentDate_y = 246
todayBtn_x = 346
todayBtn_y = 548
; 体温
temp = 36.7
temp_x = 250
temp_y = 350
; 健康
jiankang_x = 214
jiankang_y = 461
; 城市
city_x = 269
city_y = 214
sheng_default_x = 235
sheng_default_y = 338
shi_default_x = 420
shi_default_y = 254
qu_default_x = 539
qu_default_y = 402
; 社区
shequ_x = 214
shequ_y = 352
; 旅行
lvxing_x = 214
lvxing_y = 494
; 接触
jiechu_x = 214
jiechu_y = 220
; 图片上传
ddMain_pic_x = 231
ddMain_pic_y = 245
family_start_x = 231
family_start_y = 323
; 最终提交
submit_x = 273
submit_y = 605
; 关闭填表
close_table_x = 501
close_table_y = 90
; 关闭每日填表
close_mrtb_x = 358
close_mrtb_y = 90
[xiaoheiban]
; 定义晓黑板相关的控制参数
; 晓黑板的安装绝对路径
xhbAppName = C:\\Program Files (x86)\\xiaoheiban\\晓黑板.exe
xhbLoginWindowClass = Chrome_WidgetWin_1
xhbLoginWindowName = 晓黑板登录
xhbMainWindowClass = Chrome_WidgetWin_1
xhbMainWindowName = 消息/全部
xhbLoginPhone = 哓黑板登录手机号

解析程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import configparser
import logging
from logging import handlers
configFilename="suishencode.ini"
class ConfigData(object):
config = configparser.ConfigParser()
config.read(configFilename, encoding='utf-8')
# ********************************* #
# 全局参数定义开始 #
# ********************************* #
# 定义家属列表
familyList = config.get('family', 'familyList').strip().split(',')
ddMain = config.get('family', 'ddMain').strip()
xhbMain = config.get('family', 'xhbMain').strip()
# 定义等待间隔时间
pyautoguiPAUSE = config.getint('time', 'pyautoguiPAUSE')
generalWaitTime_speed_high = config.getfloat('time', 'generalWaitTime_speed_high')
generalWaitTime = config.getint('time', 'generalWaitTime')
generalTimeAdjust = config.getint('time', 'generalTimeAdjust')
generalTimeAdjust_speed_high = config.getint('time', 'generalTimeAdjust_speed_high')
generalTimeAdjust_speed_low = config.getint('time', 'generalTimeAdjust_speed_low')
# 日志参数
basicLogFileName = config.get('log', 'basicLogFileName')
logFileName = config.get('log', 'logFileName')
logMode = config.getint('log', 'logMode')
logLevelDefinition = {'DEBUG': 10,
'INFO': 20,
'NOTSET': 0,
'WARNING': 30,
'ERROR': 40,
'CRITICAL': 50}
logLevel = logLevelDefinition[config.get('log', 'level')]
passwordFile = config.get('password', 'passwordFile')
# ********************************* #
# 全局参数定义结束 #
# ********************************* #
# ********************************* #
# 微信随申码获取参数定义开始 #
# ********************************* #
# 定义微信APP安装位置
wxAppName = config.get('weixin-ssm', 'wxAppName').strip()
# 定义微信登录窗口
wxLoginWindowClass = config.get('weixin-ssm', 'wxLoginWindowClass').strip()
wxLoginWindowName = config.get('weixin-ssm', 'wxLoginWindowName').strip()
wxLoginBtnPic = config.get('weixin-ssm', 'wxLoginBtnPic').strip()
wxLoginBtn_x = config.getint('weixin-ssm', 'wxLoginBtn_x')
wxLoginBtn_y = config.getint('weixin-ssm', 'wxLoginBtn_y')
# 定义微信主窗口
wxWindowClass = config.get('weixin-ssm', 'wxWindowClass').strip()
wxWindowName = config.get('weixin-ssm', 'wxWindowName').strip()
# 定义微信小程序面板窗口
wxMicroPgWindowClass = config.get('weixin-ssm', 'wxMicroPgWindowClass').strip()
wxMicroPgWindowName = config.get('weixin-ssm', 'wxMicroPgWindowName').strip()
wx_xcxPic = config.get('weixin-ssm', 'wx_xcxPic').strip()
wx_ssbPic = config.get('weixin-ssm', 'wx_ssbPic').strip()
# 定义随申办的窗口
ssbWindowClass=config.get('weixin-ssm', 'ssbWindowClass').strip()
ssbWindowName=config.get('weixin-ssm', 'ssbWindowName').strip()
# 定义一些鼠标移动的相对常量
# 0. 窗口位置
left = config.getint('weixin-ssm', 'left')
top = config.getint('weixin-ssm', 'top')
width = config.getint('weixin-ssm', 'width')
height = config.getint('weixin-ssm', 'height')
repaint = config.getint('weixin-ssm', 'repaint')
# 1. 搜索框
searchBox_x = config.getint('weixin-ssm', 'searchBox_x')
searchBox_y = config.getint('weixin-ssm', 'searchBox_y')
# 2. 小程序面板
microPg_x = config.getint('weixin-ssm', 'microPg_x')
microPg_y = config.getint('weixin-ssm', 'microPg_y')
# 3. 查找小程序
s_microPg_x = config.getint('weixin-ssm', 's_microPg_x')
s_microPg_y = config.getint('weixin-ssm', 's_microPg_y')
# 4. 随申办定位
ssb_x = config.getint('weixin-ssm', 'ssb_x')
ssb_y = config.getint('weixin-ssm', 'ssb_y')
# 5. 随申码定位
ssm_x = config.getint('weixin-ssm', 'ssm_x')
ssm_y = config.getint('weixin-ssm', 'ssm_y')
# 6. 亲属随申码主链接
ssm_main_link_x = config.getint('weixin-ssm', 'ssm_main_link_x')
ssm_main_link_y = config.getint('weixin-ssm', 'ssm_main_link_y')
# 7. 亲属随申码定位(x不变,y从310开始,以93位间隔增长)
ssm_family_x = config.getint('weixin-ssm', 'ssm_family_x')
ssm_family_start_y = config.getint('weixin-ssm', 'ssm_family_start_y')
ssm_family_interval_y = config.getint('weixin-ssm', 'ssm_family_interval_y')
ssm_family_adjust_y = config.getint('weixin-ssm', 'ssm_family_adjust_y') # 亲属随申码返回的时候需要调整位置
# 定义搜索内容
forSearch = config.get('weixin-ssm', 'wxSearch').strip()
# 截图区域
imgLeft = config.getint('weixin-ssm', 'imgLeft')
imgTop = config.getint('weixin-ssm', 'imgTop')
imgRight = config.getint('weixin-ssm', 'imgRight')
imgBottom = config.getint('weixin-ssm', 'imgBottom')
# ********************************* #
# 微信随申码获取参数定义结束 #
# ********************************* #
# ********************************* #
# 钉钉获取参数定义开始 #
# ********************************* #
# 定义钉钉APP安装位置
ddAppName = config.get('Dingding', 'ddAppName').strip()
# 定义钉钉登录窗口
ddLoginWindowClass = config.get('Dingding', 'ddLoginWindowClass').strip()
ddLoginWindowName = config.get('Dingding', 'ddLoginWindowName').strip()
ddPasswordLoginPic = config.get('Dingding', 'ddPasswordLoginPic').strip()
ddPasswordLogin_x = config.getint('Dingding', 'ddPasswordLogin_x')
ddPasswordLogin_y = config.getint('Dingding', 'ddPasswordLogin_y')
ddInputPassword = config.get('Dingding', 'ddInputPassword').strip()
ddInputPassword_x = config.getint('Dingding', 'ddInputPassword_x')
ddInputPassword_y = config.getint('Dingding', 'ddInputPassword_y')
ddInputPhoneNumber = config.get('Dingding', 'ddInputPhoneNumber').strip()
ddInputPhoneNumber_x = config.getint('Dingding', 'ddInputPhoneNumber_x')
ddInputPhoneNumber_y = config.getint('Dingding', 'ddInputPhoneNumber_y')
ddLoginBtn = config.get('Dingding', 'ddLoginBtn').strip()
ddLoginBtn_x = config.getint('Dingding', 'ddLoginBtn_x')
ddLoginBtn_y = config.getint('Dingding', 'ddLoginBtn_y')
ddLoginPhone = config.get('Dingding', 'ddLoginPhone').strip()
# 定义钉钉窗口
ddWindowClass = config.get('Dingding', 'ddWindowClass').strip()
ddWindowName = config.get('Dingding', 'ddWindowName').strip()
ddWidth = config.getint('Dingding', 'ddWidth')
ddHeight = config.getint('Dingding', 'ddHeight')
# ********************************* #
# 钉钉获取参数定义结束 #
# ********************************* #
# ********************************* #
# 晓黑板获取参数定义开始 #
# ********************************* #
# 定义晓黑板窗口
# ********************************* #
# 晓黑板获取参数定义结束 #
# ********************************* #
# 定义晓黑板APP安装位置
xhbAppName = config.get('xiaoheiban', 'xhbAppName').strip()
# 晓黑板登录窗口
xhbLoginWindowClass = config.get('xiaoheiban', 'xhbLoginWindowClass').strip()
xhbLoginWindowName = config.get('xiaoheiban', 'xhbLoginWindowName').strip()
# 晓黑板主窗口
xhbMainWindowClass = config.get('xiaoheiban', 'xhbMainWindowClass').strip()
xhbMainWindowName = config.get('xiaoheiban', 'xhbMainWindowName').strip()
xhbLoginPhone = config.get('xiaoheiban', 'xhbLoginPhone').strip()
if __name__ == '__main__':
cd = ConfigData()