def test_transmit(self): s = Storage() s.storage = MagicMock() s.storage.status = MagicMock() s.status() self.assertEqual(s.storage.status.call_count, 1)
def test_transmit(self): s = Storage() s.storage = MagicMock() s.storage.record = MagicMock() s.record() self.assertEqual(s.storage.record.call_count, 1)
def test_transmit(self): s = Storage() s.storage = MagicMock() s.storage.cancer = MagicMock() s.cancer() self.assertEqual(s.storage.cancer.call_count, 1)
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)
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)
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)
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)
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)
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 {}
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()
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)
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(
def __init__(self): self.storage = Storage()