Python Forum
[Flask]Weather app Updatet
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Flask]Weather app Updatet
This will be and updated version as the old weather API i did use no longer is online.
Will be looking at using a weather API to get data,then make user interface (UI) for those data in Flask.
  • Update 24-jun 2018
  • Python 3.6.5
  • Flask 1.0.2
  • OpenWeatherMap API
The look:
[Image: hTD3jV.jpg]
[Image: W75EKV.jpg]

First gone look at API without Flask.
If go to OpenWeatherMap can get a API key for free.
Using Requests to get JSON data needed:
import requests

# Call example

api_key = 'xxxxxxxxxxxxxxx'
city = 'london'
celsius = 'metric'
url = f'{city}&units={celsius}&APPID={api_key}'
response = requests.get(url).json()

# City

# Temp

# Description

# Wind
London 22.89 clear sky 3.6

Code is here weather-app
If look at server side and
So this will be using jinja and pass values to weather.html.
        city = response['name']
        temp = response['main']['temp']
        description = response['weather'][0]['description']
        wind = response['wind']['speed']
    except KeyError:
        return redirect(url_for('error'))
    return render_template('weather.html',
           city=city, temp=temp, description=description, wind=wind
Looking at a part of weather.html.
We see that values get pass inside {{ city }}.
<div id="weather-city">
        <h1>{{ city }}</h1>
      <div id="weather-temp">
        {{ temp }} °C

Code weather-app
From command line:
pip install Flask
git clone https://[email protected]/snippsat/weather-app.git
Add own API key in xxxxxxxxx.
From weather-app folder python
E:\weather-app (master)
λ python
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 184-514-049
 * Running on (Press CTRL+C to quit)
In Browser:
Update Bump.

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020