Read the accompanying article here
This is a simple script to query a postgres database for customer details and reward them with airtime Utilizing SqlAlchemy as the ORM and the Africas Talking python SDK to send airtime.
The aim of this project is to act as a proof of concept for automating customer rewards.
There are 4 main scripts in this repository:
config.py
holds all the configuration related to our database. Adjust according to your setup.database_insert.py
is used to insert sample customer and sales transaction data into a Postgres database.customer_search.py
is used to query the database for customers based two criteria" Sales_Transaction dates between 12th and 19th March 2021 and value of more than KES 2500. These values are arbitrary, adjust as you prefer.customer_rewards.py
utilizes the data generated bycustomer_search.py
and the africastalking python sdk to send airtime to each customer.
- This project also uses .env file to store the API key and username. Both can be obtained by signing up/logging into Africas Talking
- Python and pip (I am currently using 3.9.2) Any version above 3.5 should work.
- An Africas Talking account.
- Api Key and username from your account. Create an app and take note of the api key.
- Additionally, you will need to request them to enable airtime access for your account. Email their airtime team for further clarification.
- Postgres Database
- This could be installed natively on your system or running in a docker container.
-
Clone the Repo
git clone https://github.com/KenMwaura1/customer-rewards
-
Create a virtual environment (venv)
python venv venv
-
Activate the virtual environment
`source ./scripts/activate`
If you are using pyenv
2a. Create a virtualenv
pyenv virtualenv customer-rewards
2b. Activate the virtualenv
pyenv activate customer-rewards
-
Change into the working folder.
cd customer-rewards
-
Create a
.env
file and add your credentialstouch .env
OR Copy the included example
cp .env-example .env
-
Add your credentials to the .env file
-
Install the required dependencies
pip install -r requirements
-
First run
config.py
to ensure there parameters are correct for accessing your database.python config.py
-
Run
customer-insert.py
to populate the database with sample customer and transaction data.python customer_insert.py
-
Follow it up with
customer_search.py
to filter out and get the required customers.python customer_search.py
-
Finally, run
customer_rewards.py
to send out airtime rewards to the selected customers.python customer_rewards.py
PS: If you need further clarification, read the article or tweet me