首先祝大家新年快樂,過年了,允許我水一篇博客。不知道大家都回老家了沒,不過我是沒有回去,晚上喫完年夜飯看到很多人發朋友圈,爲了增進和大家的友誼,於是就想着給大家點個贊,無奈內容太多了,就搞個自動化腳本,原理和前兩天我寫的30行代碼實現螞蟻森林自動偷能量一樣,這裏不再贅述,直接上代碼。
import uiautomator2 as u2
import time
# d = u2.connect()
d = u2.connect("192.168.0.102")
# d.app_start("com.tencent.mm")
# time.sleep(0.3)
# d(text="發現").click()
# time.sleep(0.3)
# d(text="朋友圈").click()
def click():
time.sleep(0.2)
d.xpath("//*[@resource-id='com.tencent.mm:id/kn']").click()
time.sleep(0.2)
if d.xpath("//*[@text='贊']").exists:
time.sleep(0.2)
d(text="贊").click()
time.sleep(0.1)
time.sleep(0.3)
def swipeDown():
a = d.xpath("//*[@resource-id='com.tencent.mm:id/kn']")
y = a.get().bounds
dist = y[3]
if dist < 200:
dist = 220
d.swipe(300, dist, 300, 50, 0.2)
time.sleep(0.1)
while True: # 不會自動停,需要手動停下來
click()
swipeDown()