Alex Johnstone

Daily Notes ☕️

Monday, 6th December, 2021

⏱ 4 mins 👓 833 words. 🏷️ Daily Notes

I want to put in my old drummer posts into this site. So I’ve used pandoc to convert my opml file into a single markdown file. This was very easy pandoc --from=opml --to=markdown_mmd blog.opml -o blog.md. However, that makes it one big file, not individual pages. I don’t have that many posts, but I don’t really want to make a whole load of files to copy and paste this info into. I’ve also noticed images aren’t referenced or showing up. What might be a better way to generate the markdown would be from the rendered HTML, that way images and everything exactly how it shows will be created. If I’m making pages then I may be better off making my own converter, reading the opml and making pages. However, this’ll just be a one off thing, so not super excited to put a lot of time into this. Maybe just generating the pages might be a start with published=false and then I can pick away it at over time.

Even though it’s much slower, I decided I’d make the individual posts and then move the content across. Part of the reasoning was that I wanted to edit the posts, as there’s a lot of cruft from drummer config which I don’t need anymore and given the one off nature of this exercise I didn’t want to spend my time writing the content conversion which pandoc has so nicely done for me.

Here’s my code to create individual files named yyyy-mm-dd-weekday.md with the frontmatter set to my style and published: false so I can add them to the repo now and then update over time.

import pathlib
from datetime import datetime
from xml.etree import ElementTree

def process_date(date):
    """
    Converts opml created date into python datetime object
    """
    datetime_object = datetime.strptime(date, '%a, %d %b %Y %H:%M:%S %Z')
    return datetime_object


def create_front_matter(date_object):
    """
    Creates the front matter in my notes from a date. 
    Format:
        ---
        title: Monday, 6th December, 2021
        date: 2021-12-06 00:00
        ---
    """

    # https://stackoverflow.com/a/66364403/2000527
    n = date_object.day
    ordindal = f"{n:d}{'tsnrhtdd'[(n//10%10!=1)*(n%10<4)*n%10::4]}"

    title = date_object.strftime(f'%A, {ordindal} %B, %Y')
    date = date_object.strftime("%Y-%m-%d %H:%M:%S")

    return (
        '---\n'
        f'title: {title}\n'
        f'date: {date}\n'
        'published: false\n'
        '---\n'
    )


with open('blog.opml', 'rt', encoding='utf-8') as f:
    tree = ElementTree.parse(f)

for node in tree.findall('.//outline'):
    type = node.attrib.get('type')
    name = node.attrib.get('name')
    date = node.attrib.get('created')
    if name and type != "calendarMonth":
        datetime_object = datetime.strptime(date, '%a, %d %b %Y %H:%M:%S %Z')
               
        # create file with name YYYY-MM-DD-day.md
        filename = datetime_object.strftime("%Y-%m-%d-%A").lower() + '.md'
        file = pathlib.Path.cwd() / 'posts' / filename
        # Add front matter contents
        file.write_text(create_front_matter(process_date(date)))

Poking about on Phil’s wiki, I came back to the journal/thoughts journal on Derek Sivers site. I had two thoughts - one: I like tiddlywiki, and if the situation was reverse I’d never find that info on this new site👀. Two: Should I be using DayOne for personal journal? Although it’s not really a personal journal, more like a family log. So actually I think that’s fine, it’s meant to ultimately end up as a printed book, and the convenience of DayOne and all it does helps that.

Interestingly my private tiddlywiki was setup around the 30th December 2020. I’ve generated a single page html of it, and I’m going to nuke it and start again! Seems like an annual occurance. However, I installed or setup too many plugins that I don’t want and want to start a fresh. I’ll import stuff into it but easier than trying to edit the existing one.