Merge pull request 'Add tagging to replies' (#12) from add-tagging-to-reply into master

Reviewed-on: tyler/Meme-service#12
This commit is contained in:
Tyler Perkins 2023-02-24 21:21:52 +00:00
commit 3d7618516b
2 changed files with 35 additions and 3 deletions

View File

@ -26,15 +26,19 @@ class exactSearch(Resource):
return {
"found" : True,
"url" : "/resource/exact/" + query,
"name" : query
"name" : query,
"tags" : client.getTagsOnMeme(query),
}
else:
return { "found" : False }
@api.route('/close/<string:query>')
@api.route('/<string:query>', doc={
"description" : "Alias for /close/{query}"
})
@api.doc(params={
'query' : 'Search query to attempt to compare against'
},description="FInd a meme thats close using levenshtein distance")
},description="Find a meme thats close using levenshtein distance")
class textualClose(Resource):
def get(self, query):
client = getClientSafely()
@ -48,7 +52,8 @@ class textualClose(Resource):
entry = {
"found" : True,
"url" : "/resource/exact/" + meme,
"name" : meme
"name" : meme,
"tags" : client.getTagsOnMeme(meme),
}
listToReturn.append(entry)
@ -57,3 +62,4 @@ class textualClose(Resource):
"numberOfResults" : len(foundMemes)
}

View File

@ -73,6 +73,7 @@ def getClient():
class Client:
allMemes = set()
memesToMd5 = dict()
memesToTags = dict()
lastCheckedAllMemes = datetime.strptime("2000-01-01 01:01:01", "%Y-%m-%d %H:%M:%S")
client = None
@ -97,6 +98,7 @@ class Client:
self.allMemes.clear()
self.memesToMd5.clear()
self.memesToTags.clear()
for obj in self.client.list_objects(S3_BUCKET):
if not obj.is_dir:
@ -122,3 +124,27 @@ class Client:
else:
raise Exception("Requested meme '" + memeName + "' not found")
return None
def getTagsOnMeme(self, memeName: str):
"""
Returns the S3 Tags object for a given meme
"""
if not isinstance(memeName, str):
raise Exception("paramater memeName is of improper type, expected a str")
if memeName in self.memesToTags:
return self.memesToTags[memeName]
memeSet = self.getCurrentMemeList()
if memeName in memeSet:
reply = self.client.get_object_tags(bucket_name=S3_BUCKET,
object_name=memeName)
self.memesToTags[memeName] = reply
return reply
else:
raise Exception("Requested meme '" + memeName + "' not found")
return None