def main(account_id): app = create_app() with app.app_context(): b = TelegramBot(account_id) b.bot.setWebhook('') b.start()
def app(): sys.modules['newsbot.test.config'] = TestingConfig app = create_app() with app.app_context(): get_db().client.drop_database(get_db().name) with app.test_request_context(): yield app
import sys from werkzeug.serving import run_simple from werkzeug.contrib.fixers import ProxyFix from newsbot.server import create_app application = create_app() application.wsgi_app = ProxyFix(application.wsgi_app) if __name__ == '__main__': run_simple(application.config.get('SERVER_HOST', 'localhost'), (sys.argv[1:] and int(sys.argv[1]) or application.config['SERVER_PORT']), application, use_reloader=True, threaded=True, extra_files='./templates/*')
ACTIVE_ACCOUNT_KEY = 'active_account_id' # TODO replace with mongomock, once FlaskMongoengine supports it MONGODB_SETTINGS = { 'db': 'test_db', 'host': 'localhost', } sys.modules['newsbot.test.config'] = TestingConfig from newsbot.server import create_app # NOQA from newsbot.models import Account, Bulletin, Fragment, Story, User # NOQA app = create_app() class BotTestCase(unittest.TestCase): app = app.test_client() def setUp(self): ctx = app.test_request_context() ctx.push() self.register_data = { 'name': 'user', 'password': '******', 'email': '*****@*****.**', 'account-name': 'company',
def create_newsbot_app(info): return create_app()
chat_user.current_fragment = None bot.sendMessage(chat_id, 'No more news for today') chat_user.save() # find more content NOT IN READ unread_bulletins = get_unread_bulletins(chat_user) if len(unread_bulletins) > 0: chat_user.current_bulletin = unread_bulletins[0] chat_user.current_story = 0 chat_user.current_fragment = 0 chat_user.save() start_story(bulletin, chat_user, chat_id) return else: chat_user.current_bulletin = None bot.sendMessage("No more bulletins to show! wait a couple " "of hours") chat_user.save() return chat_user.save() bot = telepot.Bot(settings.TELEGRAM_TOKEN) with create_app().app_context(): bot.message_loop(on_chat_message) while 1: time.sleep(10)
def main(account_id): app = create_app() with app.app_context(): b = FacebookBot(account_id) b.start(app)
from celery import Celery import telepot from telegramcelerybot import TelegramBot from flask import Flask LOCAL_BROKER = 'amqp://*****:*****@localhost/celerybot' bottasks = Celery('tasks', broker=LOCAL_BROKER) from newsbot.server import create_app flask_app = create_app() @bottasks.task(name="telegram.handle_event") def handle_event(account_id, token, event): print(account_id) print(token) print(event) b = TelegramBot(account_id) b.handle_message(event['message']) return 'OK'