Skip to content

Commit

Permalink
post-lesson updates to get-meme
Browse files Browse the repository at this point in the history
  • Loading branch information
John-J-Riehl committed Aug 5, 2022
1 parent 56112b7 commit 390fe25
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 41 deletions.
61 changes: 21 additions & 40 deletions back-end/get_meme.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 390fe25

Please sign in to comment.