def send_message(msg):
    import json
    import requests
    logger.debug(msg)
    assert isinstance(msg, Message)
    data = msg.to_dict()
    data_string = json.dumps(data)
    broadcast(data_string)
    loggert = logging.getLogger("request")
    def print_url(r, *args, **kwargs):
        loggert.info(r.url)
    # end def
    while (True):
        try:
            requests.put(DATABASE_URL, data=data_string, hooks=dict(response=print_url))
            break
        except requests.RequestException as e:
            logger.warning("Failed to report message to db: {e}".format(e=e))
        # end def
        return
Esempio n. 2
0
# -*- coding: utf-8 -*-
from luckydonaldUtils.logger import logging

__author__ = 'luckydonald'
logger = logging.getLogger(__name__)

__all__ = ['mongo', 'pony_orm', 'simple']
Esempio n. 3
0
# -*- coding: utf-8 -*-
import os
import unittest

from flask import Flask
from luckydonaldUtils.logger import logging
from pytgbot.api_types.receivable.updates import Update

from teleflask.server.mixins import UpdatesMixin

__author__ = 'luckydonald'
logger = logging.getLogger(__name__)


class Foo(UpdatesMixin):
    def __init__(self, callback_status, *args, **kwargs):
        self.callback_status = callback_status
        super().__init__(*args, **kwargs)
    # end def

    def process_result(self, update, result):
        """
        Give a process_result implementation,
        This would normal be added by :class:`TeleflaskMixinBase`.

        Here we just store the result in `self.callback_status`, for unit test checks.

        :param update: 'le Update.
        :return: None, in this case.
        """
        self.callback_status["processed_update"] = (update, result)