-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
54 lines (46 loc) · 1.69 KB
/
test.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
import lib.gui_controls as gui_controls
import requests
import base64
import config
import os
class BaiDuApi:
client_id = config.client_id
client_secret = config.client_secret
access_token = ""
def __init__(self):
self.get_token()
def get_token(self):
# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={client_id}&client_secret={client_secret}'
host = host.format(client_id=self.client_id,client_secret=self.client_secret)
response = requests.get(host)
if response:
self.access_token = response.json()["access_token"]
# 通用文字识别(标准版)
def text_1(self):
'''
通用文字识别
'''
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"
# 二进制方式打开图片文件
f = open('image\\奇遇.png', 'rb')
img = base64.b64encode(f.read())
f.close()
params = {"image":img}
request_url = request_url + "?access_token=" + self.access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
print (response.json())
# adb测试
class ADB:
exe_path = "bin\\adb.exe"
def start_server(self):
d = os.popen(self.exe_path+" devices")
print(d.read())
if __name__ == '__main__':
# gui_controls.left_click("image\\kaifuhuodong.png")
# bda = BaiDuApi()
# bda.text_1()
adb = ADB()
adb.start_server()