This project is designed to send WhatsApp messages about the current status of a PostgreSQL table to two project partners. The messages include the total row count and a summary of the latest 100 subreddits with their respective counts. The messages are sent using the Twilio API.
.
├── main.py
├── database.py
├── requirements.txt
├── send-corpus-message.sh
└── .env.example
This is the main script that imports DatabaseManager
from database.py
, constructs the messages, and sends them using the Twilio API. It is runnable and serves as the entry point for the cron job.
This module contains the DatabaseManager
class, which handles all database-related operations, including connecting to the PostgreSQL database and fetching data.
This file lists the dependencies for the project. The required packages are:
python-dotenv
twilio
This is the script used in the cron job to execute main.py
. Make sure to make this file executable using the following command:
chmod +x send-corpus-message.sh
This is an example environment file. Copy this file to .env
and fill in the appropriate values:
DATABASE_URL="postgresql://<username>:<password>@<host>:<port>/<database>"
TWILIO_ACCOUNT_SID=""
TWILIO_AUTH_TOKEN=""
TWILIO_FROM="+xxxxxxxxxxx"
TO_PHONE_NUMBERS="+xxxxxxxxxxx,+xxxxxxxxxxx"
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
pip install -r requirements.txt
-
Create and populate the .env file:
cp .env.example .env # Fill in the .env file with your credentials
-
Make the script executable:
chmod +x send-corpus-message.sh
-
Set up the cron job: Open the crontab editor:
crontab -e
Add the following line to the crontab:
0 0,1,6,8,10,12,14,16,18,20,22,23 * * * <absolute-path-to-script>/send-corpus-message.sh
This cron job runs the script at the specified hours (midnight, 1 AM, 6 AM, 8 AM, 10 AM, noon, 2 PM, 4 PM, 6 PM, 8 PM, 10 PM, and 11 PM).
The script sends WhatsApp messages with the following format:
<total_rows_in_table>
Latest 100 subreddits:
• subreddit1: count1
• subreddit2: count2
...
This allows you to monitor the state of your table as new data is added.
- Ensure you have a valid Twilio account and have set up WhatsApp messaging on your Twilio number.
- The database connection and Twilio credentials must be correctly set in the
.env
file. - Adjust the cron job timing as necessary to suit your needs.
This project is licensed under the MIT License. See the LICENSE
file for details.