-
-
Save capjamesg/169abb4798b1847be615312f05ac2194 to your computer and use it in GitHub Desktop.
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
# generate sparklines | |
collections_to_build_sparklines_for = ["posts", "likes", "notes", "bookmarks"] | |
sparklines = "" | |
for c in collections_to_build_sparklines_for: | |
dates = {} | |
for i in range(0, 90): | |
dates[(datetime.datetime.now() - datetime.timedelta(days=i)).strftime("%Y-%m-%d")] = 0 | |
for post in site_config[c]: | |
if c == "posts": | |
date = post["date"].strftime("%Y-%m-%d") | |
else: | |
date = datetime.datetime.strptime(post["full_date"], "%Y-%m-%d %H:%M:%S-00:00").strftime("%Y-%m-%d") | |
if dates.get(date) is not None: | |
dates[date] += 1 | |
values = dates.values() | |
# convert values to list | |
data_points = list(values) | |
data_points.reverse() | |
number_of_posts = len(site_config[c]) | |
sparklines += f""" | |
<p><a href="/{c}/">{number_of_posts} {c.title()}</a> <embed class="light_mode" src="/assets/sparkline.svg?{','.join([str(val) for val in data_points])}" | |
class="sparkline" width=100 height=15 /><embed class="dark_mode" src="/assets/sparkline_dark_mode.svg?{','.join([str(val) for val in data_points])}" | |
class="sparkline" width=100 height=15 /></p>""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much!