Skip to content

Commit 2187b62

Browse files
Merge pull request avinashkranjan#1660 from subhradip-bo/subhradip_branch
Added GUI and Readme file
2 parents dc3b3c0 + 8af36ab commit 2187b62

File tree

2 files changed

+72
-14
lines changed

2 files changed

+72
-14
lines changed

Weather-App/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Weather App
2+
3+
This is a simple application that allows you to check the temperature of a city using web scraping from Google search results.
4+
5+
## Prerequisites
6+
7+
- Python 3.x
8+
- Requests library (`pip install requests`)
9+
- BeautifulSoup library (`pip install beautifulsoup4`)
10+
- Tkinter library (usually included with Python)
11+
12+
## Usage
13+
14+
1. Run the `weatherapp.py` script.
15+
2. Enter the name of the city for which you want to check the temperature.
16+
3. Click the "Get Temperature" button.
17+
4. The temperature will be displayed below the button.
18+
19+
## Notes
20+
21+
- 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.
22+
- The temperature displayed might vary depending on the structure and layout of Google's search results page.
23+
- This application is for educational and demonstration purposes only and is not intended for commercial or production use.
24+
25+
## License
26+
27+
This project is licensed under the [MIT License](LICENSE).

Weather-App/weatherapp.py

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
1+
# Importing required modules
12
import requests
23
from bs4 import BeautifulSoup
4+
import tkinter as tk
35

4-
# Taking City You Want to Check Temperaature
5-
city = input("Enter City : ")
6-
# Storing City You Want to Check Temperaature
7-
search = "weather in" + city
8-
# Searching it on google
9-
url = f"https://www.google.com/search?&q={search}"
10-
# Sending and Receiving Requests
11-
r = requests.get(url)
12-
# Scraping Details
13-
s = BeautifulSoup(r.text, "html.parser")
14-
# Storing Details
15-
update = s.find("div", class_="BNeawe").text
16-
# Printing Details
17-
print("Temperature in " + city + " is: " + update)
6+
# Creating function to get temperature
7+
def get_temp():
8+
# Taking City You Want to Check Temperature
9+
city = city_entry.get()
10+
# Storing City You Want to Check Temperature
11+
search = "weather in" + city
12+
# Searching it on google
13+
url = f"https://www.google.com/search?&q={search}"
14+
# Sending and Receiving Requests
15+
r = requests.get(url)
16+
# Scrape the temperature from the search results
17+
s = BeautifulSoup(r.text, "html.parser")
18+
# Storing details
19+
update = s.find("div", class_="BNeawe").text
20+
# Display the temperature
21+
temperature_label.config(text="Temperature in " + city + " is: " + update)
22+
23+
24+
# Creating the main window
25+
root = tk.Tk()
26+
root.geometry('200x200')
27+
28+
# Creating label for city
29+
city_label = tk.Label(root, text="City: ")
30+
31+
# Creating entry widget for city
32+
city_entry = tk.Entry(root)
33+
34+
# Creating button to get temperature
35+
get_temperature_button = tk.Button(
36+
root, text="Get Temperature", command=get_temp)
37+
38+
# Displaying the temperature
39+
temperature_label = tk.Label(root)
40+
41+
# Positioning the widgets
42+
city_label.pack()
43+
city_entry.pack()
44+
get_temperature_button.pack()
45+
temperature_label.pack()
46+
47+
# Starting main loop
48+
root.mainloop()

0 commit comments

Comments
 (0)