Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2 Added Search Functionality #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
47 changes: 32 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,41 @@ def login():

@app.route("/weather")
def weather():
# weather json
lat = 26.14
lon = 91.73
API_key = '22538e054719782037738ce38f8fac32'
wthr_json = requests.get(f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API_key}&units=metric")
wthr_json_str = wthr_json.text
wthr = json.loads(wthr_json_str)
city = request.args.get('city')
if(city):
wthr_json = requests.get(f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_key}&units=metric")
wthr_json_str = wthr_json.text
wthr = json.loads(wthr_json_str)
# weather json
else:
lat = 26.14
lon = 91.73
wthr_json = requests.get(f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API_key}&units=metric")
wthr_json_str = wthr_json.text
wthr = json.loads(wthr_json_str)

# present
city = wthr['name']
country = wthr['sys']['country']
cloudiness = wthr['clouds']['all']
temp_present = wthr['main']['temp']
temp_min = wthr['main']['temp_min']
temp_max = wthr['main']['temp_max']
humidity = wthr['main']['humidity']
wthr_main = wthr['weather'][0]['main']
wind_speed = wthr['wind']['speed']
if(wthr['cod'] == '404'):
city = '404 not found'
country = 'Not Found'
cloudiness = ''
temp_present = ''
temp_min = ''
temp_max = ''
humidity = ''
wthr_main = ''
wind_speed = ''
else :
city = wthr['name']
country = wthr['sys']['country']
cloudiness = wthr['clouds']['all']
temp_present = wthr['main']['temp']
temp_min = wthr['main']['temp_min']
temp_max = wthr['main']['temp_max']
humidity = wthr['main']['humidity']
wthr_main = wthr['weather'][0]['main']
wind_speed = wthr['wind']['speed']
print(wthr_json_str)

# forcast
Expand Down
30 changes: 30 additions & 0 deletions static/styles/weather.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ body{
background: #B9FFF2;
}

#current{
position: relative;
top: 100px;
display: flex;
justify-content: center;
}

#current input{
padding: 14px;
width: 300px;
margin: 0px;
border-top-left-radius: 16px;
border-bottom-left-radius: 16px;
border: 0px;
background: #F3FEFE;
margin-bottom: 0px;
margin-right: 0px;
}

#current button{
text-align: center;
width: 60px;
padding: 14px;
border-top-right-radius: 16px;
border-bottom-right-radius: 16px;
border: 0px;
background: #a6a9a7;
margin-top: 0px;
}

.wthr_box{
width: 70%;
background: #1cf38b84;
Expand Down
6 changes: 6 additions & 0 deletions templates/weather.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ <h2></h2> -->

<div class="body">
<link rel="stylesheet" href="../static/styles/weather.css">
<form action="/weather" method="get" id="current">
<input placeholder="Find weather by city name" name="city">
<button type="submit">Search</button>
</form>

<div class="wthr_box">

<img src="../static/images/home_logo.jpg" class="icons" id="home_logo" alt="">
<h1 class="city">{{city}}</h1>
<img src="../static/images/weather.jpg" id="weather_clip" alt="">
Expand Down