-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxxqg.py
329 lines (276 loc) · 11.2 KB
/
xxqg.py
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
import time
import random
import uiautomator2 as u2
from operator import itemgetter
#
# 连接到设备
# d = u2.connect('192.168.3.5:5555')
d = u2.connect('NAB0220630013667')
#打印设备信息以确认连接成功
print(d.device_info)
# d.app_stop("cn.xuexi.android")
print("在ATX中启动UIAUTOMATOR")
time.sleep(10)
d.app_start("cn.xuexi.android")
###################################################################
#点击要闻
while True:
if d(text="取消").exists():
d(text="取消").click()
element = d(text="要闻")
if element.exists():
element.click()
break
print("--------------------------------------------------------")
print("开始阅读文章")
#看文章
j=0
for i in range(1,9):
j=j+1
element = d.xpath('//android.widget.ListView/android.widget.FrameLayout[{}]'.format(j))
if element.exists:
element.click()
time.sleep(50 + random.random() * 5)
if i == 1:
print("--------------------------------------------------------")
print("正在发表观点")
print("--------------------------------------------------------")
d(text="欢迎发表你的观点").click()
time.sleep(1)
d(text="好观点将会被优先展示").set_text("坚定信念,走强国之路") # 输入新的文本
time.sleep(1)
d(text="发布").click()
time.sleep(1)
if d(text="访问异常").exists:
time.sleep(30)
# d.xpath('//*[@resource-id="cn.xuexi.android:id/TOP_LAYER_VIEW_ID"]/android.widget.ImageView[1]').click()
# break
# d.xpath('//*[@resource-id="cn.xuexi.android:id/BOTTOM_LAYER_VIEW_ID"]/android.widget.ImageView[1]').click()
d.xpath('//*[@resource-id="cn.xuexi.android:id/TOP_LAYER_VIEW_ID"]/android.widget.ImageView[1]').click()
else:
d.swipe_ext("up")
j = 2
time.sleep(3)
###################################################################
#本地
print("--------------------------------------------------------")
print("本地学习中")
time.sleep(1)
d.xpath('//*[@resource-id="cn.xuexi.android:id/view_pager"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.ImageView[1]').click()
time.sleep(1)
d(text="北京").click()
time.sleep(1)
d.xpath('//androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[1]').click()
time.sleep(1)
d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[2]/android.widget.FrameLayout[3]/android.widget.ImageView[1]').click()
###################################################################
print("--------------------------------------------------------")
print("看视频")
#点百灵
time.sleep(2)
d.xpath('//*[@resource-id="cn.xuexi.android:id/home_bottom_tab_button_ding"]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]').click()
time.sleep(1)
d(text="竖").click()
time.sleep(1)
d.xpath('//android.widget.ListView/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]').click()
time.sleep(1)
for i in range(1,10):
d.swipe_ext("up")
time.sleep(40+random.random()*5)
d(resourceId="cn.xuexi.android:id/iv_back").click()
###################################################################
##答题
time.sleep(1)
d(resourceId="cn.xuexi.android:id/comm_head_xuexi_mine").click()
time.sleep(1)
d.click(0.502, 0.396)
time.sleep(1)
if d(text="").exists():
d(text="").click()
#获取提示
def getanswer():
d.swipe_ext("up")
time.sleep(1)
d.swipe_ext("up")
d(text="查看提示").click()
time.sleep(1)
answer = d.xpath('//*[@resource-id="app"]/android.view.View[2]/android.view.View[3]/android.view.View[2]/android.view.View[1]').get_text()
print("答案",answer)
d(text="").click()
return answer
#获取相似度
import difflib
def string_similar(s1, s2):
return difflib.SequenceMatcher(None, s1, s2).quick_ratio()
def daydati():
time.sleep(1)
d(text="每日答题").click()
try:
while "/5" in d.xpath('//*[@resource-id="app"]/android.view.View[2]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[2]').get_text():
time.sleep(1)
answer = getanswer()
if answer == "请观看视频":
d(text="").click()
time.sleep(1)
d(text="").click()
time.sleep(1)
d(text="退出").click()
daydati()
break
if d(text="单选题").exists() or d(text="多选题").exists():
elements = d.xpath('//android.widget.ListView').all()
xuanxiangs = []
for son in elements:
gsons = son.elem.getchildren()
for gson in gsons :
ggsons = gson.getchildren()
for ggson in ggsons:
gggsons = ggson.getchildren()
xuanxiangs.append(gggsons[2].get("text"))
print(gggsons[2].get("text"))
i=0
for xuanxiang in xuanxiangs:
if "错误" in xuanxiang:
d(text="错误").click()
time.sleep(1)
if d(text="答案解析").exists():
d(text="").click()
time.sleep(1)
d(text="退出").click()
daydati()
break
elif xuanxiang in answer:
d(text=xuanxiang).click()
i=i+1
time.sleep(0.5)
if i == 0:
sim=[]
for xuanxiang in xuanxiangs:
sim.append(string_similar(xuanxiang, answer))
max_index, max_number = max(enumerate(sim), key=itemgetter(1))
time.sleep(1)
d(text=xuanxiangs[max_index]).click()
time.sleep(2)
if d(text="确定").exists():
d(text="确定").click()
time.sleep(1)
if d(text="答案解析").exists():
time.sleep(1)
print("出现错误")
d(text="").click()
time.sleep(1)
d(text="退出").click()
daydati()
break
elif d(text="填空题").exists():
elements = d.xpath(
'//*[@resource-id="app"]/android.view.View[2]/android.view.View[1]/android.view.View[1]/android.view.View[2]').all()
for eles in elements:
sons = eles.elem.getchildren()
if answer.find(sons[0].get("text")[-5:]) != -1:
answer = answer[answer.find(sons[0].get("text")[-5:]) + 5:]
answer = answer[:answer.find(sons[2].get("text")[:5])]
d.set_clipboard(answer)
time.sleep(1)
d.xpath(
'//*[@resource-id="app"]/android.view.View[2]/android.view.View[1]/android.view.View[1]/android.view.View[2]/android.view.View[2]/android.view.View[1]').click()
time.sleep(1)
d(resourceId="com.huawei.ohos.inputmethod:id/clip_tv_content").click()
time.sleep(1)
if d(text="确定").exists():
d(text="确定").click()
time.sleep(1)
if d(text="答案解析").exists():
time.sleep(1)
print("出现错误")
d(text="").click()
time.sleep(1)
d(text="退出").click()
daydati()
break
except:
return
daydati()
time.sleep(1)
d(text="返回").click()
###################################################################
#双人赛
def twoxontest():
d(text="").click()
while True:
try:
if d(text="继续挑战").exists:
break
if d.xpath('//android.widget.ListView/android.view.View[1]').exists:
d.xpath('//android.widget.ListView/android.view.View[{}]'.format(random.randint(1, 2))).click()
time.sleep(random.random()/3)
except:
break
time.sleep(1)
d(text="").click()
time.sleep(1)
d(text="").click()
time.sleep(1)
d(text="退出").click()
###################################################################
#四人赛
def fourcontest():
d(text="开始比赛").click()
while True:
try:
if d(text="继续挑战").exists:
break
if d.xpath('//android.widget.ListView/android.view.View[1]').exists:
d.xpath('//android.widget.ListView/android.view.View[{}]'.format(random.randint(1, 2))).click()
time.sleep(random.random()/3)
except:
break
time.sleep(1)
d(text="").click()
time.sleep(1)
d(text="").click()
time.sleep(1)
d(text="").click()
###################################################################
#挑战答题
# def tzcontest():
# while True:
# try:
# if d(text="再来一局").exists:
# break
# elif d(text="立即复活").exists:
# d(text="立即复活").click()
# elif d.xpath('//android.widget.ListView/android.view.View[1]').exists:
# d.xpath('//android.widget.ListView/android.view.View[{}]'.format(random.randint(1, 2))).click()
# time.sleep(random.random()/3)
# except:
# break
# time.sleep(1)
# d(text="").click()
# time.sleep(1)
# d(text="").click()
# time.sleep(1)
# d(text="").click()
###################################################################
time.sleep(1)
# for i in range(1,4):
# d.xpath('//*[@resource-id="app"]/android.view.View[1]/android.view.View[3]/android.view.View[8]/android.view.View[{}]'.format(i)).click()
# time.sleep(1)
# if d(text="").exists:
# twoxontest()
# elif d(text="开始比赛").exists:
# fourcontest()
# else:d(text="时事政治").click()
d.xpath(
'//*[@resource-id="app"]/android.view.View[1]/android.view.View[3]/android.view.View[8]/android.view.View[1]').click()
time.sleep(1)
if d(text="").exists:
twoxontest()
elif d(text="开始比赛").exists:
fourcontest()
# else:
# # d(text="时事政治").click()
###################################################################
###################################################################
time.sleep(1)
# d.app_stop("cn.xuexi.android")