def run(self): logger.info('Twitch Checker is started') # Skip 1st notify if channels are already live before plugin load self._set_live_channels(self._twitch.get_live_channels()) while(not self._stop.is_set()): logger.debug('Wait polling {} sec.'.format(self._period)) self._polling.wait(self._period) logger.debug('Polling event is triggered.') self._polling.clear() logger.debug('Try get live channels') current_live_channels = self._twitch.get_live_channels() logger.debug('Live Channels: ' + str(current_live_channels.viewkeys())) local_live_channels = self.get_live_channels() logger.debug('Previous live Channels: ' + str(local_live_channels.viewkeys())) off_channels = local_live_channels.viewkeys() - current_live_channels.viewkeys() for ch in off_channels: # TODO do we have to notify user the channel went off? del local_live_channels[ch] new_live_channels = current_live_channels.viewkeys() - local_live_channels.viewkeys() # Send live notifications to subcribers for ch in new_live_channels: local_live_channels[ch] = current_live_channels[ch] local_sublist = self._get_sublist() for user in local_sublist: if ch in local_sublist[user]: msg = io.BytesIO() print('{} is now streamming!!'.format(ch), file=msg) print('msg = [Title] {}'.format(current_live_channels[ch]['status']), file=msg) print('[Playing] {}'.format(current_live_channels[ch]['game']), file=msg) print(current_live_channels[ch]['url'], file=msg) user.send_message(msg.getvalue()) self._set_live_channels(local_live_channels) self._stop.clear() logger.info('Twitch Checker is stopped')
def __init__(self): self._client = LineClientP( config['interface']['line']['account'], config['interface']['line']['password'] ) logger.debug('log-in done.') self._client.updateAuthToken() logger.debug('update auth done.')
def find_and_import_interface_class(ifmod): for name, obj in inspect.getmembers(ifmod): if inspect.isclass(obj) and issubclass(obj, BaseInterface) and obj.NAME is not None: logger.debug("Found interface class: " + str(obj)) if obj.NAME in class_dict: raise NameError("Interface name conflict: ".format(class_dict[obj.NAME], obj)) else: class_dict[obj.NAME] = obj
def find_and_import_interface_class(ifmod): for name, obj in inspect.getmembers(ifmod): if inspect.isclass(obj) and issubclass(obj, BaseInterface) and obj.NAME is not None: logger.debug("Found interface class: " + str(obj)) if obj.NAME == "test" and "nose" not in sys.modules: # pragma: no cover continue # skip test interface if we are not running test sutie if obj.NAME in class_dict: raise NameError("Interface name conflict: ".format(class_dict[obj.NAME], obj)) else: class_dict[obj.NAME] = obj
def _start(self): # Load subscribe list try: logger.debug('Loading subscribe list from file') self._sublist = pickle.load(open(self.SUB_FILE, 'rb')) self._calculate_channel_sub_count() except IOError: logger.debug('Subscribe list file not found, create empty.') self._sublist = defaultdict(list) self._channel_sub_count = defaultdict(int) self._check_thread = Checker( self.CHECK_PERIOD, self._twitch, self.get_sublist) self._check_thread.start()
def _twitch_process(cls, action, url, pms, **kwargs): twitch_api_url = cls.TWITCH_API_BASE + url if pms is None: pms_a = {} else: pms_a = pms pms_a["oauth_token"] = cls.OAUTH_TOKEN logger.debug("[{}] Url = {}".format(str(action.__name__), str(twitch_api_url))) ret = action(twitch_api_url, params=pms_a, **kwargs) logger.debug("Return Code = {}".format(ret.status_code)) if ret.status_code not in cls.IGNORE_STATUS: return ret.json() else: return {"code": ret.status_code}
def _twitch_process(cls, action, url, pms, **kwargs): twitch_api_url = cls.TWITCH_API_BASE + url if pms is None: pms_a = {} else: pms_a = pms pms_a['oauth_token'] = cls.OAUTH_TOKEN logger.debug('[{}] Url = {}'.format(str(action.__name__), str(twitch_api_url))) ret = action(twitch_api_url, params=pms_a, **kwargs) logger.debug('Return Code = {}'.format(ret.status_code)) if ret.status_code not in cls.IGNORE_STATUS: return ret.json() else: return {'code': ret.status_code}
def run(self): logger.info('Twitch Checker is started') # Skip 1st notify if channels are already live before plugin load self._set_live_channels(self._twitch.get_live_channels()) while (not self._stop.is_set()): logger.debug('Wait polling {} sec.'.format(self._period)) self._polling.wait(self._period) logger.debug('Polling event is triggered.') self._polling.clear() logger.debug('Try get live channels') current_live_channels = self._twitch.get_live_channels() logger.debug('Live Channels: ' + str(current_live_channels.viewkeys())) local_live_channels = self.get_live_channels() logger.debug('Previous live Channels: ' + str(local_live_channels.viewkeys())) off_channels = local_live_channels.viewkeys( ) - current_live_channels.viewkeys() for ch in off_channels: # TODO do we have to notify user the channel went off? del local_live_channels[ch] new_live_channels = current_live_channels.viewkeys( ) - local_live_channels.viewkeys() # Send live notifications to subcribers for ch in new_live_channels: local_live_channels[ch] = current_live_channels[ch] local_sublist = self._get_sublist() for user in local_sublist: if ch in local_sublist[user]: msg = io.BytesIO() print('{} is now streamming!!'.format(ch), file=msg) print('msg = [Title] {}'.format( current_live_channels[ch]['status']), file=msg) print('[Playing] {}'.format( current_live_channels[ch]['game']), file=msg) print(current_live_channels[ch]['url'], file=msg) user.send_message(msg.getvalue()) self._set_live_channels(local_live_channels) self._stop.clear() logger.info('Twitch Checker is stopped')
def _sub_by_url(self, match_iter, cmd, sender): logger.debug('sub by url: ' + str(match_iter)) logger.debug('sub by url, direct cmd: ' + cmd) self._subscribe(match_iter, sender)
def __init__(self): self._client = LineClientP(config['interface']['line']['account'], config['interface']['line']['password']) logger.debug('log-in done.') self._client.updateAuthToken() logger.debug('update auth done.')
def stop(self): self.async_stop() logger.debug('waiting for thread end') self.join()
def async_stop(self): logger.debug('stop is called') self._polling.set() self._stop.set()
def refresh(self): logger.debug('Trigger refresh') self._polling.set()