A simple way to export your medium’s reading list to a markdown file

A simple way to export your medium’s reading list to a markdown file

Play all audios:

Loading...

IN A FEW LINES OF PYTHON CODE I have been using Medium regularly since 2018 and I have to admit that I bookmark quite a lot of articles. Given the platform’s and its key publications’


impressive growth in the last years, there is just tons of great articles to read. I often see something that piques my curiosity in one of the email newsletters I receive, on Twitter,


LinkedIn, etc. Most of the time, such an article goes straight to backlog before I can find some time to sit down and read a few of those. To put a number to my article hoarding habit, my


current backlog contains ~3.8k saved articles. While I know that it is impossible for me to read them all in the future, I would still like to have them as a point of reference and be able


to search for some articles my past self found relevant. Recently, Medium introduced a new feature — _Lists. _Now we can create a custom list and save the articles organised by some theme.


All the previously created bookmarks were automatically converted into the default reading list. While I really like this addition, there is one key feature that is currently missing — the


search option. I contacted Medium’s support and they told me they are working on bringing search back to the lists, so I do expect it will happen soon. However, I wanted to search for some


articles in my backlog, so I figured out that exporting them to a Markdown file seems like a nice exercise and there is no harm in having a backup stored locally or in the cloud. I chose


Markdown as I can directly use that file with Bear, which I currently use as my knowledge base. If you are interested, I described how Bear improves my productivity in one of my past


articles. In this article, I will show you how to easily export your Medium’s reading list and store it in a Markdown file. PYTHON IMPLEMENTATION Thanks to some handy libraries, the coding


part is very easy. Before we start, we need to get the data. GETTING THE DATA FROM MEDIUM My initial approach was to scrape the data directly from the reading list. However, it turns out


that there is no need for that. We can easily request our data. To do so, we just need to go to the _Settings_ and find the _download your information button_ under the _Account_ header.


Then, we just wait for an email with a link to the .zip file. Once we get the .zip file with all our data, we can find quite a lot of useful information there. To find our saved articles we


need to look into the bookmarks directory. For me, the directory contained 39 HTML files, each with a chunk of all the 3.8k articles saved in the reading list. Now we are ready to combine


the data into a single Markdown file. SETUP To get it done, we only need to import two libraries. CONVERTING HTML TO MARKDOWN The first step is to get all the paths to the HTML files


containing the bookmarked articles. We can get a list of all the files of a certain type in a particular directory using the glob library. What returns the following list:


[‘../data/bookmarks/bookmarks-0001.html’, ‘../data/bookmarks/bookmarks-0002.html’, ‘../data/bookmarks/bookmarks-0003.html’] For this article, I restricted the list to the first 3 files, but


the same code works for any number of files. Then, we iterate over the list of HTML files, open each one of them, convert it to Markdown using the markdownify function and append it to a


list combining all the contents of the files. markdownify outputs a string that we could simply copy/paste into a Markdown file, however, we will do it automatically in one go for all the


files. While appending to the list, we also split the string by ###, which is the first header of the file. Then, we take all that comes after it. The discarded text before the header


contains some meta-data about fonts, etc. We definitely do not need that in our final file. SAVING THE RESULTS In the very last step, we combine all the strings together using the join


method. As a result, all sub-strings are separated by a new line. Then, we simply save the string to a Markdown file. Below you can see a preview of how the file looks in VS Code. WRAP-UP In


this article, we explored how to export Medium’s reading list to a Markdown file. The code is very simple and you can use any other type of file for storing the data. In the future, I would


like to run some kind of analysis on top of my bookmarked articles. Who knows what patterns can be discovered there! You can find the code used for this article on my GitHub. Also, any


constructive feedback is welcome. You can reach out to me on Twitter or in the comments. If you liked this article, you might also be interested in one of the following: ONE SIMPLE TIP TO


MAKE YOUR READMES STAND OUT TAKE YOUR DOCUMENTATION TO THE NEXT LEVEL WITH CHARTS DESIGNED USING MERMAID — A MARKDOWN-LIKE SCRIPT! towardsdatascience.com 9 USEFUL PANDAS METHODS YOU MIGHT


HAVE NOT HEARD ABOUT THEY CAN MAKE YOUR DAILY WORK EASIER AND FASTER. towardsdatascience.com EMBED YOUR INTERACTIVE VISUALIZATIONS IN MEDIUM POSTS USING DATAPANE towardsdatascience.com