trents_blog/docs/posts/rewrite-hugo-themes-report-in-python.md
2020-12-15 00:17:03 -08:00

34 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Rewrite Hugo Themes Report in Python"
date: 2019-01-25T01:02:57-08:00
draft: false
tags: ["python","sql","sqlalchemy","html5","hugo-themes"]
authors: ["trent"]
---
date: 2019-01-25T01:02:57-08:00
## **Ranking Hugo Themes by Stars, Commit Date**
A while back I was grazing the selfhosted subreddit, and noticed Hugo coming up in conversation.
I recalled that hugo requires a third-party theme in order to function. But was a bit of a challenge,
because how do you know what is a good Hugo theme?
## **First Version in Bash**
I ended up writing a little bash script (now deprecated) that scrapes the Github api and generates a little report about Hugo themes.
It basically curled json from the Github api, and parsed it with grep, awk, and sed, and eventually spat out a plain text file.
## **Rewrite in Python**
It was about a year later that I decided to rewrite the script in Python, using sqlite as a database.
I discovered how to use the python requests module, got some practice with sqlite,
and discovered how to make conditional request against the Github api using ETags and If-Modified-Since (ETags are easier).
But this was my first time using python like this. And I have to tell you,
**its a lot moar fun than recursive fibonacci tutorials!**
## **Building an HTML5 Table (bootstrap, actually)**
By the time I had figured out how to collect the data I needed, I realized that I could simply generate an html table right in the python script.
`rank_hugo_themes.py` runs in a cronjob every night, and you can view
[Hugo Themes Report](https://trentsonlinedocs.xyz/hugo-themes-report/hugo-themes-report.html){target=_blank} here.
And you can [see the script on Github](https://github.com/TrentSPalmer/hugo_themes_report){target=_blank}.