From 98c80c598d2fd3a440d815c5a1422027eeb33880 Mon Sep 17 00:00:00 2001 From: gotlium Date: Mon, 15 Feb 2016 18:01:33 +0500 Subject: [PATCH] update docs --- docs/deploy.rst | 2 +- docs/usage.rst | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/deploy.rst b/docs/deploy.rst index cf4a558..3c94a59 100644 --- a/docs/deploy.rst +++ b/docs/deploy.rst @@ -20,7 +20,7 @@ Login as `matterbot`:: sudo -i -u matterbot -Clone your project:: +Clone your project (before create git repository with `settings.py`):: $ git clone https://github.com/USER/REPO.git ~/mybot diff --git a/docs/usage.rst b/docs/usage.rst index 890cb66..848df26 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -19,3 +19,49 @@ Run the bot:: $ MATTERMOST_BOT_SETTINGS_MODULE=settings matterbot + +Integration with Django +----------------------- + +Create bot_settings on your project and after you can create `django` command:: + + import logging + import sys + + from django.core.management.base import BaseCommand + from django.conf import settings + + from mattermost_bot import bot, settings + + + class Command(BaseCommand): + + def handle(self, **options): + + logging.basicConfig(**{ + 'format': '[%(asctime)s] %(message)s', + 'datefmt': '%m/%d/%Y %H:%M:%S', + 'level': logging.DEBUG if settings.DEBUG else logging.INFO, + 'stream': sys.stdout, + }) + + try: + b = bot.Bot() + b.run() + except KeyboardInterrupt: + pass + + +Modify `manage.py`:: + + #!/usr/bin/env python + import os + import sys + + if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") + os.environ.setdefault("MATTERMOST_BOT_SETTINGS_MODULE", "project.bot_settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv)