Skip to content

Instantly share code, notes, and snippets.

@russelllim22
Created August 25, 2021 21:56
Show Gist options
  • Save russelllim22/5dfb818028e26442fbd0feeb5bdbc911 to your computer and use it in GitHub Desktop.
Save russelllim22/5dfb818028e26442fbd0feeb5bdbc911 to your computer and use it in GitHub Desktop.
# topic_list = ["Accessibility", "Addiction", "Android Dev", "Artificial Intelligence",...]
# monthly_counts = {"Accessibility": 26, "Addiction": 71, "Android Dev": 132, "Artificial Intelligence": 101, ...}
html_string = ""
heading_list = []
for topic in topic_list:
# In Medium articles, the large headings are <h3> tags
string = "<h3>"+topic+"</h3>"
# I have saved the chart images in the current working directory
string += "<img src='"topic+"-pie.png'/><br>"
string += "<img src='"topic+"-bar.png'/><br>"
html_string += string
heading_list.append([string, monthly_counts[topic], topic])
# Sort the topics in descending order
heading_list.sort(key = lambda x: x[1], reverse=True)
# Use a HTML ordered list element
heading_list_html = "<ol>"
for i in range(len(heading_list)):
heading_list_html += "<li>"+(str(heading_list[i][2]) +" (" + str(math.floor(heading_list[i][1] / 10) * 10) + ")</li>")
# example output: "<li> Accessibility (30+) </li>"
heading_list_html += "</ol>"
html_string = list_topics + "<br><br>" + html_string
with open("index.html", "w") as file:
file.write(html_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment