From 1ba32879e463c237f1177e59621db90647e409d3 Mon Sep 17 00:00:00 2001 From: AnishKr91620 <145275076+AnishKr91620@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:25:48 +0530 Subject: [PATCH] Create get-live-weather-desktop-notifications-using-python MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- ...weather-desktop-notifications-using-python | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 get-live-weather-desktop-notifications-using-python diff --git a/get-live-weather-desktop-notifications-using-python b/get-live-weather-desktop-notifications-using-python new file mode 100644 index 00000000..cf9fbfc4 --- /dev/null +++ b/get-live-weather-desktop-notifications-using-python @@ -0,0 +1,28 @@ +# 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)