Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/victoriacheng15/flask-weather
A Flask weather app displaying real-time weather information from REST API based on user-input city and country queries.
https://github.com/victoriacheng15/flask-weather
api flask pytest python render
Last synced: about 1 month ago
JSON representation
A Flask weather app displaying real-time weather information from REST API based on user-input city and country queries.
- Host: GitHub
- URL: https://github.com/victoriacheng15/flask-weather
- Owner: victoriacheng15
- License: mit
- Created: 2024-03-18T00:56:11.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-04T01:25:59.000Z (8 months ago)
- Last Synced: 2024-10-02T23:40:39.425Z (about 2 months ago)
- Topics: api, flask, pytest, python, render
- Language: Python
- Homepage: https://flask-weather-vx15.onrender.com/
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask Weather App
The Flask Weather App is a simple web application built with Flask, a lightweight Python web framework, designed to provide users with current weather information for any city worldwide. Leveraging the OpenWeather API, this app offers real-time weather data including temperature, humidity, wind speed, and weather description for the specified location.
[Live Site](https://flask-weather-vx15.onrender.com/)
> Please note that I'm using the free render plan, which means the website may take longer to spin up.
## How to run the App:
1. Clone the repository
```bash
git clone [email protected]:victoriacheng15/flask-weather.gitcd flask-weather
```
2. Install
```bash
pip install -r requirements.txt
```
3. Obtain API Key
Sign up for an account on [OpenWeather](https://openweathermap.org/) to obtain an API key, which is required to access weather data.
4. Set Environment Variable
create `.env` file
```bash
WEATHER_API_KEY="YOUR_KEY"
```
5. Run the app
```bash
python3 main.py
```## What have I learned?
In this project, I learned to define routes in Flask, facilitating URL endpoints for user interaction. Using `@app.route()`, I set up routes for the home and weather pages, dictating how the application responds to client reques
Example:
```py
# For home page
@app.route("/")# For weather page
@app.route("/weather")
```Additionally, I explored passing data between Python functions and HTML templates in Flask. By utilizing `render_template()`, I dynamically generated HTML content by transferring data from Python to templates. This allowed for the presentation of real-time weather information obtained from the OpenWeather API.
Example:
```py
# Pass data object with date and time properties to the home page
render_template("index.html", data={"date": date, "time": time})
```
```htmlDate: {{ data.date }}
Current Time: {{ data.time }}
```
```py
# Pass data as as individual property for weather page
render_template(
"weather.html",
title=weather_data["name"],
country=weather_data["sys"]["country"],
status=weather_data["weather"][0]["description"].capitalize(),
# .... more
)
```
```html{{ title }}, {{ country }} Weather
Current Weather Status: {{ status }}
Tempature: {{ temp }}c°
```