Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions projects/Fetch HTTP status code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Program to fetch the HTTP status code

This script is used to fetch the status code of any request.

Input:
-> URL of a website or an API

Output:
-> Line 1 : Status code of the response followed by emoji (thumbsup/thumbsdown)
-> Line 2 : Relevant message about the status code.
i.e. If status code corresponds to failure, then reason of failure would be shown in the message field.

## Prerequisites

This program uses and external dependency of "emoji" library to display the emojis in output.
This library can be installed easily by using the following command:
pip install -r requirements.txt

## How to use this script?

-> Install the requirements.
->Type the following command:
python fetch_http_status_code.py
->A message asking URL/API would be displayed : Enter any url of choice and check the output
22 changes: 22 additions & 0 deletions projects/Fetch HTTP status code/fetch_http_status_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#Program to fetch the http status code give the url/api
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
import emoji

#Taking input url from user
requestURL = input("Enter the URL to be invoked: ")

#Gets the response from URL and prints the status code, corresponding emoji and message accordingly
try:
response = urlopen(requestURL)
#In case of success, prints success status code and thumbs_up emoji
print('Status code : ' + str(response.code) + ' ' + emoji.emojize(':thumbs_up:'))
print('Message : ' + 'Request succeeded. Request returned message - ' + response.reason)
except HTTPError as e:
#In case of request failure, prints HTTP error status code and thumbs_down emoji
print('Status : ' + str(e.code) + ' ' + emoji.emojize(':thumbs_down:'))
print('Message : Request failed. Request returned reason - ' + e.reason)
except URLError as e:
#In case of bad URL or connection failure, prints Win Error and thumbs_down emoji
print('Status :', str(e.reason).split(']')[0].replace('[','') + ' ' + emoji.emojize(':thumbs_down:'))
print('Message : '+ str(e.reason).split(']')[1])
1 change: 1 addition & 0 deletions projects/Fetch HTTP status code/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emoji==0.6.0