Open Notepad to enter text

This example uses a script to open a notepad on the phone and enter text.

Programming language: Python

Steps

1. Get token

2. Get device object

3. Click on the notepad on the screen

4. Sleep for five seconds

5. Enter 123

Source code

#!/user/bin/python
#-*- coding:utf-8 -*-

import urllib.parse
import urllib
import http.client
import json
import urllib.parse
import base64
import time
from argparse import Namespace


def login(key):
    request_url = "http://localhost:8090/TotalControl/v1/login"
    conn = http.client.HTTPConnection('localhost:8090')
    header = {'Authorization':key}
    conn.request(method="GET", url=request_url, headers=header)
    response = conn.getresponse()
    res = response.readline()
    return res
def getMain(token):
    request_url = "http://localhost:8090/TotalControl/v1/devices/main?token="+token
    conn = http.client.HTTPConnection('localhost:8090')
    # header = {'Authorization': 'c2lnbWE6amllaHVh'}
    conn.request(method="GET", url=request_url)
    response = conn.getresponse()
    res = response.readline()
    resp = json.loads(res)
    main = resp['id']
    return main
def click(deviceId,x,y,token):
    request_url = "http://localhost:8090/TotalControl/v1/devices/" + deviceId + "/screen/inputs"
    conn = http.client.HTTPConnection('localhost:8090')
    body={'x':x,'y':y,'token':token}
    body=json.dumps(body).encode(encoding='utf-8')
    conn.request(method="POST",url=request_url,body=body)
    response = conn.getresponse()
    res = response.readline()
    print(res)
    return res
def inputText(deviceId, token,text):
    request_url = "http://IP:8090/TotalControl/v1/devices/"+ deviceId +"/screen/texts"
    conn = http.client.HTTPConnection('localhost:8090')
    body = {'text':text , 'token': token}
    body = json.dumps(body).encode(encoding='utf-8')
    conn.request(method="POST", url=request_url, body=body)
    response = conn.getresponse()
    res = response.readline()
    print(res)
    return res

encodeStr=base64.b64encode("sigma:jiehua".encode("UTF-8"))
res=login(encodeStr)#Get token
resp = json.loads(res)
token=resp['value']['token']
deviceId=getMain(token)#Get device object
click(deviceId,500,500,token)#Click on the screen 500,500
time.sleep(5)#Sleep for five seconds
inputText(deviceId,token,"123");#Enter 123