complete basic uploading
This commit is contained in:
parent
9ad81399cb
commit
6dcf4b43b8
26
src/memes.py
26
src/memes.py
@ -82,12 +82,12 @@ def getClient():
|
||||
# Helper methods
|
||||
# Methods to break up the calldict methods
|
||||
|
||||
def getCurrentMemeList():
|
||||
def getCurrentMemeList(force=False):
|
||||
global last_checked_all_memes
|
||||
global all_memes
|
||||
now = datetime.now()
|
||||
# if no update in the past 5 mins
|
||||
if (now - last_checked_all_memes).seconds > 300:
|
||||
if (now - last_checked_all_memes).seconds > 300 or force:
|
||||
print("Enough time has elapsed, refreshing meme cache...")
|
||||
last_checked_all_memes = now
|
||||
all_memes.clear()
|
||||
@ -266,18 +266,30 @@ async def uploadMeme(command, message, client):
|
||||
if len(message.attachments) <= 0:
|
||||
return "You didn't attach anything! Please attach a file to upload"
|
||||
|
||||
tags = Tags.new_object_tags()
|
||||
tags["uploader"] = message.author.name
|
||||
print(tags)
|
||||
uploader_tags = Tags.new_object_tags()
|
||||
uploader_tags["uploader"] = message.author.name
|
||||
print(uploader_tags)
|
||||
|
||||
all_memes = getCurrentMemeList()
|
||||
client = getClient()
|
||||
file_names = []
|
||||
|
||||
for file in message.attachments:
|
||||
if file.filename in all_memes:
|
||||
return "File with name " + file.filename + " already exists!"
|
||||
return "File with name '" + file.filename + "' already exists!"
|
||||
#TODO check for file hash
|
||||
|
||||
await file.save("/tmp/" + file.filename)
|
||||
|
||||
#upload the file to S3
|
||||
client.fput_object(bucket_name=S3_BUCKET,
|
||||
object_name=file.filename,
|
||||
file_path="/tmp/" + file.filename,
|
||||
tags=uploader_tags,
|
||||
content_type=None)
|
||||
|
||||
return "not implemented dickhead"
|
||||
os.remove("/tmp/" + file.filename)
|
||||
|
||||
getCurrentMemeList(force=True)
|
||||
|
||||
return "Thanks got your memes!"
|
||||
|
Loading…
Reference in New Issue
Block a user