Merge pull request 'add helper functions' (#9) from simplify-markdown-link-create into master

Reviewed-on: #9
This commit is contained in:
Sarah 2022-12-04 14:12:07 +00:00
commit e47d22aa22
2 changed files with 14 additions and 2 deletions

View File

@ -121,10 +121,22 @@ def get_film_list(films):
film_links = [] film_links = []
for film in films: for film in films:
film_link = "[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) film_link = generate_imdb_film_link(film)
film_links.append(film_link) film_links.append(film_link)
if len(film_links) > 0: if len(film_links) > 0:
return "<br>".join(film_links) return "<br>".join(film_links)
else: else:
return "" return ""
def generate_markdown_link(text, url):
return "[{}]({})".format(text, url)
def generate_imdb_film_link(film):
return generate_markdown_link(film['title'], "https://www.imdb.com/title/tt{}/".format(film['imdb_id']))
def generate_wikipedia_page_link(page_title):
return generate_markdown_link(page_title, "https://en.wikipedia.org/wiki/{}".format(page_title.replace(" ", "_")))

View File

@ -29,7 +29,7 @@ def build_page(films_by_reference_keyword):
table += "\n" table += "\n"
row_data = [] row_data = []
row_data.append("[{}](https://en.wikipedia.org/wiki/{})".format(str(string.capwords(year[13:].replace("-", " "))), str(string.capwords(year[13:].replace("-", " ")).replace(" ", "_")))) row_data.append(VCinemaUtils.generate_wikipedia_page_link(string.capwords(year[13:].replace("-", " "))))
row_data.append(VCinemaUtils.get_film_list(reference_keywords_sorted[year])) row_data.append(VCinemaUtils.get_film_list(reference_keywords_sorted[year]))
table += " | ".join(row_data) table += " | ".join(row_data)