Photo by Avel Chuklanov on Unsplash
Lessons learnt from my latest side project on how to Import my blog posts from Ghost to Hashnode
Copy and paste can be fun. But for bulk imports, it's no longer fun.
I've been blogging a lot on Ghost for the past 2 to 3 years. I'm currently experimenting with getting additional traffic as a means of helping more people by sharing the lessons and experience that I've gathered in the Software Development world for the past 8+ years.
I'm however lacking on the marketing side as I don't possess such a background. I intend to read more on the subject during the course of next year.
To try to increase my reach, I didn't jump on board on the Dev.to community when it was the talk of the town years ago. I preferred focusing on improving my writing quality and still being productive at work. As such, I can only concentrate on one thing at a time within affecting both qualities.
Moreover, I try sharing what I learn from my day to day job. Recently though, I've been reading more books. As a result. I've got far more ideas on how to show my work and help further people online.
Migrating on Hashnode
I remember Hashnode being still in the early stages a few months or years back. I can't remember exactly. Time goes by so quickly. But the community instantly took off providing numerous quality content and means of making genuine relationships.
Therefore, when I write a new weekly post on my blog, I also copy and paste it into Hashnode depending on my agenda. Ghost has in my opinion a better editor whilst Hashnode has a stricter markdown writing experience. I can't really copy it directly from Ghost to Hashnode without losing structure and images. As a result, I write mostly on my blog.
I recently discovered that I can import blog posts from medium or via a bulk markdown importer into Hashnode. Ghost on the other side, exports in a structured JSON format. So, if I want to import some of my posts on Hashnode, I have to first transform and clean them into the correct file format.
Searching on the Internet, I didn't find a solution for that. Since I'm on my end of year holidays, I can free time to code a bare-bones solution. So far are the lessons I've learnt.
Python
I've not been programming in Python for a few years now apart from basic copying and pasting some scripts. Moreover, my skills as a developer have drastically improved throughout the years of working professionally. I now try to use Test-Driven Development (TDD) and logging to any application I work on.
I've been working on Java and C# for the majority of this year. Therefore coding in Python, which is not a compiled and strong typed language, there are some differences that I've forgotten. I catch myself trying to use const, strong types and even enums when a quick and dirty variable does all the job.
PyCharm
One of the reasons I'm using Python is thanks to the PyCharm Community version. Even though their products are relatively expensive, Jetbrains, in my opinion, have the best IDEs on the market. I've been enjoying coding in Java using IntelliJ idea despite last using it since University.
Ruby is my favourite language thanks to its incredible ease of use and versatility. If there was a community version for it, I would have used it for sure. The only issue seems to be related to developing on Windows machine. I've always encountered blocking problems when working on side projects on Windows using Ruby on Rails.
TDD
Following a TDD approach is initially highly time-consuming. I'm coding different scenarios to make the codes more robust. For example, what happens if the wrong file format is selected or one with zero posts? I imagine I could code the entire script within 2 to 3 hours but having this safety net is far more effective in the long run.
Nonetheless, Python default test library, unittest behaves somewhat strangely to what I'm used to such as fixtures and asserting exceptions. I've spent more than a couple of hours without progressing at all.
Glancing on online documentation, I see PyTest is a better match for me. So if I'm serious with testing, I'll first watch some video tutorials before trying to implement it right off the bat.
Minimum Coding
I'm writing the first iteration just to make it import some of my articles onto Hashnode. If it's worth improving, I can then consider having a UI for importing a JSON file and listing all the various blog posts.
In fact, since I'm using Python I can even consider using data analytics on the way I write. This can help me improve my overall writing and editing skills. The only analytics I've done with Python was listing the words I used most often (excluding stop words).
I can also similarly wrap this script as an API in a web server running Flask or even a full-blown Web Application. I can also list the titles and enable the user to modify the front matter. This might require a database though as I need a way to temporary persist data before updating them as HTTP requests are stateless.
Use of Correct Path functions
If I want my codes to run on different Operating Systems, I need to add the relevant codes. I'm coding this script on Ubuntu 20.04 and have been autocompleting the paths in PyCharm.
This would not most probably work on Windows because Python contrary to Java, is not cross-platform by default.
Overthinking
As a professional Software Developer working on multiple Enterprise projects, I have the tendency of overthinking basic ad hoc scripts or solutions due to my exposure. For example, for this project, I could have used a single python file with all the classes and their respective methods. Instead, I divided them into several folders.
The thing with most languages, libraries and frameworks, is that there are usually several ways of doing the same thing. This, as a result, can be overwhelming as it forces the author to think more about the project design and/or structure. In that regard, I prefer someone else doing the hard work and learning to use their solutions. Ruby on Rails and Django among others do most of the heavy lifting.
As I've written above, not having used Python for some time and not understanding the problem domain (blogging and files) enough - maybe I should not have added tests. But at the same time, they enabled me to think beyond happy paths and prepare before the actual concerns arise. For instance, it's so easy to upload the wrong file or file format.
In terms of logic though, with the vast libraries available in the Python ecosystem, I barely need to go any logical thinking myself. For instance, I want to convert an HTML file to a markdown one, there are multiple choices to select.
Upcoming
I'm thinking of completing the script within the next couple of weeks. If I have some time to spare, I'll consider polishing it a bit, such as making the codes cross-platform and improve the README file.
I'm also thinking about writing a brief technical documentation on how I've implemented the logic. This might be useful for someone still learning Python.
Conclusion
The best thing about learning how to program is you can solve certain issues yourself.