From 2e58c64cedc9c7501f5088aa26000479a880e42e Mon Sep 17 00:00:00 2001 From: Manuel Hude Date: Mon, 30 Nov 2020 12:47:32 +0100 Subject: [PATCH] new identifier and added creation folder logic --- iotclient/iot_client.py | 7 ++++++- middleware/app_be/views/mongo_db.py | 6 ++++-- middleware/app_be/views/rest_api.py | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/iotclient/iot_client.py b/iotclient/iot_client.py index 29aa747..eba5fce 100644 --- a/iotclient/iot_client.py +++ b/iotclient/iot_client.py @@ -54,7 +54,12 @@ def get_image(identifier): 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 + + goal_folder_path = os.path.sep.join(os.path.abspath(__file__).split(os.path.sep)[:-3]) + os.path.sep + goal_folder_name + + if not os.path.isdir(goal_folder_path): + os.mkdir(goal_folder_path) + out = open(path, 'wb') out.write(b64encoded_image) out.close() diff --git a/middleware/app_be/views/mongo_db.py b/middleware/app_be/views/mongo_db.py index 01a2b4b..3326c1f 100644 --- a/middleware/app_be/views/mongo_db.py +++ b/middleware/app_be/views/mongo_db.py @@ -16,5 +16,7 @@ class MongoManager: MongoManager.__instance = pymongo.MongoClient('127.0.0.1', 27017) db = MongoManager.__instance.AIC coll = db.metadata - coll.create_index("filename",unique=True) - coll.create_index([("loc", pymongo.GEO2D)]) \ No newline at end of file + db.coll["identifier"] + db.coll["location"] + coll.create_index("identifier",unique=True) + coll.create_index([("location", pymongo.GEO2D)]) \ No newline at end of file diff --git a/middleware/app_be/views/rest_api.py b/middleware/app_be/views/rest_api.py index 4378c9b..41616f0 100644 --- a/middleware/app_be/views/rest_api.py +++ b/middleware/app_be/views/rest_api.py @@ -55,7 +55,7 @@ class ImageEndpoint: col = db.metadata metadata = None try: - resp = col.find({"filename": identifier+".jpg"}) + resp = col.find({"identifier": identifier}) metadata = resp[0] except: print("Could not find Metadata") @@ -94,6 +94,7 @@ class ImageEndpoint: col = db.metadata try: + metadata['identifier'] = identifier metadata['location'] = [metadata['longitude'],metadata['latitude']] col.insert_one(metadata)