Added dropbox api support as service and cleaned up get single call

This commit is contained in:
Martin Schett
2020-11-29 21:48:21 +01:00
parent 24a139e8c8
commit 63175ce112
6 changed files with 123 additions and 17 deletions
+13 -1
View File
@@ -8,6 +8,8 @@ from datetime import datetime
def print_response(response):
print("Code: " + str(response.status_code) + "; Body: " + str(response.json()))
def unwrap_file(file_str: str) -> bytes:
return base64.b64decode(file_str)
def send_image(identifier, image_path, metadata_payload):
print("Sending image with identifier " + identifier)
@@ -46,7 +48,17 @@ def get_image(identifier):
try:
response = requests.get(baseurl + get_url)
print_response(response)
payload = response.json()
print(payload['id'])
print(payload['metadata'])
b64encoded_image = unwrap_file(payload['image_data'])
goal_folder_name = "images_fetch"
path = "../../"+goal_folder_name+"/"+payload['metadata']['filename']
goal_folder_path = os.path.sep.join(os.path.abspath(__file__).split(os.path.sep)[:-3]) + os.path.sep + goal_folder_name
out = open(path, 'wb')
out.write(b64encoded_image)
out.close()
os.system(goal_folder_path + os.path.sep + payload['metadata']['filename'])
except os.error:
print("Error sending request")
return True