-
Notifications
You must be signed in to change notification settings - Fork 2
/
study.py
223 lines (189 loc) · 6.95 KB
/
study.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
# coding: utf-8
# In[1]:
from uiautomator import device as driver
import numpy as np
import time
import os
import sys
# In[2]:
Height=1280
Width=720
all_of_list=[]
if os.path.isfile("db.npy"):
all_of_list = np.load ("db.npy").tolist()
all_of_list2=[]
if os.path.isfile("db2.npy"):
all_of_list2 = np.load ("db2.npy").tolist()
# In[3]:
def login():
try:
driver(text="登录").click()
driver.click(0.5*Width, 0.42*Height)
time.sleep(1)
os.system("adb shell am broadcast -a ADB_INPUT_TEXT --es msg '你自己的密码'")
time.sleep(1)
driver(text="登录").click()
time.sleep(2)
except BaseException:
print("已登录")
else:
print('正在登录')
def autoJob(tv,sleep_time,sum=6,click=True):
count_click=0
count=0
drag_str='adb shell input swipe '+str(Width*0.5)+' '+str(Height*0.88)+' '+str(Width*0.5)+' '+str(Height*0.3)
for _ in range(100):
text_lists=driver(className='android.widget.TextView')
try:
for i in range(len(text_lists)):
txt=text_lists[i].text
if len(txt)>11 and txt not in all_of_list and count<sum:
driver(text=txt,className='android.widget.TextView').click()
#分享,收藏,评论
if click and count_click<2:
#分享
time.sleep(4)
driver.click(0.94*Width, 0.975*Height)
time.sleep(2)
driver(text="分享到学习强国").click()
time.sleep(2)
driver.press.back()
#收藏
driver.click(0.84*Width, 0.975*Height)
#评论
time.sleep(1)
driver(text="欢迎发表你的观点").click()
time.sleep(2)
os.system("adb shell am broadcast -a ADB_INPUT_TEXT --es msg '中国加油!全力支持'")
os.system("adb shell input keyevent 66")#不知道为什么输入一个回车,点击发布才有反应
time.sleep(2)
driver(text="发布").click()
time.sleep(1)
driver.click(0.94*Width, 0.864*Height)
count_click=count_click+1
'''
#收藏
time.sleep(3)
driver.click(0.84*Width, 0.975*Height)
time.sleep(1)
driver.click(0.84*Width, 0.975*Height)
#删除发布的评论
time.sleep(2)
driver(text="删除").click()
time.sleep(2)
driver(text="确认").click()
'''
count=count+1
all_of_list.append(txt)
print("正在"+tv+"...",txt)
time.sleep(sleep_time)
driver.press.back()
except BaseException:
print("抛出异常,程序继续执行...")
if count >=sum:
break
os.system(drag_str)
def watch_local():
driver(text='北京').click()
time.sleep(2)
driver(text='北京卫视').click()
print("观看本地频道...")
time.sleep(20)
print("本地频道结束")
driver.press.back()
# In[4]:
#阅读文章,阅读6个文章,每个文章停留130秒
def read_articles():
time.sleep(2)
#切换到要闻界面
driver(text='综合').click()
autoJob(tv="阅读文章",sleep_time=135)
#观看视频,每个视频观看20秒,以及17分钟新闻联盟
def watch_video():
time.sleep(2)
#切换到电视台页面
driver(resourceId="cn.xuexi.android:id/home_bottom_tab_button_contact").click()
driver(text="联播频道").click()
autoJob(tv="观看视频",sleep_time=25,click=False)
driver(text="联播频道").click()
news=None
for v in driver(className='android.widget.TextView'):
if "《新闻联播》" in v.text:
news=v.text
break
driver(text=news).click()
#100天后删除最早一天的记录
text_list=np.array (all_of_list)
if len(text_list)>2500:
text_list = text_list[25:]
#存储已看视频和文章
np.save ('db.npy',text_list)
print("正在观看新闻联播...")
time.sleep(1050)
driver.press.back()
print("观看视频结束.")
# In[5]订阅
def dingyue(sum=2,click=True):
count=0
driver(text='我的').click()
time.sleep(3)
driver(text='订阅').click()
time.sleep(1)
driver(text='添加').click()
time.sleep(1)
drag_str='adb shell input swipe '+str(Width*0.5)+' '+str(Height*0.88)+' '+str(Width*0.5)+' '+str(Height*0.3)
for _ in range(100):
dingyue_lists=driver(className='android.widget.TextView')
try:
for i in range(len(dingyue_lists)):
txt=dingyue_lists[i].text
if len(txt)>11 and txt not in all_of_list2 and count<sum:
driver(text=txt,className='android.widget.TextView').click()
time.sleep(1)
driver(text="订阅").click()
count=count+1
all_of_list2.append(txt)
print("已订阅",txt)
driver.press.back()
except BaseException:
print("抛出异常,程序继续执行...")
driver.press.back()
driver.press.back()
print("都已经订阅了")
break
if count >=sum:
driver.press.back()
driver.press.back()
print("全部完成")
break
os.system(drag_str)
#100天后删除最早一天的记录
dingyue_list=np.array (all_of_list2)
if len(dingyue_list)>2500:
dingyue_list = dingyue_list[25:]
#存储已看视频和文章
np.save ('db2.npy',dingyue_list)
def screenshot():
#driver(text='我的').click()
time.sleep(2)
driver(text='学习积分').click()
# In[6]:
if __name__ == '__main__':
#自动打开学习强国
os.system('adb shell am start cn.xuexi.android/com.alibaba.android.rimet.biz.SplashActivity')
time.sleep(1)
#屏幕高度
Height=driver.info['displayHeight']
Width=driver.info['displayWidth']
#切换adb输入法
os.system('adb shell ime set com.android.adbkeyboard/.AdbIME')
#login()---------------------------需要自动登录请删去# 如果你不需要在两个设备上切换登录 无需打开此功能
watch_local()
read_articles()
watch_video()
dingyue()
screenshot()
#切换回搜狗输入法
#os.system('adb shell ime set com.sohu.inputmethod.sogou.meizu/com.sohu.inputmethod.sogou.SogouIME')
#熄灭屏幕
os.system('adb shell input keyevent 26')