We know weather updates are how much important in our day-to-day life. So, We are introducing the logic and script with some easiest way to understand for everyone. Let’s see a simple Python script to show the live update for Weather information.
Modules Needed
In this script, we are using some libraries
- bs4: Beautiful Soup(bs4) is a Python library for pulling data out of HTML and XML files. To install this module type the below command in the terminal.
pip install bs4
- win10toast: This library helps in creating desktop notifications. To install this module type the below command in the terminal.
pip install win10toast
- requests: This library allows you to send HTTP/1.1 requests extremely easily. To install this module type the below command in the terminal.
pip install requests
Approach :
- Extract data form given URL.
- Scrape the data with the help of requests and Beautiful Soup.
- Convert that data into html code.
- Find the required details and filter them.
- Save the result in the String.
- Pass the result in Notification object.
Let’s execute the script step-by-step :
Step 1: Import all dependence
Python3
import requests from bs4 import BeautifulSoup from win10toast import ToastNotifier |
Step 2: Create an object of ToastNotifier class.
Python3
n = ToastNotifier() |
Step 3: Define a function for getting data from the given url.
Python3
def getdata(url): r = requests.get(url) return r.text |
Step 4: Now pass the URL into the getdata function and Convert that data into HTML code.
Python3
soup = BeautifulSoup(htmldata, 'html.parser') print(soup.prettify()) |
After executing this script you will get raw data like these:

Raw HTML information
Step 5: Find the required details and filter them
Python3
current_temp = soup.find_all("span", class_=" _-_-components-src-organism-CurrentConditions-CurrentConditions--tempValue--MHmYY") chances_rain = soup.find_all("div", class_= "_-_-components-src-organism-CurrentConditions-CurrentConditions--precipValue--2aJSf") temp = (str(current_temp)) temp_rain = str(chances_rain) result = "current_temp " + temp[128:-9] + " in patna bihar" + "\n" +temp_rain[131:-14] |
Step 6: Now pass the result into notifications object.
Python3
n.show_toast("Weather update", result, duration = 10) |
Output :

notification
Complete Code:
Python3
# import required libraries import requests from bs4 import BeautifulSoup from win10toast import ToastNotifier # create an object to ToastNotifier class n = ToastNotifier() # define a function def getdata(url): r = requests.get(url) return r.text soup = BeautifulSoup(htmldata, 'html.parser') current_temp = soup.find_all("span", class_= "_-_-components-src-organism-CurrentConditions-CurrentConditions--tempValue--MHmYY") chances_rain = soup.find_all("div", class_= "_-_-components-src-organism-CurrentConditions-CurrentConditions--precipValue--2aJSf") temp = (str(current_temp)) temp_rain = str(chances_rain) result = "current_temp " + temp[128:-9] + " in patna bihar" + "\n" + temp_rain[131:-14] n.show_toast("live Weather update", result, duration = 10) |
Output:

Live Notification
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Build a GUI Application to Get Live Stock Price using Python
- Build an GUI Application to Get Live Air Quality Information Using Python.
- Application to get live USD/INR rate Using Python
- Get live train status using Python
- Windows 10 Toast Notifications with Python
- Creating a Keras Callback to send notifications on WhatsApp
- Python | Real time weather detection using Tkinter
- Create a Weather app using Flask | Python
- Weather app using Django | Python
- Python Desktop Notifier using Plyer module
- Scrapping Weather prediction Data using Python and BS4
- Create a GUI for Weather Forecast using openweathermap API in Python
- Implementing Weather Forecast using Facade Design Pattern in Python
- Find current weather of any city using OpenWeathermap API in Python
- Desktop Notifier in Python
- Python Desktop News Notifier in 20 lines
- Corona Virus Live Updates for India - Using Python
- Plot Live Graphs using Python Dash and Plotly
- GUI Application for Live Cricket scoreboard Using Python
- Querying Live running status and PNR of trains using Railway API in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

