Skip to content

Digging currency rates of various currencies for us

License

Notifications You must be signed in to change notification settings

N0081K/gold-digger

 
 

Repository files navigation

Gold-digger (Exchange rates service)

Used technologies

Development setup

Setup python environment:

pip install -U pip wheel && pip install -r requirements-dev.txt

Create PostgreSQL database golddigger and grant permissions to user postgres.

CREATE DATABASE "golddigger" WITH OWNER = postgres ENCODING = 'UTF8';

Create local settings file called gold_digger/settings/_settings_local.py with configuration for local machine. For development purposes there is no configuration required so file may be empty.

For custom database connection use something like this to overwrite default configuration in gold_digger/settings/_settings_default.py:

DATABASE_HOST = "<your_PG_server>"
DATABASE_PORT = "<database_port>"
DATABASE_USER = "<database_user>"
DATABASE_PASSWORD = "<secret_password>"
DATABASE_NAME = "<database_name>"

Usage

Available commands:

  • python -m gold_digger initialize-db creates all tables in new database
  • python -m gold_digger update [--date="yyyy-mm-dd"] updates exchange rates for specified date (default today)
  • python -m gold_digger update-all [--origin-date="yyyy-mm-dd"] updates exchange rates since specified origin date
  • python -m gold_digger api starts development API server

For running the tests simply use:

  • py.test or ptw which starts watchdog which run the tests after every save of Python file
  • py.test --database-tests --db-connection postgresql://postgres:postgres@localhost/golddigger-test (with custom db connection) which runs also tests marked as @database_test. These tests are executed against real test database.

Tests & QA

  • pytest runs unit tests (use --database-tests for database tests)
  • black . formats code (use --check for dry run)
  • ruff . checks code quality (use --fix to fix fixable errors)

API endpoints

Docker

To build a docker image run:

docker build -t gold-digger:latest .

Docker container starts the Gunicorn server by default.

  • This command runs API container with Gunicorn server:

docker run --detach --restart=always --publish=8080:8080 --name=gold-digger gold-digger:latest

  • To control Gunicorn's parameters use this:

docker run --detach --restart=always --publish=8080:8080 -e GUNICORN_WORKERS=1 -e GUNICORN_BIND=0.0.0.0:8080 --name=gold-digger gold-digger:latest

  • To run Cron container with daily updates at 00:05 use command:

docker run --detach --restart=always --name gold-digger-cron gold-digger:latest python -m gold_digger cron

  • If you are connecting to local database on the host run the container with --net=host option:

docker run --detach --restart=always --net=host --publish=8080:8080 --name=gold-digger gold-digger:latest

docker run --detach --restart=always --net=host --name gold-digger-cron gold-digger:latest python -m gold_digger cron

  • To inject your database user, password, host, port and name use:
docker run --detach --restart=always \
    -e GOLD_DIGGER_DATABASE_HOST=<your_database_host> \
    -e GOLD_DIGGER_DATABASE_PORT=<your_database_port> \
    -e GOLD_DIGGER_DATABASE_USER=<your_database_user> \
    -e GOLD_DIGGER_DATABASE_PASSWORD=<your_database_secret_password> \
    -e GOLD_DIGGER_DATABASE_NAME=<your_database_name> \
    --publish=8080:8080 --name=gold-digger gold-digger:latest
docker run --detach --restart=always \
    -e GOLD_DIGGER_DATABASE_HOST=<your_database_host> \
    -e GOLD_DIGGER_DATABASE_PORT=<your_database_port> \
    -e GOLD_DIGGER_DATABASE_USER=<your_database_user> \
    -e GOLD_DIGGER_DATABASE_PASSWORD=<your_database_secret_password> \
    -e GOLD_DIGGER_DATABASE_NAME=<your_database_name> \
    --name gold-digger-cron gold-digger:latest python -m gold_digger cron

Settings profiles

Currently, you can use two settings profiles:

  • default profile named local with definitions in gold_digger/settings/_settings_local.py
  • production profile named master with definitions in gold_digger/settings/_settings_master.py

To run this application with production settings master you need to export environment variable GOLD_DIGGER_PROFILE.

docker run --detach --restart=always -e GOLD_DIGGER_PROFILE=master --publish=8080:8080 --name=gold-digger gold-digger:latest

docker run --detach --restart=always -e GOLD_DIGGER_PROFILE=master --name gold-digger-cron gold-digger:latest python -m gold_digger cron

About

Digging currency rates of various currencies for us

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 89.2%
  • Groovy 9.7%
  • Dockerfile 1.1%