diff --git a/README.md b/README.md new file mode 100644 index 0000000..93818b9 --- /dev/null +++ b/README.md @@ -0,0 +1,64 @@ +# EVS Notifications System +Nobody wants their aircon to switch off in the middle of the night when their credit runs out. + +The EVS notification system scrapes your credit balance daily. When your balance falls below a preset threshold, the system notifies you via Telegram bot. + +## Architecture +Click [here](assets/architecture.jpg) for an image of the system architecture. + +All operations involving data is done through individual corresponding APIs. + +### Components +* Postgres database +* Vue website for dashboard analytics +* Telegram bot + +### APIs +* CRUD operations for database +* GET operations only for dashboard +* Endpoint for fetching balance via web scraping +* Endpoint for sending one-time messages via Telegram bot + +### Daily-run services +* Scrape all user balances and add to database +* Retrieve all users to notify and send notifications + +## Pre-requisites +1. Python 3.6+ +1. Either: + * Postgres 9.5 + * Docker +1. NodeJS + +## Deployment +### Python +The following components use Python: +* APIs (Flask) +* Telegram bot (python-telegram-bot) +* Daily-run services + +All Python-based components have a `requirements.txt` file in their corresponding folder. + +### Vue dashboard +There is a corresponding README in the `dashboard` folder. A static site is bundled using Webpack and used for hosting. + +### Postgres +The database is run from a Docker container. To get a database up and running on your local machine: +``` +docker pull postgres:9.5 +docker run --rm -d \ + --name pg-docker \ + -e POSTGRES_USER=ubuntu \ + -e POSTGRES_PASSWORD=password \ + -e POSTGRES_DB=evs \ + -p 5432:5432 \ + -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data \ + postgres:9.5 +``` + +Afterwards, to connect to the database: +``` +PGPASSWORD=docker psql -h localhost -U postgres -d evs +``` + +For first-time setup, run `\i create_tables.sql` to define database schema. \ No newline at end of file diff --git a/assets/architecture.drawio b/assets/architecture.drawio new file mode 100644 index 0000000..2cda17d --- /dev/null +++ b/assets/architecture.drawio @@ -0,0 +1 @@ +7Zttc6o4FMc/jS/bIQkCvmzt053p3emOnb23+2YnQsRskbghVr2ffhMIAoJKfQDdbd9ITkJIzv93YnKwHdSfLB45no6/M48EHWh4iw6660D5B6D8UJZlYgEri8+pp22ZYUB/EW00tHVGPRIVGgrGAkGnR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XpdqwtNu3jyN9ZO/sl0Sif/cr+oew2BjXoAGSYy7Z5T6Ncym80ogMPfTVRnTX9jgo4o4fkMbDEnW0rVbg2pHWnWigxppzpdWAHjxgyiDeB1t6APAEY5iwhTWz6JCE6XRDw8mV6t2cCVfs0kuwCBoH2OAiFr9xeGeq8/3egB/VMEPEybG5/1DOiWPGOXHeM4zTqmitxKx6h3JaHANFQvGGKADvLVFpnKHmzPP/aJAvuVBMTneFJejIdMXFC4m706UDcc7d0TifbCIuFz9WrT8LDEG0fkgqSqt/40LFXV27fEo9EUh/tL9YMMY5Wi8ZBh7uVkSvo9X5kcdIYypTmpo4dUrNPFhJAF17WxUPvaGCfS5oGrVvI0e0EKodL28wwUgt2Sq06Z7Eqv4+zAKuu+K61QyClkia//cK6r9lu+Vl8SV6W6jhHddxe4gykd/s8guNOfvp/8iHABAjnNrr6ymP2UPsm/Zf+wgO7/BQ== \ No newline at end of file diff --git a/assets/architecture.jpg b/assets/architecture.jpg new file mode 100644 index 0000000..6e432f7 Binary files /dev/null and b/assets/architecture.jpg differ diff --git a/hosts/database/setup/setup.md b/hosts/database/setup/setup.md index 85de2f9..37bc2d6 100644 --- a/hosts/database/setup/setup.md +++ b/hosts/database/setup/setup.md @@ -1,3 +1,4 @@ +## Local machine ``` sudo -u postgres createuser --interactive createdb evs diff --git a/services/requirements.txt b/services/requirements.txt new file mode 100644 index 0000000..3288e92 --- /dev/null +++ b/services/requirements.txt @@ -0,0 +1,2 @@ +requests +