DEV Community

Cover image for UrlAutomationMachine: Why check status codes when you can get a machine to do it for you
Abdulbasid Guled
Abdulbasid Guled

Posted on

UrlAutomationMachine: Why check status codes when you can get a machine to do it for you

At some point, everything is gonna be automated right? At least we know who to blame if AI suddenly takes over am I right?

Anyway, for our first big release for DPS909, we were tasked with creating a CMD tool that can detect broken URLs. I decided to make mine look very much like a conveyer belt for reasons I will keep to myself. I chose to use python for this since I had did a summer course over the summer in python and I felt more comfortable with the tools the language had to accomplish this task.

Here's a picture showcasing how it should operate:
UrlAutomationMachine Demo

Here's a few options that you can find:

UrlAutomationMachine Options

In terms of the output, it will display as follows:

  • Green indicates success
  • Red indicates failure
  • White/Grey indicates a url that is unknown in nature

This is all based on the status code that is returned. A head request is made each time in order to decrease the amount of time taken making a request as opposed to a get request.

When you download the repo, make sure to run the following:

pip3 install --editable .
Enter fullscreen mode Exit fullscreen mode

This will install all necessary libraries needed to run the application using the file included, of which the following were used:

  • Colorama: This was used to colorize the output on the terminal
  • urlLib3: This was used to make the http request, originally used requests but switched to this library instead out of a recommendation.
  • argparse: This was used to facilitate the cmd tool, setup the arguments and pass the argument needed to the main function
  • re: This was used to create a regex that could be applied to any file. This allowed any file to be passed, knowing that the url would be pulled from the file.

This release 0.1 project was an interesting project and one that has changed throughout the two weeks I've been working on it. I originally had just a main method do everything, but I changed it to operate via a class that was imported to the main function in order to also add in the extra functionality of checking a separate url.

With this, the first of 4 releases for this open source class is now complete. As October comes close, Hacktoberfest looms. Time for me to find a repo to start making commits to. Until next time guys, stay tuned

Discussion (0)