Add tagging
This commit is contained in:
parent
3bb70938ca
commit
f6f4319bf4
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user