Automatic Reading Course--Five Apps

Keywords: Mobile Android encoding Python

Here are five steps to achieve automatic reading. (android phone only)
I. Connecting Mobile Phones to Computers

First connect the mobile phone to the computer with usb cable, then start menu. cmd opens the console and enters adb devices. The following page will appear:

This is to remember the string. This is the name of your cell phone.

Note: If this internal command does not exist, please turn off the anti-virus software on the mobile phone and the computer. To connect the mobile phone with usb, you should choose to manage the files instead of just charging. Install the mobile phone butler. If the mobile phone Butler can connect the computer to the mobile phone, there will be no problem here.

2. Open appium

The installation of appium has been mentioned in the previous tutorial. If it is not installed, please find "Five Automatic Reading Tutorials - Appium Installation" in the public number.

Open appium directly here. There's a triangular arrow in the upper right corner. Click on this button.

A triangle becomes a square.

Explain that appium started successfully.

III. Running scripts

Copy the following script into the text document and change the suffix name of the file to py

# coding=utf-8
from appium import webdriver
import time
desired_caps = {
                'platformName': 'Android',
                'deviceName': 'G2******304007116',
                'platformVersion': '6.0',
                # apk package name
                'appPackage': 'com.kingnet.fiveline',
                # Launcher activity of apk
                'appActivity': 'com.kingnet.fiveline.ui.welcome.WelcomeActivity',
                'unicodeKeyboard': True,#Sending strings using UNICODE encoding
                'resetKeyboard': True#Hidden keyboard
                }
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
# Get the machine screen size x,y
def getSize():
    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']
    return (x, y)
# Screen slides up
def swipeUp(t):
    l = getSize()
    x1 = int(l[0] * 0.5)  # x coordinates
    y1 = int(l[1] * 0.75)  # Initial y coordinates
    y2 = int(l[1] * 0.25)  # Endpoint y coordinates
    driver.swipe(x1, y1, x1, y2, t)
# Screen slides down
def swipeDown(t):
    l = getSize()
    x1 = int(l[0] * 0.5)  # x coordinates
    y1 = int(l[1] * 0.25)  # Initial y coordinates
    y2 = int(l[1] * 0.75)  # Endpoint y coordinates
    driver.swipe(x1, y1, x1, y2, t)
# Screen slides to the left
def swipLeft(t):
    l = getSize()
    x1 = int(l[0] * 0.75)
    y1 = int(l[1] * 0.5)
    x2 = int(l[0] * 0.05)
    driver.swipe(x1, y1, x2, y1, t)
# Screen slides to the right
def swipRight(t):
    l = getSize()
    x1 = int(l[0] * 0.05)
    y1 = int(l[1] * 0.5)
    x2 = int(l[0] * 0.75)
    driver.swipe(x1, y1, x2, y1, t)
#Element search
def isFind(c):
    if driver.find_elements_by_id("com.kingnet.fiveline:id/mLayoutOperatePraise") == []:
        return  True
    else:
        return False
print("opened")
time.sleep(25)
print("sleep end")
for i in range(21):
    driver.find_elements_by_class_name("android.view.ViewGroup")[0].click()
    print(u"Click on the first content")#If you add U, Chinese will not be scrambled. Otherwise, the printed Chinese will be scrambled.
    time.sleep(10)
    print(u"Wait 10 seconds")
    count = 0
    while(isFind("com.kingnet.fiveline:id/mLayoutOperatePraise")):
        swipeUp(1000)
        time.sleep(2)
        print(u"Wait 2 seconds after the slide")
        count = count+1
        if(count>25):
            break
        print(count)
    time.sleep(8)
    if(count<26):
        driver.find_element_by_id("com.kingnet.fiveline:id/mLayoutOperatePraise").click()
        time.sleep(2)
    driver.find_element_by_id("com.kingnet.fiveline:id/mTextCommentAction").click()
    time.sleep(2)
    searchInputBox = driver.find_element_by_id('com.kingnet.fiveline:id/mEditCommentInput')
    searchInputBox.send_keys(u"Good content.")
    time.sleep(2)
    driver.find_element_by_id("com.kingnet.fiveline:id/mTextCommentAction").click()
    time.sleep(2)
    print(u"Slide down for 5 seconds")
    driver.back()
    print(u"Back to home page")
    time.sleep(2)
    swipeUp(6000)
    print(u"Slide down for 6 seconds")

The deviceName in the script is modified to the string obtained by the adb command at the beginning, as shown in the following figure:

Then we get such a document:

In the folder where the file is located, shift + right mouse button, and then select "Open the command window here" will open the cmd console, enter the command:

python autoReader-wutiao.py

You can automatically open five app s, read news, vote, and comment.

Posted by plutarck on Mon, 28 Jan 2019 03:54:14 -0800