Build a Website Connectivity Checker in Python
We’re going to create an easy python project to display whether or not an internet site is available or not. We could be making this undertaking using the usage of urllib library and Tkinter library. It is a mediocre-stage project in which we are able to analyze a bit about HTTP codes.
Tkinter: This module is for creating an easy and simple GUI in Python. To install the module Tkinter, use the following command:
pip install tk
Urllib : This module is used while working with URLs. To install the module urllib , use the following command:
pip install urllib
Code Description & Execution
A website connectivity checker is a software that helps us to reveal whether a website is available or not. There are frequent times when we open a url and the web page isn’t to be had. To avoid such problems we can use a website connectivity checker. The consumer simply needs to input the url and it will be checked and availability will be visible. If the url is available “Available” will be displayed else “Not Available” will be displayed.
As written above we need to import the libraries in the program root and make an instance of tk().Now that we have created a window, we can specify some attributes to it. To give a selected size to the window, we use the geometry() technique. We give a name to the window using the name() approach. Now we want to feature a heading to our window. For this we create a label named head the use of the Label() method. Whilst the use of a Label() method, we can specify the textual content, font, historical past color, foreground shade, and so on. To show this Label on the window, we use the percent() method.
Any URL is entered in the access area and is saved inside the variable url. Now we want to make sure that the url variable is String type. StringVar() method lets you control strings and get their cost when wanted. We create a take a look at() feature so that you can perform a url checking for us. Each time the button may be clicked this feature may be evoked.
We create a variable named net. Using the get() method we extract the fee of the url and store the value on the web.
Urllib.Request enables us to use the urlopen so that it will open that url for us. As soon as the url is open we test the status code for that url through the usage of the getcode() approach. We stored this reputation code of the web in a variable status_code.
As we need to test if the website is running or not, we want the source code to be 200. (Fame Code 2 hundred ways ok. It specifies that an internet site is operating). Now we check if status_code is the same as two hundred or no longer. A boolean value ( actual or false ) is stored in a variable website_is_up.
Now the usage of the if-else loop, we test if the website_is_up is authentic then we make a label to display “internet site to be had”. If it’s far fake then we display a label “internet site now not to be had”.
How to Execute?
Note: Make sure you have added path while installing the software’s.
- Install the prerequisites/software’s required to execute the code from reading the above blog which is provided in the link above.
- Press windows key and type in anaconda prompt a terminal opens up.
- Go to the directory where your requirement.txt file is present, not just requirement.txt, if you want to execute any .py or .ipynb files, you need to go to that specific folder or path, where they are saved.
- <<directory of your file:>>. E.g., If my file is in d drive, then.
- Type d:
- cd d:\License-Plate-Recognition-main #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE
7. If your project is in c drive, you can ignore step 4 and go with step 5
8. Run pip install -r requirements.txt or conda install requirements.txt (Requirements.txt is a text file consisting of all the necessary libraries required for executing this python file. If it gives any error while installing libraries, you might need to install them individually.), example: pip install “module_name”.
- We might face an issue while installing specific libraries, in this case, you might need to install the libraires manually. Example: pip install “module_name/library” i.e., pip install pandas
- Make sure you have the latest or specific version of python, since sometimes it might cause version mismatch.