Skip to content

This is a simple program to query a PostgreSQL database for customer details and reward them with airtime

License

Notifications You must be signed in to change notification settings

KenMwaura1/customer-rewards

Repository files navigation

forthebadge made-with-python GPL license Open Source Love svg1

Customer-Rewards

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.

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.

Prerequisites

  • 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.

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

2a. Create a virtualenv

    pyenv virtualenv customer-rewards

2b. Activate the virtualenv

pyenv activate customer-rewards
  1. Change into the working folder.

    cd customer-rewards
    
  2. Create a .env file and add your credentials

    touch .env 
    

OR Copy the included example

cp .env-example .env 
  1. Add your credentials to the .env file

  2. Install the required dependencies

    pip install -r requirements
    
  3. First run config.py to ensure there parameters are correct for accessing your database.

    python config.py
    
  4. Run customer-insert.py to populate the database with sample customer and transaction data.

    python customer_insert.py
    
  5. Follow it up with customer_search.py to filter out and get the required customers.

    python customer_search.py
    
  6. 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

About

This is a simple program to query a PostgreSQL database for customer details and reward them with airtime

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages