diff --git a/main.py b/main.py index a47a3cd..4b035f8 100644 --- a/main.py +++ b/main.py @@ -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 diff --git a/static/styles/weather.css b/static/styles/weather.css index 0309df4..b1432aa 100644 --- a/static/styles/weather.css +++ b/static/styles/weather.css @@ -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; diff --git a/templates/weather.html b/templates/weather.html index b94f47d..59987a3 100644 --- a/templates/weather.html +++ b/templates/weather.html @@ -17,7 +17,13 @@

-->
+
+ + +
+
+

{{city}}