From 390fe25f81235c8a7c3b1717d77236756a7c6bdf Mon Sep 17 00:00:00 2001 From: John Riehl Date: Fri, 5 Aug 2022 13:19:08 -0400 Subject: [PATCH] post-lesson updates to get-meme --- back-end/get_meme.py | 61 +++++++++++++++----------------------------- client/src/App.js | 2 +- 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/back-end/get_meme.py b/back-end/get_meme.py index 6151ef8..a4e2d09 100644 --- a/back-end/get_meme.py +++ b/back-end/get_meme.py @@ -1,51 +1,32 @@ import json -import boto3 import base64 import io import time from PIL import Image +### include missing imports here def lambda_handler(event, context): - # the meme id is in path parameters + ### get the meme id from path parameters meme_id = - # get entry from the database - dynamodb = - memes_table = - - db_entry = memes_table. - - try: - entry = - except : - # return an error code if the meme's not in the database - - # now get the meme from S3 - s3 = - bucket = - meme = - - # test to see if the meme file exists - - # create an in memory file and download the image data into it - in_mem_file = io.BytesIO() - meme. - - # load the meme as an image to get its type - image = Image.open(in_mem_file) - - # get the list of likes for this meme - likes_table = - db_likes = likes_table. - - # extract the user names into a list - likes = [item["userName"] for item in db_likes["Items"]] - - # return success code and the meme - return { - "statusCode": 200, - "body": json.dumps({ + ### get entry from the database + + ### return an error code if the meme's not in the database + + # create an in-memory file + with io.BytesIO() as in_mem_file: + ### download the image data into the in-memory file. return + ### an error code if the object doesn't exist + + # load the meme as an image to get its type + image = Image.open(in_mem_file) + + time_now = int(time.time()) + + ### build the object to return + meme_data = { "imageUrl": (f"data:image/{image.format};base64," + base64.b64encode(in_mem_file.getvalue()).decode("utf-8")), - }) - } + } + + ### return success code and meme_data diff --git a/client/src/App.js b/client/src/App.js index d6fadf6..0126de2 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -282,7 +282,7 @@ const App = () => { const dateString = (epoch) => { const date = new Date(epoch * 1000); - return `${date.toDateString()} ${date.getHours()}:${date.getMinutes()}`; + return `${date.toDateString()} ${date.getHours()}:${date.getMinutes().toString().padStart(2, "0")}`; }; const ttlString = (timeSeconds) => {