This project collects weather data using Python, Flask and PostgreSQL. It periodically fetches real-time data from a Weather API, stores it in PostgreSQL, and returns the weather data for a specific city.
Before you begin, ensure you have the following installed and set up on your development environment:
- Python: Version 3.12.4 or higher.
- PostgreSQL: Ensure you have PostgreSQL installed and running locally. You can download it from PostgreSQL Downloads.
(https://www.postgresql.org/download/)
is the URL to the PostgreSQL Downloads page.
1 - Clone the Repository:
- git clone https://github.com/sabrahermassi/weather-data-collection-and-fetching.git
- cd weather-data-collection-and-fetching
2 - Install Python Dependencies: Install project dependencies using pip, this will install all required Python packages listed in requirements.txt.
- python -m pip install --upgrade pip
- pip install -r requirements.txt
1 - Set Up Database Configuration: Create a test_database.ini file in the root directory for testing purposes:
main_database
: First section for the postgres main database running on your computerhost
: The hostname of the postgres databaseport
: The port number of the postgres databasedatabase
: The name of your main postgres databaseuser
: The user name of the postgres databasepassword
: The password created for the postgres databasetest_weather_database
: Second section for the test database you createdhost
: The hostname of the test databaseport
: The port number of the test databasedatabase
: The name of your test databaseuser
: The user name of the test databasepassword
: The password created for the test database
2 - Set Up Environment Variables: Create a .env file in the root directory with the following content (Update API_KEY with your actual API key for weather data access.):
API_KEY
: your api key from the weather API of your choiceAPI_BASE_URL
: URL to the weather API of your choise
- To start the application, run: python api/app.py
- To run unit tests, use: pytest tests/unit
- To run integration tests, use: pytest tests/integration