Developer's Notes v1.3.1.1
Feature drop in February? Is it a coincidence? New pages available with lots of cloud Python computing! Maybe a bit artsy as well. Here's the new features:
- - There is a whole new tab called "Quirks." Although there is only one page within it now, I have more planned. You can check them out on project's Github.
- - Poem of the day is out! It works with 2 seperate cloud actions, more on that later.
- - You can also share this poem in many different ways. Copy its link, copy the poem, or download an image. However you like!
- - Added read time information for blog cards. Also created contrast between the description and infos.
- - Improved universalized design system (cool version of "rounded corners everywhere"), fixed minor bugs.



Behinde the scenes
To make "Poem of the day" universal across all devices. I created a cloud-based API that runs on Pythonanywhere with Python. It's a simple API built with flask that generates a random number at 00:00 Istanbul time. You can access the API on this link. It runs on free tier and returns randomNum and poemCount. Poem of the day fetches this data and gets today's poem from the database.
- That was rather easy compared to the download function. To dynamically change the image every day for the selected poem, I coded an image creator with Python's Pillow library. It wasn't the easiest task, I had to learn the library from scratch, but once I got the hang of it, I was able to achieve what I wanted. After pushing my code to Github, I used Github Actions to create an image for today's poem. If you want to check all the code, you can visit its project page, but for now I'll just show some tricky parts you might get stuck on.
# CLEAR poem from "r" if you're using JSONs like I do
def clearPoem():
poem = poemData.translate(str.maketrans('', '', 'r'))
return poem
# get POEM LINE COUNT to decide on height later
poemLineCount = clearPoem().count('n')
# calculate poem TITLE WIDTH and LONGEST LINE WIDTH to dynamically adjust the image's width
pageWidth = 1500
widthOfTitle = fontObjectTitle.getlength(data["items"][poemNum]["title"])
longestLineWidth = fontObjectPoem.getlength(longestLineFinder(poemData))
if(widthOfTitle > 1400):
pageWidth = int(widthOfTitle) + 200
if(longestLineWidth > 1400):
pageWidth = int(longestLineWidth) + 200
# calculate the ideal HEIGHT of overall image with the help of calculating line count of the poem
pageHeight = 150 + poemLineCount*fontObjectPoem.getmask(clearPoem()).getbbox()[3]
# center the poem (can't use "anchor" because poem is multiline) by calculating where it should start in pixels
idealPoemWidth = (pageWidth - longestLineWidth) / 2
# center the title and source while drawing with "anchor"
drawingObject.text((pageWidth/2,75), data["items"][poemNum]["title"], (251,231,209), font=fontObjectTitle, anchor="mt")
- There is more to consider when building such an algorithm, but you can check them on Github if you'd like to. After those, calculating the read times were a breeze. Here's how:
function numOfWords(yourString) {
var numWords = yourString.trim().split(' ').length;
return numWords;
}
// you can adjust the wpm to your liking
let wpm = 240;
let timeToRead = Math.ceil(numOfWords(yourText) / wpm);
- That's it for v1.3.1.1, I hope you enjoyed reading through! If you're curious about more, you can always contact me via email.
- This winter is not cold at all,
Önder.