https://github.com/kenmwaura1/customer-rewards
This is a simple program to query a PostgreSQL database for customer details and reward them with airtime
https://github.com/kenmwaura1/customer-rewards
africastalking database postgresql python
Last synced: 7 months ago
JSON representation
This is a simple program to query a PostgreSQL database for customer details and reward them with airtime
- Host: GitHub
- URL: https://github.com/kenmwaura1/customer-rewards
- Owner: KenMwaura1
- License: mit
- Created: 2021-04-05T20:17:34.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T20:18:11.000Z (over 2 years ago)
- Last Synced: 2025-03-29T05:51:18.699Z (8 months ago)
- Topics: africastalking, database, postgresql, python
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.python.org/)
[](http://perso.crans.org/besson/LICENSE.html)
[](https://github.com/ellerbrock/open-source-badges/)
# Customer-Rewards
**Read the accompanying article [here](https://dev.to/ken_mwaura1/automate-customer-rewards-using-python-postgresql-and-africas-talking-9dj)**
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.
## Getting Started
### Points to Note
There are 4 main scripts in this repository:
1. `config.py` holds all the configuration related to our database. Adjust according to your setup.
2. `database_insert.py` is used to insert sample customer and sales transaction data into a Postgres database.
3. `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.
4. `customer_rewards.py` utilizes the data generated by `customer_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](https://www.account.africastalking.com/)
### Prerequisites
- Python and pip (I am currently using 3.9.2) Any version above 3.5 should work.
- An [Africas Talking account](https://account.africastalking.com/auth/register/).
- 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.
## Running the script
1. Clone the Repo
```
git clone https://github.com/KenMwaura1/customer-rewards
```
2. Create a virtual environment (venv)
```
python venv venv
```
- Activate the virtual environment
`source ./scripts/activate`
If you are using [pyenv](https://github.com/pyenv/pyenv)
2a. Create a virtualenv
```
pyenv virtualenv customer-rewards
```
2b. Activate the virtualenv
```
pyenv activate customer-rewards
```
3. Change into the working folder.
```
cd customer-rewards
```
4. Create a `.env` file and add your credentials
```
touch .env
```
OR Copy the included example
```
cp .env-example .env
```
5. Add your credentials to the .env file
6. Install the required dependencies
```
pip install -r requirements
```
7. First run `config.py` to ensure there parameters are correct for accessing your database.
```
python config.py
```
8. Run `customer-insert.py` to populate the database with sample customer and transaction data.
```
python customer_insert.py
```
9. Follow it up with `customer_search.py` to filter out and get the required customers.
```
python customer_search.py
```
10. 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](https://twitter.com/Ken_Mwaura1)