diff --git a/Weather-App/README.md b/Weather-App/README.md new file mode 100644 index 0000000000..c64537b396 --- /dev/null +++ b/Weather-App/README.md @@ -0,0 +1,27 @@ +# Weather App + +This is a simple application that allows you to check the temperature of a city using web scraping from Google search results. + +## Prerequisites + +- Python 3.x +- Requests library (`pip install requests`) +- BeautifulSoup library (`pip install beautifulsoup4`) +- Tkinter library (usually included with Python) + +## Usage + +1. Run the `weatherapp.py` script. +2. Enter the name of the city for which you want to check the temperature. +3. Click the "Get Temperature" button. +4. The temperature will be displayed below the button. + +## Notes + +- The application fetches the temperature information by performing a Google search for "weather in ". It then extracts the temperature details from the search results using web scraping techniques. +- The temperature displayed might vary depending on the structure and layout of Google's search results page. +- This application is for educational and demonstration purposes only and is not intended for commercial or production use. + +## License + +This project is licensed under the [MIT License](LICENSE). diff --git a/Weather-App/weatherapp.py b/Weather-App/weatherapp.py index f73c0c9cfa..f4c77e96fe 100644 --- a/Weather-App/weatherapp.py +++ b/Weather-App/weatherapp.py @@ -1,17 +1,48 @@ +# Importing required modules import requests from bs4 import BeautifulSoup +import tkinter as tk -# Taking City You Want to Check Temperaature -city = input("Enter City : ") -# Storing City You Want to Check Temperaature -search = "weather in" + city -# Searching it on google -url = f"https://www.google.com/search?&q={search}" -# Sending and Receiving Requests -r = requests.get(url) -# Scraping Details -s = BeautifulSoup(r.text, "html.parser") -# Storing Details -update = s.find("div", class_="BNeawe").text -# Printing Details -print("Temperature in " + city + " is: " + update) +# Creating function to get temperature +def get_temp(): + # Taking City You Want to Check Temperature + city = city_entry.get() + # Storing City You Want to Check Temperature + search = "weather in" + city + # Searching it on google + url = f"https://www.google.com/search?&q={search}" + # Sending and Receiving Requests + r = requests.get(url) + # Scrape the temperature from the search results + s = BeautifulSoup(r.text, "html.parser") + # Storing details + update = s.find("div", class_="BNeawe").text + # Display the temperature + temperature_label.config(text="Temperature in " + city + " is: " + update) + + +# Creating the main window +root = tk.Tk() +root.geometry('200x200') + +# Creating label for city +city_label = tk.Label(root, text="City: ") + +# Creating entry widget for city +city_entry = tk.Entry(root) + +# Creating button to get temperature +get_temperature_button = tk.Button( + root, text="Get Temperature", command=get_temp) + +# Displaying the temperature +temperature_label = tk.Label(root) + +# Positioning the widgets +city_label.pack() +city_entry.pack() +get_temperature_button.pack() +temperature_label.pack() + +# Starting main loop +root.mainloop()