Skip to content

Commit

Permalink
Format Python script
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Nov 4, 2023
1 parent bb72935 commit 1ea72bf
Show file tree
Hide file tree
Showing 3 changed files with 894 additions and 367 deletions.
10 changes: 7 additions & 3 deletions gcp/social_card_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ def get_image(path: str, query_params: dict, social_cards: dict = {}):
if len(list(image_folder.glob(f"{filename}_with_title.*"))) > 0:
filename = f"{filename}_with_title"
# React builds the image filename as 'original_name.hash.extension'. Find it by searching for the original name

image_files = list(image_folder.glob(f"{filename}.*"))
if len(image_files) > 0:
# In order of preference: file ending with .png, then jpeg, then jpg
for extension in [".png", ".jpeg", ".jpg"]: # Twitter doesn't show the title so we include alternative versions.
for extension in [
".png",
".jpeg",
".jpg",
]: # Twitter doesn't show the title so we include alternative versions.
for image_file in image_files:
if image_file.name.endswith(extension):
return f"https://policyengine.org/static/media/{image_file.name}"
Expand Down Expand Up @@ -115,7 +119,7 @@ def add_social_card_tags(
title = get_title(path, query_params)
description = get_description(path, query_params)
image_url = get_image(path, query_params, social_cards)
print('Image URL:', image_url)
print("Image URL:", image_url)

# Use beautiful soup to add the tags for Twitter and Facebook
soup = BeautifulSoup(html_file, "html.parser")
Expand Down
Loading

0 comments on commit 1ea72bf

Please sign in to comment.