Release 0.1, playing around with new Libraries

Mohammed Ahmed
3 min readSep 25, 2020

When release 0.1 was… well, released, I it gave me a chance to learn new CLI libraries within Python. I knew of Python’s built-in Argument Parser, but another student (Chris Pinkney, huge shoutouts to you) had recommended a library called Click. This was very interesting, so I decided to use it. However, because I was using dependencies that aren’t within base Python, I had to create a setup.py. I made this for multiple reasons, but my main two were: invoking the script without running Python, and installing missing dependencies(this for for the user). While learning about Click, I found it to be really easy to use, once you understand how it works, and creating the arguments were a breeze, since it’s one function.

My generic function, used to get the status of a link

I have a generic function called ‘test_request’ that will grab the status of the link, and print out the result. I used a try-except because there’s a possibility that the urllib3 object will return an error. I used the library ‘colorama’ to colour my output, so that’s why you see the variable called ‘Fore’.

Reading a file from a disk

The basic file read just strips a line from the file, and calls test_request. The regex finds every link in the file, and stores it in a list. Once we finish that, we iterate through the list and call the test_request. I added an OSError as a just in case, if the file cannot be opened.

My single URL reader function

The single URL function just grabs a URL as an argument, and tests that URL. I pass it as a string to test_request.

The version function… well, check the version.

For the last function I had my Version function. This quite literally print the string “Version 0.1” in blue. Cause after all, this is release 0.1, so I called it version 0.1.

Calling ‘version’
Calling ‘url’ with a YouTube link
calling ‘file’ with ‘test.html’

This was a very fun experience, and I cannot wait for release 0.2!

  • Mo

--

--

Mohammed Ahmed
0 Followers

Transit Enthusiast, and Games Enthusiast