-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrashtech_api.py
More file actions
42 lines (32 loc) · 1.17 KB
/
trashtech_api.py
File metadata and controls
42 lines (32 loc) · 1.17 KB
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
#!/usr/bin/env python
import requests
import logging
import json
import base64
class TrashtechApi:
api_base = 'http://trashtech.herokuapp.com/api'
def configuration(self):
url = "%s/device_configurations/1" % self.api_base
logging.info('[INFO] request call: %s' % url)
response = requests.get(url)
json = response.json()
logging.info('[INFO] json response: %s' % json)
return json
def create_status(self, device_reference, complete_file_path, image_created_at):
with open(complete_file_path, "rb") as image_file:
encoded_image = base64.b64encode(image_file.read())
request_json = {
"device_status": {
"image_created_at": image_created_at,
"image_base": "data:image/jpg;base64,%s" % encoded_image,
"device_reference": device_reference,
"container_identifier_number": device_reference,
}
}
# logging.info("[INFO] request json: %s", request_json)
url = "%s/device_statuses/" % (self.api_base)
logging.info("[INFO] request call: %s", url)
response = requests.post(url, json = request_json)
json = response.json()
logging.info('[INFO] json response: %s' % json)
return json