Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rukbotto/financial-chat-django

Simple chat application powered by Django.
https://github.com/rukbotto/financial-chat-django

Last synced: 15 days ago
JSON representation

Simple chat application powered by Django.

Awesome Lists containing this project

README

        

# Financial Chat Django

A simple chat application powered by *Django*. It offers basic real-time chat messaging between users in chat rooms. As a bonus, it is possible to ask a financial chat bot for stock quote prices!

## Installation

Install *PostgreSQL* and *Git*:

```
# On MacOS
$ brew install postgresql git

# On Debian GNU/Linux
$ sudo apt install postgresql git
```

Install `virtualenv` or `virtualenvwrapper`:

```
# Install virtualenv
$ sudo pip install virtualenv

# Or virtualenvwrapper
$ sudo pip install virtualenvwrapper
```

Clone this repository:

```
$ git clone https://github.com/rukbotto/financial-chat-django ~/financial-chat-django
```

Create a virtualenv for installing all dependencies:

```
# Using virtualenv
$ virtualenv ~/.virtualenvs/financial-chat-django --python=python3

# Or using virtualenvwrapper
$ mkvirtualenv financial-chat-django --python=python3
```

Activate the newly created virtualenv:

```
# Using virtualenv
$ source ~/.virtualenvs/financial-chat-django/bin/activate

# Or using virtualenvwrapper
$ workon financial-chat-django
```

Install all dependencies:

```
(financial-chat-django) $ cd ~/financial-chat-django
(financial-chat-django) $ pip install -r requirements.txt
```

## Database configuration

Create a new PostgreSQL role:

```
(financial-chat-django) $ psql postgres
postgres=# CREATE ROLE financial_chat_django WITH LOGIN PASSWORD 'strong_password_here';
postgres=# ALTER ROLE financial_chat_django CREATEDB;
postgres=# \q
```

Then create the database using the recently created user:

```
(financial-chat-django) $ psql postgres -U financial_chat_django
postgres=> CREATE DATABASE financial_chat_django;
```

Finally grant permissions:

```
postgres=> GRANT ALL PRIVILEGES ON DATABASE financial_chat_django TO financial_chat_django;
postgres=> \q
```

## Django configuration

Create a local configuration file:

```
(financial-chat-django) $ touch financial_chat_django/local_settings.py
```

And add the following lines of code in order to configure local development settings:

```python
SECRET_KEY='secret_key_here'

DEBUG = True

ALLOWED_HOSTS = []

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'financial_chat_django',
'USER': 'financial_chat_django',
'PASSWORD': 'strong_password_here',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
```

The secret key can be generated by *Django* using the interactive *Python* shell:

```
(financial-chat-django) $ python
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
>>> from django.core.management.utils import get_random_secret_key
>>> get_random_secret_key()
>>> '3z^w%y!...'
```

Copy the generated secret key and paste it into the `SECRET_KEY` setting in the local configuration file.

## Docker installation

We are using *Docker* for installing and running *Redis* and *RabbitMQ* services instead of installing them directly in the development machines.

For installing *Docker* in *MacOS*, you can download the installer from [*Docker Store*](https://store.docker.com/editions/community/docker-ce-desktop-mac).

For *Debian*, you need to add the *Docker APT* repository and install *Docker* using the package manager. Detailed instructions can be found [here](https://docs.docker.com/install/linux/docker-ce/debian/).

## Redis installation

*Redis* is an in-memory database and message broker required by *Django Channels* for enabling real-time communication between chat users.

To install *Redis*, pull the latest official image form *Docker Store*:

```
$ docker pull redis
```

## RabbitMQ installation

*RabbitMQ* is a message broker required by *Celery* for queuing tasks, like the one which queries stock quote prices.

To install *RabbitMQ*, pull the latest official image from *Docker Store*:

```
$ docker pull rabbitmq
```

## Usage

Run the *Redis* and *RabbitMQ* containers:

```
$ docker run -d -p 6379:6379 --name financial_chat_redis redis
$ docker run -d --p 5672:5672 -p 15672:15672 -name financial_chat_rabbit rabbitmq
```

Run database migrations:

```
(financial-chat-django) $ python manage.py migrate
```

Apply database fixtures:

```
(financial-chat-django) $ python manage.py loaddata users profiles chat_rooms
```

Run *Celery*:

```
(financial-chat-django) $ celery -A financial_chat_django worker -l info
```

Run the local development server:

```
(financial-chat-django) $ python manage.py runserver 0.0.0.0:8000
```

Finally, open in your favorite browser, then login as user 'john' with password 'john' or user 'bob' with password 'bob', and finally select the 'Lorem ipsum' chat room to start chatting.

If you want to ask for quotes, input the following command in the text box:

```
/stock=AAPL
```

The above example will display the *Apple* quote price as a chat message. Please note the quote names need to be uppercased for the command to work.