How to build a command line app

Image credit: John Kagga

One of today’s tasks was writing a command line application in Python. When I first looked at the description of the problem I was a bit scared since I had never developed one before. I quickly made some research on how I could develop a command line app in python. I came across many results but two stood out Click and Docopt. I then read a bit about both of them but decided to go with Click.

What I developed

The application I developed enables a user to read news articles from four different sources BBC, Bloomberg, BuzzFeed and Al Jazeera using News API. The user is able to choose a source from which to read the latest news articles.

How I developed the application

I created a Python virtual environment on my computer so the application and its dependencies where isolated from the main Python installation. This is a good practice since different projects or applications require different modules and maybe different python versions.

I then installed Click, the command-line parsing library which enabled me show the News sources and also prompt a user for their input(selection of a News source). Click also enabled me to format the text and style of the News articles that are displayed in the command-line.

In order for me to interact with the News API, I installed the requests Python module which simplifies making API calls to Restful web services. With this module I was able to make request for the latest articles from the API using different news sources as described above.

When I was developing the application, I came across Postman an API tool which enabled me test out the API in a graphical interface before diving into code and also Json View a Google Chrome extension that neatly formats Json within the browser.

The app I developed can be found Here

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.