Python · Shipped
Weather Data API
A Flask REST API serving historical temperature data by station, date, and year.
PythonFlask
A Flask-based RESTful API that provides historical temperature data for various weather stations. The project allows users to query temperature data by station ID, specific dates, and yearly records.
Features #
- View all available weather stations
- Get temperature data for a specific station on a specific date
- Retrieve all temperature records for a specific station
- Get yearly temperature data for a specific station
Technologies Used #
- Python 3.x
- Flask (Web Framework)
- Pandas (Data Processing)
- HTML (Frontend)
Installation #
- Clone the repository:
git clone <repository-url>
cd weather-api
- Create and activate a virtual environment:
python -m venv .venv
# On Windows
.venv\Scripts\activate
# On Unix or MacOS
source .venv/bin/activate
- Install the required dependencies:
pip install flask pandas
Project Structure #
weather-api/
├── main.py # Main application file
├── data_small/ # Directory containing weather station data
│ └── stations.txt # List of weather stations
│ └── TG_STAID*.txt # Temperature data files
├── templates/ # HTML templates
│ └── home.html # Homepage template
└── static/ # Static files (CSS, JS, etc.)
API Endpoints #
-
Homepage
- URL:
/ - Method:
GET - Description: Displays the list of all available weather stations
- URL:
-
Get Temperature for Specific Station and Date
- URL:
/api/v1/<station>/<date> - Method:
GET - Parameters:
- station: Station ID
- date: Date in YYYY-MM-DD format
- Returns: JSON with station ID, date, and temperature
- URL:
-
Get All Data for a Station
- URL:
/api/v1/<station> - Method:
GET - Parameters:
- station: Station ID
- Returns: JSON array with all temperature records
- URL:
-
Get Yearly Data for a Station
- URL:
/api/v1/yearly/<station>/<year> - Method:
GET - Parameters:
- station: Station ID
- year: Year in YYYY format
- Returns: JSON array with temperature records for the specified year
- URL:
Example Usage #
- Get temperature for station 10 on October 25, 1988:
http://127.0.0.1:5000/api/v1/10/1988-10-25
- Get all temperature records for station 10:
http://127.0.0.1:5000/api/v1/10
- Get temperature records for station 10 in 1988:
http://127.0.0.1:5000/api/v1/yearly/10/1988
Running the Application #
- Activate the virtual environment (if not already activated)
- Run the application:
python main.py
- Open a web browser and navigate to
http://127.0.0.1:5000
Data Format #
The temperature data is stored in text files with the following format:
- Temperature values are stored in tenths of a degree Celsius
- The API automatically converts the values to actual degrees Celsius when serving the data
- Dates are in YYYY-MM-DD format
Contributing #
Feel free to submit issues and enhancement requests!