-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhuitoutiao-read2.py
98 lines (83 loc) · 2.18 KB
/
huitoutiao-read2.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
# coding:utf-8
# from uiautomator2 import device as d
import uiautomator2 as u2
import random
import time
import datetime
# 加关注,容易出现在文章列表
news = [
"光明网",
"新华社",
"中国青年网",
"看看新闻",
"娱小白",
"环球网",
"花影故事",
"环京津",
"新华社",
"中国经济网",
"吃货做美食",
""
]
# 点亮屏幕
def light_screen():
d.screen.on()
# 自动阅读
def auto_read():
# 随机滚动距离
d.swipe(500, 100 * random.uniform(5, 10), 500, 100)
# if d(text='展开全文').exists:
# d(text='展开全文').click()
# 随机停止 0-4 秒
time.sleep(random.uniform(1, 3))
# 寻找新文章
def click_new():
while 1:
# 滑动寻找指定文章
d.swipe(500, 1800, 500, 100)
# random.shuffle(news)
for new in news:
print('寻找' + new)
if d(text=new).exists:
d(text=new).click()
print('找到' + new)
time.sleep(2)
return
print('寻找失败, 继续')
time.sleep(3)
# 开始阅读
def start_read():
print("寻找新文章")
click_new()
# 开始阅读
print("开始自动阅读阅读")
while True:
auto_read()
if d(text='没有更多了').exists:
d.press("back")
# 滚动一次,否则一次阅读到同一文章
time.sleep(1)
d.swipe(500, 1500, 500, 100)
break
# 重新阅读
start_read()
# 执行5小时
d = u2.connect()
if __name__ == '__main__':
print("点亮屏幕")
# light_screen()
# 获取当前时间
startTime = datetime.datetime.now()
while 1:
now_time = datetime.datetime.now()
mkt_last = time.mktime(startTime.timetuple())
mkt_now = time.mktime(now_time.timetuple())
post_time = (mkt_now - mkt_last) / 60 # 转成分钟
# 1小时 === 60分钟
left_time = 60 - post_time
if left_time > 0:
print("剩余" + str(int(left_time)) + '分钟')
start_read()
else:
print("自动读书完毕")
break