示例#1
0
    def test_transmit(self):
        s = Storage()
        s.storage = MagicMock()
        s.storage.status = MagicMock()

        s.status()

        self.assertEqual(s.storage.status.call_count, 1)
示例#2
0
  def test_transmit(self):
    s = Storage()
    s.storage = MagicMock()
    s.storage.record = MagicMock()

    s.record()

    self.assertEqual(s.storage.record.call_count, 1)
示例#3
0
  def test_transmit(self):
    s = Storage()
    s.storage = MagicMock()
    s.storage.status = MagicMock()

    s.status()

    self.assertEqual(s.storage.status.call_count, 1)
示例#4
0
  def test_transmit(self):
    s = Storage()
    s.storage = MagicMock()
    s.storage.cancer = MagicMock()

    s.cancer()

    self.assertEqual(s.storage.cancer.call_count, 1)
示例#5
0
    def test_transmit(self):
        s = Storage()
        s.storage = MagicMock()
        s.storage.cancer = MagicMock()

        s.cancer()

        self.assertEqual(s.storage.cancer.call_count, 1)
示例#6
0
    def test_transmit(self):
        s = Storage()
        s.storage = MagicMock()
        s.storage.record = MagicMock()

        s.record()

        self.assertEqual(s.storage.record.call_count, 1)
示例#7
0
    def test_transmit(self):
        s = Storage()
        s.storage = MagicMock()
        s.storage.search = MagicMock()
        search = "foo"

        s.search(search)

        s.storage.search.assert_called_once_with(search)
示例#8
0
    def test_transmit(self):
        s = Storage()
        s.storage = MagicMock()
        s.storage.leaderboards = MagicMock()
        horizon = "foo"

        s.leaderboards(horizon)

        s.storage.leaderboards.assert_called_once_with(horizon)
示例#9
0
  def test_transmit(self):
    s = Storage()
    s.storage = MagicMock()
    s.storage.channel = MagicMock()

    channel = "forsenlol"
    s.channel(channel)

    s.storage.channel.assert_called_once_with(channel)
示例#10
0
  def test_transmit(self):
    s = Storage()
    s.storage = MagicMock()
    s.storage.leaderboard = MagicMock()
    leaderboard = "foo"

    s.leaderboard(leaderboard)

    s.storage.leaderboard.assert_called_once_with(leaderboard)
示例#11
0
  def test_transmit(self):
    s = Storage()
    s.storage = MagicMock()
    s.storage.leaderboards = MagicMock()
    horizon = "foo"

    s.leaderboards(horizon)

    s.storage.leaderboards.assert_called_once_with(horizon)
示例#12
0
  def test_transmit(self):
    s = Storage()
    s.storage = MagicMock()
    s.storage.search = MagicMock()
    search = "foo"

    s.search(search)

    s.storage.search.assert_called_once_with(search)
示例#13
0
    def test_transmit(self):
        s = Storage()
        s.storage = MagicMock()
        s.storage.leaderboard = MagicMock()
        leaderboard = "foo"

        s.leaderboard(leaderboard)

        s.storage.leaderboard.assert_called_once_with(leaderboard)
示例#14
0
    def test_transmit(self):
        s = Storage()
        s.storage = MagicMock()
        s.storage.channel = MagicMock()

        channel = "forsenlol"
        s.channel(channel)

        s.storage.channel.assert_called_once_with(channel)
示例#15
0
  def test_transmit(self):
    s = Storage()
    s.storage = MagicMock()
    s.storage.store = MagicMock()

    channel = "forsenlol"
    message = "message"
    s.store(channel, message)

    s.storage.store.assert_called_once_with(channel, message)
示例#16
0
    def test_transmit(self):
        s = Storage()
        s.storage = MagicMock()
        s.storage.store = MagicMock()

        channel = "forsenlol"
        message = "message"
        s.store(channel, message)

        s.storage.store.assert_called_once_with(channel, message)
示例#17
0
class RequestHandler:
    __instance = None

    # poor man's singleton
    def instance():
        if RequestHandler.__instance is None:
            RequestHandler.__instance = RequestHandler()
        return RequestHandler.__instance

    def __init__(self):
        self.storage = Storage()

    # respond to a request
    def handle(self, request):
        try:
            # search_channel requests
            if request['request'] == "twitchcancer.search":
                # we need a channel to search for
                if request['data'] is not None:
                    return self.storage.search(request['data'])
        except KeyError:
            logger.warning("got a malformed request %s", request)
        except TypeError:
            logger.warning("got a malformed request %s", request)

        return {}
示例#18
0
class RequestHandler:

  __instance = None

  # poor man's singleton
  def instance():
    if RequestHandler.__instance is None:
      RequestHandler.__instance = RequestHandler()
    return RequestHandler.__instance

  def __init__(self):
    self.storage = Storage()

  # respond to a request
  def handle(self, request):
    try:
      # search_channel requests
      if request['request'] == "twitchcancer.search":
        # we need a channel to search for
        if request['data'] is not None:
          return self.storage.search(request['data'])
    except KeyError:
      logger.warning("got a malformed request %s", request)
    except TypeError:
      logger.warning("got a malformed request %s", request)

    return {}
示例#19
0
def main():
    # persist data generated by monitor
    parser = argparse.ArgumentParser()
    parser.add_argument('-l',
                        '--log',
                        dest='loglevel',
                        help="set the level of messages to display")
    parser.add_argument('-c',
                        '--config',
                        dest='config',
                        help="load configuration from this file")

    args = parser.parse_args()
    if args.config:
        Config.load(args.config)
    setup_logger(logger, args.loglevel, Config, "record.log")

    # start recording forever
    storage = Storage()
    storage.record()
示例#20
0
async def create_publishers():
    # setup storage
    storage = Storage()

    # list of topics clients can subscribe to
    topics = [
        PubSubTopic('twitchcancer.live', storage.cancer, 1),
        PubSubVariableTopic('twitchcancer.leaderboards.*',
                            storage.leaderboards, 60),
        PubSubVariableTopic('twitchcancer.leaderboard.*', storage.leaderboard,
                            60),
        PubSubTopic('twitchcancer.status', storage.status, 3),
        PubSubVariableTopic('twitchcancer.channel.*', storage.channel, 60),
    ]

    # add publisher tasks to the loop
    tasks = [publish(topic) for topic in topics]
    logger.info('added publisher topics: %s', ', '.join(map(str, topics)))

    await asyncio.gather(*tasks)
示例#21
0
import logging
import re

from autobahn.asyncio.websocket import WebSocketClientProtocol
from typing import Optional

from twitchcancer.config import Config
from twitchcancer.storage.storage import Storage
from twitchcancer.symptom.diagnosis import Diagnosis

logger = logging.getLogger(__name__)

diagnosis = Diagnosis()
storage = Storage()


async def record(parsed):
    # compute points for the message
    points = diagnosis.points(parsed['message'])

    # store cancer records for later
    storage.store(parsed['channel'], points)
    # print(parsed['channel'], points)


class TwitchClient(WebSocketClientProtocol):
    def onOpen(self):  # noqa
        self.sendMessage('CAP REQ :twitch.tv/membership'.encode())
        self.sendMessage('PASS {0}'.format(
            Config.get("monitor.chat.password").lower()).encode())
        self.sendMessage('NICK {0}'.format(
示例#22
0
 def __init__(self):
     self.storage = Storage()
示例#23
0
 def __init__(self):
   self.storage = Storage()