Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Weather-App/README.md
Original file line number Diff line number Diff line change
@@ -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 <city>". 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).
59 changes: 45 additions & 14 deletions Weather-App/weatherapp.py
Original file line number Diff line number Diff line change
@@ -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()