How I use python to get the top tech articles on my phone and how you can too!

When you are working in tech, it's very important to be updated with the latest articles in tech. With a plethora of resources, newsletters, and websites out there, it often becomes confusing and overwhelming. While there are a lot of websites that will deliver the top tech news and articles directly to my email, I find that actually making an effort to read them is challenging. I often get distracted with the task at hand and forget to read the articles. In order to overcome this issue, I turned to my friend Python.

Using a very simple python script, I get the top tech articles from my favorite resource saved to my phone on the pocket app, which I can read at my leisure time. I usually use my evening tea breaks to get through those articles.

Let's see how I did it.

Requirements

  • Windows OS
  • Python 3
  • Python libraries: requests, bs4
  • Pocket App account. Create one here
  • Pocket app on your phone
  • Your favorite resource(s) for tech articles. I have used Hacker News in this post.

Why I chose Pocket

Pocket is a very user-friendly app with a clean UI, and the app has worked perfectly on my Android phone, without major glitches. There are other apps like Instapaper which can also be used. In this post, we will use Pocket as an example.

Let's get started

After you have installed Python 3 (pip is automatically included with Python 3) on your system, install request and bs4 packages using the following commands:

pip install requests
pip install bs4

Once installed, download the source code from here

I am not going to explain how to scrape websites or use the requests package to make API calls, as the internet is filled with thousands of resources. You can learn it using Google/YouTube. Once you download the source code, place it in a directory you will not alter frequently. The source code has two properties files - config and pocket. We shall discuss these files, and how you can edit them to your liking.

Hacker Noon Configuration

The file looks like this:

[HACKERNEWS]
url = https://news.ycombinator.com/news?p=
max.items = 5
min.votes = 500
max.pages = 5

You can configure the max articles you want to save using the max.items property. I believe five articles per day is good enough for me, but you can modify it according to your choice. The max.pages property defines how many pages you want the python script to scrape. The first 5 pages work out for me.

Lastly, I use a property called min.votes. Hacker News has a feature where readers can upvote an article if they liked it. Really good articles usually have a minimum of 100 upvotes, so I went with 100. The scrapper will sort the articles in descending order according to the upvotes, so only the best articles get saved to your phone.

Pocket Configuration

This file is used to set your access token for your pocket app. You can read about getting the consumer key and access token using the Pocket Developer API here

Once you have the keys, set it in the appropriate fields in the pocket properties file. Run the save_to_pocket python file to make sure everything is working fine.

Automating The Process

Now that your python code is up and running, it's time to automate the process. The entire exercise is wasted if there's no automation and you have to manually run the python file every day. In order to automate the process, you need to create a batch file. Here's how your batch file will look like:

"Path-To-Python-Installation.exe" "Path-To-The-Python-File.py"
pause

You can create a bat file using notepad. Make sure to save the file using a .bat extension. Now let's schedule the task to automate it.

In the search bar, search for Task Scheduler and open it. Select the 'Create Basic Task' option. You can choose a name and description for your task. Click on Next to move to the Trigger section. You can schedule your task based on a trigger. I personally chose to run the batch file daily at 11 am, as my team meets for daily standups at that time, so the script can run in the background.

In the Actions tab, select the 'Start a program' option. Browse and select the path to the batch file you created earlier. Select the 'Finish' option to save your task.

In order to make sure that the batch file runs in the background, edit the scheduled task and change the user group, and add 'SYSTEM' to the text field and save the changes.

Voila!

Congratulations, you have completed all the steps. Now the top tech articles will be saved to the Pocket app on your phone daily!

Thanks for reading, and please feel free to reach out to me in case you need any help.

No Comments Yet