├── requirements.txt ├── config.py ├── Climate Change Impact Analysis.txt ├── README.md ├── process_data.py ├── app.py ├── fetch_climate_data.py ├── generate from the start year to 2022 - generate from the start year to 2022.csv ├── generate a table for 20 years for Precipitation... - generate a table for 20 years for Precipitation....csv └── create a table for Sea Level Rise Data (sea_level... - create a table for Sea Level Rise Data (sea_level....csv /requirements.txt: -------------------------------------------------------------------------------- 1 | requests 2 | pandas 3 | flask 4 | flask-restful 5 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | API_KEY = 'your_api_key' 2 | DATABASE_URI = 'sqlite:///climate_data.db' 3 | -------------------------------------------------------------------------------- /Climate Change Impact Analysis.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Akajiaku11/Climate-Data-API-Project/HEAD/Climate Change Impact Analysis.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Climate Data API Project 2 | A simple API for serving climate data, using data from OpenWeather API. 3 | 4 | ## Setup 5 | 1. Install dependencies: 6 | ```bash 7 | pip install -r requirements.txt 8 | -------------------------------------------------------------------------------- /process_data.py: -------------------------------------------------------------------------------- 1 | def preprocess_data(df): 2 | # Convert timestamp to datetime format 3 | df['timestamp'] = pd.to_datetime(df['timestamp']) 4 | # Any additional preprocessing like handling missing data can be done here 5 | return df 6 | 7 | cleaned_data = preprocess_data(climate_df) 8 | print(cleaned_data) 9 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify 2 | from flask_restful import Api, Resource 3 | 4 | # Initialize the Flask app and API 5 | app = Flask(__name__) 6 | api = Api(app) 7 | 8 | class ClimateData(Resource): 9 | def get(self): 10 | # Return the last 5 climate data points (example) 11 | data = cleaned_data.to_dict(orient='records') 12 | return jsonify(data) 13 | 14 | api.add_resource(ClimateData, '/climate_data') 15 | 16 | if __name__ == '__main__': 17 | app.run(debug=True) 18 | -------------------------------------------------------------------------------- /fetch_climate_data.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import pandas as pd 3 | from datetime import datetime 4 | 5 | # OpenWeather API URL 6 | API_KEY = "your_api_key" 7 | CITY = "London" 8 | BASE_URL = f"http://api.openweathermap.org/data/2.5/forecast?q={CITY}&units=metric&cnt=5&appid={API_KEY}" 9 | 10 | def fetch_climate_data(): 11 | response = requests.get(BASE_URL) 12 | data = response.json() 13 | 14 | # Extract relevant data (Temperature, Humidity, etc.) 15 | climate_data = [] 16 | for entry in data['list']: 17 | timestamp = datetime.utcfromtimestamp(entry['dt']) 18 | temperature = entry['main']['temp'] 19 | humidity = entry['main']['humidity'] 20 | weather = entry['weather'][0]['description'] 21 | 22 | climate_data.append({ 23 | 'timestamp': timestamp, 24 | 'temperature': temperature, 25 | 'humidity': humidity, 26 | 'weather': weather 27 | }) 28 | 29 | return pd.DataFrame(climate_data) 30 | 31 | climate_df = fetch_climate_data() 32 | print(climate_df) 33 | -------------------------------------------------------------------------------- /generate from the start year to 2022 - generate from the start year to 2022.csv: -------------------------------------------------------------------------------- 1 | Date,Temperature (°C) 2 | 1980-01-31,14.192752 3 | 1980-02-29,16.484448 4 | 1980-03-31,12.956228 5 | 1980-04-30,14.432986 6 | 1980-05-31,15.495426 7 | 1980-06-30,16.766324 8 | 1980-07-31,13.945523 9 | 1980-08-31,14.592378 10 | 1980-09-30,15.79819 11 | 1980-10-31,12.392852 12 | 1980-11-30,16.429545 13 | 1980-12-31,15.052887 14 | 1981-01-31,14.53415 15 | 1981-02-28,16.956228 16 | 1981-03-31,13.522085 17 | 1981-04-30,14.757822 18 | 1981-05-31,15.090457 19 | 1981-06-30,16.943786 20 | 1981-07-31,15.47819 21 | 1981-08-31,14.343786 22 | 1981-09-30,14.205129 23 | 1981-10-31,13.673118 24 | 1981-11-30,16.528874 25 | 1981-12-31,14.173118 26 | 1982-01-31,14.943786 27 | 1982-02-28,16.882353 28 | 1982-03-31,12.925783 29 | 1982-04-30,15.335417 30 | 1982-05-31,16.257822 31 | 1982-06-30,16.192752 32 | 1982-07-31,15.180915 33 | 1982-08-31,13.556228 34 | 1982-09-30,17.465851 35 | 1982-10-31,13.271126 36 | 1982-11-30,12.673118 37 | 1982-12-31,15.407347 38 | 1983-01-31,13.602564 39 | 1983-02-28,16.407347 40 | 1983-03-31,16.07819 41 | 1983-04-30,14.87819 42 | 1983-05-31,15.766324 43 | 1983-06-30,16.692752 44 | 1983-07-31,15.452887 45 | 1983-08-31,14.004574 46 | 1983-09-30,14.673118 47 | 1983-10-31,13.141106 48 | 1983-11-30,16.882353 49 | 1983-12-31,14.205129 50 | 1984-01-31,14.343786 51 | 1984-02-29,16.257822 52 | 1984-03-31,13.317647 53 | 1984-04-30,15.180915 54 | 1984-05-31,15.943786 55 | 1984-06-30,16.829258 56 | 1984-07-31,15.090457 57 | 1984-08-31,13.945523 58 | 1984-09-30,14.592378 59 | 1984-10-31,13.317647 60 | 1984-11-30,16.692752 61 | 1984-12-31,14.592378 62 | 1985-01-31,14.757822 63 | 1985-02-28,16.692752 64 | 1985-03-31,13.090457 65 | 1985-04-30,15.495426 66 | 1985-05-31,16.192752 67 | 1985-06-30,17.12819 68 | 1985-07-31,15.570455 69 | 1985-08-31,14.205129 70 | 1985-09-30,14.87819 71 | 1985-10-31,13.602564 72 | 1985-11-30,17.030915 73 | 1985-12-31,14.673118 74 | 1986-01-31,14.87819 75 | 1986-02-28,16.829258 76 | 1986-03-31,13.317647 77 | 1986-04-30,15.335417 78 | 1986-05-31,16.257822 79 | 1986-06-30,17.030915 80 | 1986-07-31,15.47819 81 | 1986-08-31,13.824897 82 | 1986-09-30,14.673118 -------------------------------------------------------------------------------- /generate a table for 20 years for Precipitation... - generate a table for 20 years for Precipitation....csv: -------------------------------------------------------------------------------- 1 | Date,Precipitation (mm) 2 | 1980-01-31,48.734694 3 | 1980-02-29,54.265306 4 | 1980-03-31,45.734694 5 | 1980-04-30,53.265306 6 | 1980-05-31,59.795918 7 | 1980-06-30,51.265306 8 | 1980-07-31,47.795918 9 | 1980-08-31,52.265306 10 | 1980-09-30,56.795918 11 | 1980-10-31,43.265306 12 | 1980-11-30,50.795918 13 | 1980-12-31,49.265306 14 | 1981-01-31,46.734694 15 | 1981-02-28,55.265306 16 | 1981-03-31,42.734694 17 | 1981-04-30,51.265306 18 | 1981-05-31,57.795918 19 | 1981-06-30,50.265306 20 | 1981-07-31,48.795918 21 | 1981-08-31,53.265306 22 | 1981-09-30,57.795918 23 | 1981-10-31,44.265306 24 | 1981-11-30,51.795918 25 | 1981-12-31,49.265306 26 | 1982-01-31,47.734694 27 | 1982-02-28,56.265306 28 | 1982-03-31,43.734694 29 | 1982-04-30,52.265306 30 | 1982-05-31,58.795918 31 | 1982-06-30,51.265306 32 | 1982-07-31,49.795918 33 | 1982-08-31,54.265306 34 | 1982-09-30,58.795918 35 | 1982-10-31,45.265306 36 | 1982-11-30,52.795918 37 | 1982-12-31,50.265306 38 | 1983-01-31,48.734694 39 | 1983-02-28,57.265306 40 | 1983-03-31,44.734694 41 | 1983-04-30,53.265306 42 | 1983-05-31,59.795918 43 | 1983-06-30,52.265306 44 | 1983-07-31,50.795918 45 | 1983-08-31,55.265306 46 | 1983-09-30,59.795918 47 | 1983-10-31,46.265306 48 | 1983-11-30,53.795918 49 | 1983-12-31,51.265306 50 | 1984-01-31,49.734694 51 | 1984-02-29,58.265306 52 | 1984-03-31,45.734694 53 | 1984-04-30,54.265306 54 | 1984-05-31,60.795918 55 | 1984-06-30,53.265306 56 | 1984-07-31,51.795918 57 | 1984-08-31,56.265306 58 | 1984-09-30,60.795918 59 | 1984-10-31,47.265306 60 | 1984-11-30,54.795918 61 | 1984-12-31,52.265306 62 | 1985-01-31,50.734694 63 | 1985-02-28,59.265306 64 | 1985-03-31,46.734694 65 | 1985-04-30,55.265306 66 | 1985-05-31,61.795918 67 | 1985-06-30,54.265306 68 | 1985-07-31,52.795918 69 | 1985-08-31,57.265306 70 | 1985-09-30,61.795918 71 | 1985-10-31,48.265306 72 | 1985-11-30,55.795918 73 | 1985-12-31,53.265306 74 | 1986-01-31,51.734694 75 | 1986-02-28,60.265306 76 | 1986-03-31,47.734694 77 | 1986-04-30,56.265306 78 | 1986-05-31,62.795918 79 | 1986-06-30,55.265306 80 | 1986-07-31,53.795918 81 | 1986-08-31,58.265306 82 | 1986-09-30,62.795918 -------------------------------------------------------------------------------- /create a table for Sea Level Rise Data (sea_level... - create a table for Sea Level Rise Data (sea_level....csv: -------------------------------------------------------------------------------- 1 | Date,Sea Level Rise (m) 2 | 1980-01-31,0.1 3 | 1980-02-29,0.11 4 | 1980-03-31,0.12 5 | 1980-04-30,0.13 6 | 1980-05-31,0.14 7 | 1980-06-30,0.15 8 | 1980-07-31,0.16 9 | 1980-08-31,0.17 10 | 1980-09-30,0.18 11 | 1980-10-31,0.19 12 | 1980-11-30,0.2 13 | 1980-12-31,0.21 14 | 1981-01-31,0.22 15 | 1981-02-28,0.23 16 | 1981-03-31,0.24 17 | 1981-04-30,0.25 18 | 1981-05-31,0.26 19 | 1981-06-30,0.27 20 | 1981-07-31,0.28 21 | 1981-08-31,0.29 22 | 1981-09-30,0.3 23 | 1981-10-31,0.31 24 | 1981-11-30,0.32 25 | 1981-12-31,0.33 26 | 1982-01-31,0.34 27 | 1982-02-28,0.35 28 | 1982-03-31,0.36 29 | 1982-04-30,0.37 30 | 1982-05-31,0.38 31 | 1982-06-30,0.39 32 | 1982-07-31,0.4 33 | 1982-08-31,0.41 34 | 1982-09-30,0.42 35 | 1982-10-31,0.43 36 | 1982-11-30,0.44 37 | 1982-12-31,0.45 38 | 1983-01-31,0.46 39 | 1983-02-28,0.47 40 | 1983-03-31,0.48 41 | 1983-04-30,0.49 42 | 1983-05-31,0.5 43 | 1983-06-30,0.51 44 | 1983-07-31,0.52 45 | 1983-08-31,0.53 46 | 1983-09-30,0.54 47 | 1983-10-31,0.55 48 | 1983-11-30,0.56 49 | 1983-12-31,0.57 50 | 1984-01-31,0.58 51 | 1984-02-29,0.59 52 | 1984-03-31,0.6 53 | 1984-04-30,0.61 54 | 1984-05-31,0.62 55 | 1984-06-30,0.63 56 | 1984-07-31,0.64 57 | 1984-08-31,0.65 58 | 1984-09-30,0.66 59 | 1984-10-31,0.67 60 | 1984-11-30,0.68 61 | 1984-12-31,0.69 62 | 1985-01-31,0.7 63 | 1985-02-28,0.71 64 | 1985-03-31,0.72 65 | 1985-04-30,0.73 66 | 1985-05-31,0.74 67 | 1985-06-30,0.75 68 | 1985-07-31,0.76 69 | 1985-08-31,0.77 70 | 1985-09-30,0.78 71 | 1985-10-31,0.79 72 | 1985-11-30,0.8 73 | 1985-12-31,0.81 74 | 1986-01-31,0.82 75 | 1986-02-28,0.83 76 | 1986-03-31,0.84 77 | 1986-04-30,0.85 78 | 1986-05-31,0.86 79 | 1986-06-30,0.87 80 | 1986-07-31,0.88 81 | 1986-08-31,0.89 82 | 1986-09-30,0.9 83 | 1986-10-31,0.91 84 | 1986-11-30,0.92 85 | 1986-12-31,0.93 86 | 1987-01-31,0.94 87 | 1987-02-28,0.95 88 | 1987-03-31,0.96 89 | 1987-04-30,0.97 90 | 1987-05-31,0.98 91 | 1987-06-30,0.99 92 | 1987-07-31,1 93 | 1987-08-31,1.01 94 | 1987-09-30,1.02 95 | 1987-10-31,1.03 96 | 1987-11-30,1.04 97 | 1987-12-31,1.05 98 | 1988-01-31,1.06 99 | 1988-02-29,1.07 100 | 1988-03-31,1.08 101 | 1988-04-30,1.09 102 | 1988-05-31,1.1 --------------------------------------------------------------------------------