Climate Reports is a Python application designed to process climate data and generate PDF reports. The application provides functionality to create climate reports and send via email.
You can see a generated report example here
To set up and run the application using Docker Compose:
-
Setup Configuration:
- Duplicate env-sample.py and rename it to env.py.
- Add SMTP configurations to env.py.
-
Build and Run Containers:
docker-compose up --build
This command will start the application and expose the TCP server on port 5784.
-
Attach to the Container:
docker exec -it <container_name> /bin/bash
Replace <container_name> with the name of your running container. You can find it using docker ps.
-
Activate Conda Environment: Inside the container, activate the Conda environment:
conda activate your_env_name
-
Navigate to the Application Directory:
cd /app
If you prefer to set up the environment manually:
-
Create Conda Environment:
conda env create -f environment.yml -n <environment_name>
Replace <environment_name> with the name you want to your enviroment.
-
Activate Conda Environment:
conda activate <environment_name>
-
Setup Configuration:
- Duplicate env-sample.py and rename it to env.py.
- Add SMTP configurations to env.py.
To start the TCP server:
python climate_reports_generator/main.py
To run tests and populate the database with sample data:
pytest climate_reports_generator/tests.py
To generate a PDF report, place your data file in the climate_reports_generator/raw_data/
directory. Then run the following command:
python climate_reports_generator/report_generator.py TELEFONE DATA BRUTO [--ENVIA_EMAIL]
This command will generate the PDF, save it to climate_reports_generator/generated_reports/
, and send it to the user's email.
-
TELEFONE:
- Description: Phone number(s) of the users who will receive the report. You can specify one or more numbers, separated by commas.
- Format: 01234567891 or 01234567891,78945612348
-
DATA:
- Description: The date and time for the report. This is used to timestamp the report.
- Format: YYYY-MM-DDTHH:MM
-
BRUTO:
- Description: Path to the raw report data file in JSON format. This file should be located in the
climate_reports_generator/raw_data/
directory. - Format: climate_reports_generator/raw_data/test_data.txt
- Description: Path to the raw report data file in JSON format. This file should be located in the
-
--ENVIA_EMAIL
(Optional):- Description: A flag to indicate if the report should be sent via email. If this flag is included, the generated report will be sent to the users' email addresses.
- Type: Boolean flag (true if provided, false otherwise)
Example Command
python climate_reports_generator/report_generator.py 01234567891,78945612348 2024-01-01T00:00 climate_reports_generator/raw_data/test_data.txt --ENVIA_EMAIL
To test email functionality, use an SMTP service such as Mailtrap (free plan allows sending emails to registered address). The application will send the report to the user’s email.
The generated report will be attached to an email. Here is a example: