Skip to content

This weather app displays weather data for a large amount of cities across the world.

License

Notifications You must be signed in to change notification settings

JM1F/Weather-App

Repository files navigation

Weather-App

This weather app displays weather data for a large amount of cities across the world.

All data is received from https://openweathermap.org/api.

GUI made using python-tkinter

Two websites are used, one for the REST API and the other is used for city selection and tide times (UK Only). Either website can be locally hosted or hosted with a third party. (Program currently set up for local host) Both websites need to be used for the weather app to properly work.

image

  • The GUI showing weather data for London.

How To Use The App For The First Time

1. When you have opened the map website click on the map where you roughly live and a black circle will show the radius of the eligible cities.

image

  • The map and tide times (UK) are both hosted on a website. (The source code is currently set to local host)

2. Once the map is clicked the address of the REST API is fetched and the longitude and latitude data is sent to it.

3. Now you need to open the GUI as shown above where you open the settings menu:

4. Here you can choose your city and the app will save it into a file so you don't have to go through the process again (Unless you want to change cities).

How It Works

  • Coordinates are inputted by the user when the map webpage is clicked.
  • This data is then sent to the REST API.
  • The REST API then talks to python through python-flask.
  • The data is then parsed from the REST API to Python.

  • (If the data is already saved in the Location File then the previous will not be performed if there is a city already saved.)

  • The location data is then used as parameters for OpenWeatherMap's API.

url3 = "http://api.openweathermap.org/data/2.5/find?lat={}&lon={}&cnt=10&appid={}".format(lat, long, APIKEY)
  • Where the GUI on the front-end displays the data received from the OpenWeatherMap API.

REST API Module

# Rest API sends and receives data, currently set up for local host.

app = Flask(__name__)
cors = CORS(app)
messages = {}
@app.route('/', methods=['GET', "PUT", "POST"])
def flaskREST():
   
    # POST request
    if request.method == 'POST':
        try:
            print('Incoming...')
            Long = request.get_json("long")
            messages["coords"] = Long
            print(messages)
            return jsonify(messages)
        except:
            print("An Error Occured...")

    # GET request
    if request.method == "GET":
        try:
            return jsonify(messages)  
        except:
            print("An Error Occured...")

    # PUT request
    if request.method == "PUT":
        try:
            Long = request.get_json("long")
            messages["coords"] = Long
            print(messages)
            return jsonify(messages)
        except:
            print("An Error Occured...")

if __name__ == '__main__':
    app.run(host="127.0.0.1", port=5000)
  • Currently set to local host. (127.0.0.1:5000)

About

This weather app displays weather data for a large amount of cities across the world.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published