Python 3 Win10Toast Web Scraping Script to Get Live Weather API Desktop Notification Using BeautifulSoup4 Library Full Project For Beginners
Welcome folks today in this blog post we will be scraping live weather desktop notifications
using wintoast
library and beautifulsoup4
library in python. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the following library using the pip
commnad
pip install win10toast
pip install bs4
pip install requests
After installing these libraries make an app.py
file and copy paste the following code
app.py
# 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
htmldata = getdata("https://weather.com/en-IN/weather/today/l/25.59,85.14?par=google&temp=c/")
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)
Now if you execute the python
script by typing the below command as shown below
python app.py
As you can see we have got the live weather update
desktop notification as shown above in patna
bihar