#coding=utf-8
import Tkinter
import json
import time
import requests
root_url = "http://10.18.2.20:9090/v1"
def postPhoto():
url = root_url + "/visions/photos"
headers = {'Content-Type': 'application/json'}
photo = {
'resolution': '640x480'
}
josn_data = json.dumps(photo)
response = requests.post(url=url, data=josn_data, headers=headers)
# print(response.content)
photo_name = (json.loads(response.content))["data"]["name"]
print(photo_name)
url = root_url + "/visions/photos?body=" + photo_name
response = requests.get(url)
# print(response.content)
img = response.content
with open('./a.jpg', 'wb') as f:
f.write(img)
def stop():
url = root_url + "/motions"
headers = {'Content-Type': 'application/json'}
stop = {"motion":{
"name": ""
},"operation": "stop"}
json_data = json.dumps(stop)
response = requests.put(url=url,data=json_data,headers=headers)
print(response.content)
def bow():
url = root_url + "/motions"
headers = {'Content-Type': 'application/json'}
bow = {"motion": {
"name": "bow",
# "direction": "",
"repeat": 1,
"speed": "very slow"
},"operation": "start"}
json_data = json.dumps(bow)
response = requests.put(url=url, data=json_data, headers=headers)
print(response.content)
time.sleep(5)
stop()
def gui():
top = Tkinter.Tk()
top.geometry('360x160')
A = Tkinter.Button(top,text="鞠躬",command=bow)
B = Tkinter.Button(top,text="拍照",command=postPhoto)
A.pack()
B.pack()
top.mainloop()
gui()