My first python script

The title of this post should really be "my first time using a python script," because calling the script my own seems a bit of a stretch.

You see, I don't know the first thing about python. But I had a task I wanted to automate, and I figured there was no time like the present.

So, I asked ChatGPT: "I want to migrate my blog from one platform to another. I have a raw HTML export of all the posts and I need to convert all the files to json. How can I automate this? Walk me through the process step by step."

ChatGPT taught me how to install python, install the libraries I needed, wrote the script, and taught me how to run it in terminal.

I uploaded some representative source files along with an example json file provided by the new host.

Admittedly, this seems like something very simple for anyone who actually knows python. But as someone who's never written a line of code in my life, it seemed like a true miracle.

It only took a couple of attempts for it to work. Amazing.

Then, I got a little greedy

Sure, the script converted the files into json, but it didn't preserve the formatting of the posts. Headers, lists, and inline formatting. That's a bummer. I didn't want to have to go through and add all that back in manually.

A few more prompts to ChatGPT and I now had a second script. It would clean up the dirty and ancient HTML files into something much cleaner that would allow the next script to preserve most of the formatting upon converting the files to json.

It worked! Amazing.

Up to this point, I'd probably spent no more than 30 minutes on this project. I was on track for a regular bedtime.

Then, I got way too greedy

"What else could my script do?" I wondered, drunk on the newfound power over the digital files of my online realm.

Here, it might be helpful to note that my new blogging platform of choice is called Ghost. The way I'd be doing things so far, the script made it so that, to display the formatting of the original posts properly, it used what is called an HTML block within the Ghost editor.

Practically, what that means is that the editing experience looks like the first image below. But I wanted it to look like the second image.

Keep in mind, to the blog visitor, there wouldn't be much of a difference. But it really bothered me knowing that it wasn't "just right." And to be honest, there is a slight difference in how Ghost renders the content inside of the HTML block as opposed to using Ghost's native format (which, as of this writing, is called Lexical).

And this is where things went off the rails. I wanted the script not only to parse the original HTML files and clean them up, but also convert the content into the Ghost json import format AND avoid the use of an html block by converting the content into the native Lexical format.

In other words, I was out of my depth. And I experienced first hand what this redditor describes about so called "vibe coding."

I couldn't say it better myself.

So at this point it was after 3AM. My greed had got the better of me, and I had failed at my ultimate ambition.

So I'll be going through about 165 posts in Ghosts and manually converting them from html blocks to native Lexical. That sounds fancy, but all it takes is a simple copy and paste. 165 times. Boo.

That said, I don't think I'd have copy and pasted 165 blog posts into Ghost by hand. This was a great learning experience in which I had a visceral encounter with the tradeoffs between taking the time to automate a repetitive task instead of just doing it manually.

No regrets.

Member discussion