-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceStatusesIntegrationUtil.py
More file actions
41 lines (30 loc) · 1.19 KB
/
DeviceStatusesIntegrationUtil.py
File metadata and controls
41 lines (30 loc) · 1.19 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
from datetime import datetime
import time
import os
import requests
import base64
class TrashtechApi:
api_base = 'http://trashtech.herokuapp.com/api'
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.decode('utf-8'),
"device_reference": device_reference,
"container_identifier_number": device_reference,
}
}
# logging.info("[INFO] request json: %s", request_json)
url = "%s/device_statuses/" % (self.api_base)
response = requests.post(url, json=request_json)
json = response.json()
print(json)
return json
trashtechApi = TrashtechApi()
while True:
dirName = './Resources/P3Tworzywo/'
for filename in os.listdir(dirName):
trashtechApi.create_status("000006", dirName + filename, datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
time.sleep(900)