def emit(self, signal, *args): signal = str(signal) if len(args) == 1: if isinstance(args[0], tuple): args = args[0] dispatcher.send(signal, self, *args)
def _check_streams(self): if not self.stream_names: return global _timer output = [] try: data = self.retrieve_stream_data(self.stream_names) except: data = dict() for stream, params in data.iteritems(): if not params: self.cache.set(stream, STATUS_OFFLINE) continue try: previous_state = int(self.cache.get(stream)) except (TypeError, ValueError): previous_state = None if previous_state in (None, STATUS_OFFLINE): output.append(MESSAGE_TEMPLATE.format(**params)) self.cache.set(stream, STATUS_ONLINE) if self.whitelist and output: message = "\n".join(output) responses = dispatcher.send(signals.REQUEST_CHATS) chats = responses[0] for chat in chats: if chat_is_whitelisted(chat, self.whitelist): self.output.append(ChatMessage(chat, message)) _timer = Timer(self.check_interval, self._check_streams) _timer.daemon = True _timer.start()
def _notify_chats(self, names): substitutes = { "name": humanize_names_list(names), "interjection": random.choice(INTERJECTIONS), } message = TODAY.format(**substitutes) if self.whitelist: # for chat in self.whitelist: # self.output.append(ChatMessage(chat, message)) responses = dispatcher.send(signals.REQUEST_CHATS) chats = responses[0] for chat in chats: if chat_is_whitelisted(chat, self.whitelist): self.output.append(ChatMessage(chat, message))