new identifier and added creation folder logic

This commit is contained in:
Manuel Hude 2020-11-30 12:47:32 +01:00
parent e1a1cb25fc
commit 2e58c64ced
3 changed files with 12 additions and 4 deletions

View File

@ -54,7 +54,12 @@ def get_image(identifier):
b64encoded_image = unwrap_file(payload['image_data']) b64encoded_image = unwrap_file(payload['image_data'])
goal_folder_name = "images_fetch" goal_folder_name = "images_fetch"
path = "../../"+goal_folder_name+"/"+payload['metadata']['filename'] 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 = open(path, 'wb')
out.write(b64encoded_image) out.write(b64encoded_image)
out.close() out.close()

View File

@ -16,5 +16,7 @@ class MongoManager:
MongoManager.__instance = pymongo.MongoClient('127.0.0.1', 27017) MongoManager.__instance = pymongo.MongoClient('127.0.0.1', 27017)
db = MongoManager.__instance.AIC db = MongoManager.__instance.AIC
coll = db.metadata coll = db.metadata
coll.create_index("filename",unique=True) db.coll["identifier"]
coll.create_index([("loc", pymongo.GEO2D)]) db.coll["location"]
coll.create_index("identifier",unique=True)
coll.create_index([("location", pymongo.GEO2D)])

View File

@ -55,7 +55,7 @@ class ImageEndpoint:
col = db.metadata col = db.metadata
metadata = None metadata = None
try: try:
resp = col.find({"filename": identifier+".jpg"}) resp = col.find({"identifier": identifier})
metadata = resp[0] metadata = resp[0]
except: except:
print("Could not find Metadata") print("Could not find Metadata")
@ -94,6 +94,7 @@ class ImageEndpoint:
col = db.metadata col = db.metadata
try: try:
metadata['identifier'] = identifier
metadata['location'] = [metadata['longitude'],metadata['latitude']] metadata['location'] = [metadata['longitude'],metadata['latitude']]
col.insert_one(metadata) col.insert_one(metadata)