Created
April 18, 2020 16:58
-
-
Save lancejohnson/40a1bff6526708071608ccad445096f5 to your computer and use it in GitHub Desktop.
A simple file to be sure I can load a file, keep it in memory and use it.
This file contains hidden or 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
import boto3 | |
import csv | |
import io | |
import os | |
from PIL import Image, ImageDraw, ImageFont | |
import pdb | |
def image_test(): | |
def load_file_from_s3(*, bucket, key): | |
s3_client = boto3.client( | |
"s3", | |
aws_access_key_id=AWS_ACCESS_KEY_ID, | |
aws_secret_access_key=AWS_SECRET_ACCESS_KEY, | |
) | |
buffer_file = io.BytesIO() | |
s3_client.download_fileobj(bucket, key, buffer_file) | |
buffer_file.seek(0) | |
return buffer_file | |
AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID", "") | |
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY", "") | |
BUCKET = "giftsondemand-input" | |
slogan_to_write = "Johnson" | |
SLOGAN_TEMPLATE_IMG_KEY = "imgs/mug_template_feminine_its_a_surname_thing.png" | |
slogan_img_template_file = load_file_from_s3( | |
bucket=BUCKET, key=SLOGAN_TEMPLATE_IMG_KEY | |
) | |
template_img = Image.open(slogan_img_template_file) | |
draw = ImageDraw.Draw(template_img) | |
INPUT_BUCKET = "giftsondemand-input" | |
FONT_S3_KEY = "fonts/angelina.ttf" | |
font_file = load_file_from_s3(bucket=INPUT_BUCKET, key=FONT_S3_KEY) | |
font = ImageFont.truetype(font_file, 310) | |
# Find starting x coordinate to center text | |
text_width, text_height = draw.textsize(slogan_to_write, font) | |
img_width, img_height = template_img.size | |
starting_x = (img_width - text_width) / 2 | |
draw.text( | |
xy=(starting_x, 1050), text=slogan_to_write, fill=(88, 89, 91, 255), font=font, | |
) | |
def csv_test(): | |
def load_file_from_s3(*, bucket, key): | |
s3_client = boto3.client( | |
"s3", | |
aws_access_key_id=AWS_ACCESS_KEY_ID, | |
aws_secret_access_key=AWS_SECRET_ACCESS_KEY, | |
) | |
buffer_file = io.BytesIO() | |
s3_client.download_fileobj(bucket, key, buffer_file) | |
buffer_file.seek(0) | |
text_wrapper = io.TextIOWrapper(buffer_file) | |
return text_wrapper | |
AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID", "") | |
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY", "") | |
INPUT_BUCKET = "giftsondemand-input" | |
SLOGANS_CSV_KEY = "input_csv/input.csv" | |
csv_file = load_file_from_s3(bucket=INPUT_BUCKET, key=SLOGANS_CSV_KEY) | |
pdb.set_trace() | |
reader = csv.DictReader(csv_file) | |
slogan_dicts = [row for row in reader] | |
if __name__ == "__main__": | |
csv_test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment