Article

Automate Currency Exchange Rate WhatsApp Notifications with Python and Twilio

Python project that fetches real-time currency exchange rates and sends them as WhatsApp notifications using the Twilio API. Step-by-step setup with cron scheduling.

Originally published on June 15, 2024. ~4 min read.

Have you ever needed to stay updated with real-time currency exchange rates and receive instant notifications? If so, I have an exciting project to share with you! Introducing the Currency Exchange Rate to BRL WhatsApp Notifier, a Python-based tool that fetches the current exchange rates for various currencies and cryptocurrencies, converts them to Brazilian Real (BRL) or others, and sends the converted rates directly to your WhatsApp or group using the Twilio API.

Why This Project?

Staying updated with the latest exchange rates is crucial for traders, investors, and anyone dealing with multiple currencies. However, constantly checking the rates can take time and effort. This project automates the entire process, ensuring you receive real-time updates directly on your WhatsApp, making it easier to make informed decisions.

I usually must be on top of things while busy. So, sending me these conversions and values via WhatsApp helps me stay on top of my swing trade and know when to buy or sell a currency. This saves me from having to remember and keep logging into coin sites.

Features

  • Automated Fetching: Retrieves current exchange rates for USD, BTC, EUR, and ETH.
  • Conversion to BRL: Converts the fetched rates to Brazilian Real (BRL).
  • WhatsApp Notifications: Sends the converted rates to your WhatsApp using the Twilio API.
  • Environment Variables: Utilizes .env files to manage sensitive information securely.

How It Works

The project uses Python libraries like requests, BeautifulSoup, and yfinance to fetch and parse exchange rates from Google Finance. It then uses the Twilio API to send the converted rates as WhatsApp messages. Here is a step-by-step guide on how to set it up.

Step 1: Clone the Repository

First, clone the GitHub repository to your local machine:

git clone https://github.com/yourusername/currency-exchange-whatsapp-notifier.git
cd currency-exchange-whatsapp-notifier

Step 2: Set Up the Environment

Create a virtual environment and activate it:

python3 -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

Install the required dependencies:

pip install -r requirements.txt

Step 3: Configure Environment Variables

Create a .env file in the project root and add your Twilio credentials and WhatsApp numbers:

TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_WHATSAPP_NUMBER=whatsapp:+14155238886
RECIPIENT_WHATSAPP_NUMBER=whatsapp:+recipient_phone_number

Step 4: Run the Script

To fetch the exchange rates and send them to WhatsApp, run the following command:

python send_exchange_rates.py

Step 5: Schedule the Script

You can schedule the script to run at specific times using cron on macOS or Linux. For example, to run the script at 8 AM and 2 PM daily:

macOS and Linux:

  1. Open Terminal.
  2. Edit the crontab file:
crontab -e

3. Add the following lines:

0 8 * * * /path/to/your/venv/bin/python /path/to/your/script/send_exchange_rates.py
0 14 * * * /path/to/your/venv/bin/python /path/to/your/script/send_exchange_rates.py

Conclusion

With the Currency Exchange Rate to BRL (or other country/currency) WhatsApp Notifier, you can effortlessly stay updated with real-time exchange rates. Whether you are a trader, investor, or someone who needs to keep track of currency conversions, this tool can be a valuable addition to your workflow.

Check out the GitHub repository for the complete source code and detailed instructions.

If you found this project helpful, please give it a star on GitHub and share it with others who might benefit. Your feedback and contributions are always welcome.

About this version

Originally published on Medium

This article was originally published on June 15, 2024. The version on buildcomcarlos.com is the integral editorial copy maintained on my site. You can read the original on Medium with the original layout, claps and responses.