Giter VIP home page Giter VIP logo

expense-tracker's Introduction

expense-tracker

Track expenses and incomes via WhatsApp and get a full report.

This project uses:

Please make sure you have mysql installed and there is a MySQL server available. You can visit this tutorial to learn more about standing up a MySQL server.

The server is enabled to interact with Twilio's WhatsApp API. It provides a webhook which Twilio can POST to, so that it may record a transaction, create a report and other useful commands.

When standing up the server locally, please visit localhost:8000/docs to read the docs.

Creating the database and tables

In a terminal, connect to the MySQL database server. You can visit this tutorial to learn how to connect locally to your server.

To connect locally to the server you can use this command:

mysql -u user -p

Once the mysql> prompt is available, you can create the database and tables.

Create the database:

mysql> CREATE DATABASE main;

Use the database you just created:

mysql> USE main;

Create the tables:

mysql> CREATE TABLE users (
    id INT unsigned NOT NULL AUTO_INCREMENT,
    created_at DATETIME NOT NULL,
    whatsapp_phone VARCHAR(15) NOT NULL,
    name VARCHAR(150) NOT NULL,

    PRIMARY KEY (id)
);
CREATE TABLE organizations (
    id INT unsigned NOT NULL AUTO_INCREMENT,
    created_at DATETIME NOT NULL,
    name VARCHAR(150) NOT NULL,
    currency VARCHAR(3) NOT NULL,
    language VARCHAR(2) NOT NULL,
    
    PRIMARY KEY (id)
);
CREATE TABLE transactions (
    id INT unsigned NOT NULL AUTO_INCREMENT, 
    created_at DATETIME NOT NULL,
    label VARCHAR(150) NOT NULL,
    value FLOAT NOT NULL,
    currency VARCHAR(3) NOT NULL,
    value_converted FLOAT NOT NULL,
    description VARCHAR(150) NOT NULL,
    
    PRIMARY KEY (id)
);

Run locally

Some environment variables are required to run the application. They should be defined in a standard .env file. Please copy the .env.example file into a .env and replace the values with your own.

Before running the app, make sure the MySQL database server is running, the tables are created and the environment variables are set.

Run the app:

uvicorn app.main:server --reload

Query the docs. Go to your web browser and visit the following url: localhost:8000/docs.

Perform a health check:

curl --location --request GET 'localhost:8000' \
--header 'Content-Type: application/json'

A webhook can be submitted from Twilio. Please see the docs for the details on using the /twilio endpoint.

Note that the sender in the From param must be authorized in the ALLOWED_FROM environment variable.

Run with Docker

Build the image.

docker build -t expense-tracker .

Run a container using the image. Do not forget to have the environment variables set in the .env file.

docker run -d --name expense-tracker -p 80:8000 --env-file .env --rm expense-tracker

Now you can make all the same requests that were described in the previous section, but to port 80.

You can see the logs of your container with docker logs expense-tracker or follow them adding the -f flag before the container name.

expense-tracker's People

Contributors

sebastian-quintero avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.