This is a proof-of-concept (POC) project for managing and retrieving climate data. The project provides RESTful API endpoints for saving climate data, fetching records, and calculating climate change metrics.
Follow these instructions to set up and run the project locally.
- Python 3.x
- Flask
- Flask-SQLAlchemy
You can install the required Python packages using pip:
pip install Flask Flask-SQLAlchemy
This files contains the complete implementation of the climate data POC using Flask and SQLite with proper thread safety using flask_sqlalchemy. This code includes all the required endpoints and database operations:
-
First install the required libraries:
- pip install Flask Flask-SQLAlchemy
-
Create app.py Python file
-
Create seed_data.py Python file
Initialize the SQLite database and insert sample data:
python seed_data.py
- Run the Flask application (app.py) to start the API server
python app.py
The application will be running at http://127.0.0.1:5000.
URL: /save_data
Method: POST
To send data to this endpoint, you can use a tool like curl or Postman, or you can integrate it into your frontend application as needed. Here's an example curl request:
curl -X POST -H "Content-Type: application/json" -d '{
"climate":"hot",
"area_code": 555,
"temperature": 30,
"humidity": 70,
"chances_of_rain": 50
}' http://localhost:5000/send_data
URL: /fetch_all_records
Method: GET
Response: JSON response containing all climate data records
URL: /fetch_records_by_area/<area_code>
Method: GET
Response: JSON response containing climate data records for the specified area code
URL: /fetch_records_by_climate/<climate>
Method: GET
Response: JSON response containing climate data records for the specified climate
URL: /calculate_metrics
Method: POST
Payload: JSON payload containing climate data including from_climate, to_climate, and area_code
To test this endpoint, you can use a tool like curl or Postman, or you can integrate it into your frontend application. Here's an example curl request:
curl -X POST -H "Content-Type: application/json" -d '{
"from_climate":"hot",
"to_climate":"cold",
"area_code": 555
}' http://localhost:5000/calculate_metrics