-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56112b7
commit 390fe25
Showing
2 changed files
with
22 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters