From 658f23e17fffbb6b7e47894e8956f7d35642b074 Mon Sep 17 00:00:00 2001 From: ritikjha5700 Date: Tue, 4 Oct 2022 12:07:36 +0530 Subject: [PATCH] Added smart weather info script --- smartWeatherInfo/README.md | 15 +++++++++++++++ smartWeatherInfo/weatherInfo.py | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 smartWeatherInfo/README.md create mode 100644 smartWeatherInfo/weatherInfo.py diff --git a/smartWeatherInfo/README.md b/smartWeatherInfo/README.md new file mode 100644 index 000000000..1ed79139c --- /dev/null +++ b/smartWeatherInfo/README.md @@ -0,0 +1,15 @@ +# Smart weather Information: + +This automation script will send weather information as a desktop notification whenever you opened your pc + +# requirements: + +You need to install these three libraries to get started: + +1. Beautiful Soup +2. ToastNotifier +3. Requests + +# You can install these libraries using the command: + +`pip install requests BeautifulSoup4 win10toast` diff --git a/smartWeatherInfo/weatherInfo.py b/smartWeatherInfo/weatherInfo.py new file mode 100644 index 000000000..488c1e7d2 --- /dev/null +++ b/smartWeatherInfo/weatherInfo.py @@ -0,0 +1,34 @@ +from bs4 import BeautifulSoup +import requests +import time +from win10toast import ToastNotifier + +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} + + +def weather(city): + city = city.replace(" ", "+") + res = requests.get( + f'https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8', headers=headers) + soup = BeautifulSoup(res.text, 'html.parser') + location = soup.select('#wob_loc')[0].getText().strip() + current_time = soup.select('#wob_dts')[0].getText().strip() + info = soup.select('#wob_dc')[0].getText().strip() + weather = soup.select('#wob_tm')[0].getText().strip() + information = f"{location} \n {current_time} \n {info} \n {weather} °C " + + toaster = ToastNotifier() + toaster.show_toast("Weather Information", + f"{information}", + duration=10, + threaded=True) + while toaster.notification_active(): + time.sleep(0.005) + + +# print("enter the city name") +# city=input() +city = "London" +city = city+" weather" +weather(city)