class BackendTest(TestCase): MODULE = None def __init__(self, *args, **kwargs): super(BackendTest, self).__init__(*args, **kwargs) self.backends = {} self.backend_instance = None self.backend = None self.weboob = Weboob() # Skip tests when passwords are missing self.weboob.requests.register('login', self.login_cb) if self.weboob.load_backends(modules=[self.MODULE]): # provide the tests with all available backends self.backends = self.weboob.backend_instances def login_cb(self, backend_name, value): raise SkipTest('missing config \'%s\' is required for this test' % value.label) def run(self, result): """ Call the parent run() for each backend instance. Skip the test if we have no backends. """ # This is a hack to fix an issue with nosetests running # with many tests. The default is 1000. sys.setrecursionlimit(10000) try: if not len(self.backends): self.backend = self.weboob.build_backend(self.MODULE, nofail=True) TestCase.run(self, result) else: # Run for all backend for backend_instance in self.backends.keys(): print(backend_instance) self.backend = self.backends[backend_instance] TestCase.run(self, result) finally: self.weboob.deinit() def shortDescription(self): """ Generate a description with the backend instance name. """ # do not use TestCase.shortDescription as it returns None return '%s [%s]' % (str(self), self.backend_instance) def is_backend_configured(self): """ Check if the backend is in the user configuration file """ return self.weboob.backends_config.backend_exists( self.backend.config.instname)
class MyThread(Thread): daemon = True def __init__(self, bot): Thread.__init__(self) self.weboob = Weboob(storage=StandardStorage(STORAGE_FILE)) self.weboob.load_backends() self.bot = bot self.bot.weboob = self.weboob def run(self): for ev in self.bot.joined.itervalues(): ev.wait() self.weboob.repeat(300, self.check_board) self.weboob.repeat(600, self.check_dlfp) self.weboob.loop() def find_keywords(self, text): for word in [ 'weboob', 'videoob', 'havesex', 'havedate', 'monboob', 'boobmsg', 'flatboob', 'boobill', 'pastoob', 'radioob', 'translaboob', 'traveloob', 'handjoob', 'boobathon', 'boobank', 'boobtracker', 'comparoob', 'wetboobs', 'webcontentedit', 'weboorrents', u'sàt', u'salut à toi', 'assnet', 'budget insight', 'budget-insight', 'budgetinsight', 'budgea' ]: if word in text.lower(): return word return None def check_dlfp(self): for backend, msg in self.weboob.do('iter_unread_messages', backends=['dlfp']): word = self.find_keywords(msg.content) if word is not None: url = msg.signature[msg.signature.find('https://linuxfr'):] self.bot.send_message('[DLFP] %s talks about %s: %s' % (msg.sender, word, url)) backend.set_message_read(msg) def check_board(self): def iter_messages(backend): with backend.browser: return backend.browser.iter_new_board_messages() for backend, msg in self.weboob.do(iter_messages, backends=['dlfp']): word = self.find_keywords(msg.message) if word is not None and msg.login != 'moules': message = msg.message.replace(word, '\002%s\002' % word) self.bot.send_message('[DLFP] <%s> %s' % (msg.login, message)) def stop(self): self.weboob.want_stop() self.weboob.deinit()
class BackendTest(TestCase): MODULE = None def __init__(self, *args, **kwargs): super(BackendTest, self).__init__(*args, **kwargs) self.backends = {} self.backend_instance = None self.backend = None self.weboob = Weboob() # Skip tests when passwords are missing self.weboob.requests.register('login', self.login_cb) if self.weboob.load_backends(modules=[self.MODULE]): # provide the tests with all available backends self.backends = self.weboob.backend_instances def login_cb(self, backend_name, value): raise SkipTest('missing config \'%s\' is required for this test' % value.label) def run(self, result): """ Call the parent run() for each backend instance. Skip the test if we have no backends. """ # This is a hack to fix an issue with nosetests running # with many tests. The default is 1000. sys.setrecursionlimit(10000) try: if not len(self.backends): self.backend = self.weboob.build_backend(self.MODULE, nofail=True) TestCase.run(self, result) else: # Run for all backend for backend_instance in self.backends.keys(): print(backend_instance) self.backend = self.backends[backend_instance] TestCase.run(self, result) finally: self.weboob.deinit() def shortDescription(self): """ Generate a description with the backend instance name. """ # do not use TestCase.shortDescription as it returns None return '%s [%s]' % (str(self), self.backend_instance) def is_backend_configured(self): """ Check if the backend is in the user configuration file """ return self.weboob.backends_config.backend_exists(self.backend.config.instname)
class MyThread(Thread): daemon = True def __init__(self, bot): Thread.__init__(self) self.weboob = Weboob(storage=StandardStorage(STORAGE_FILE)) self.weboob.load_backends() self.bot = bot self.bot.set_weboob(self.weboob) def run(self): for ev in self.bot.joined.itervalues(): ev.wait() self.weboob.repeat(300, self.check_board) self.weboob.repeat(600, self.check_dlfp) self.weboob.loop() def find_keywords(self, text): for word in [ 'weboob', 'videoob', 'havesex', 'havedate', 'monboob', 'boobmsg', 'flatboob', 'boobill', 'pastoob', 'radioob', 'translaboob', 'traveloob', 'handjoob', 'boobathon', 'boobank', 'boobtracker', 'comparoob', 'wetboobs', 'webcontentedit', 'weboorrents', u'sàt', u'salut à toi', 'assnet', 'budget insight', 'budget-insight', 'budgetinsight', 'budgea']: if word in text.lower(): return word return None def check_dlfp(self): for backend, msg in self.weboob.do('iter_unread_messages', backends=['dlfp']): word = self.find_keywords(msg.content) if word is not None: url = msg.signature[msg.signature.find('https://linuxfr'):] self.bot.send_message('[DLFP] %s talks about %s: %s' % ( msg.sender, word, url)) backend.set_message_read(msg) def check_board(self): def iter_messages(backend): with backend.browser: return backend.browser.iter_new_board_messages() for backend, msg in self.weboob.do(iter_messages, backends=['dlfp']): word = self.find_keywords(msg.message) if word is not None and msg.login != 'moules': message = msg.message.replace(word, '\002%s\002' % word) self.bot.send_message('[DLFP] <%s> %s' % (msg.login, message)) def stop(self): self.weboob.want_stop() self.weboob.deinit()
class BackendTest(TestCase): MODULE = None def __init__(self, *args, **kwargs): TestCase.__init__(self, *args, **kwargs) self.backends = {} self.backend_instance = None self.backend = None self.weboob = Weboob() if self.weboob.load_backends(modules=[self.MODULE]): # provide the tests with all available backends self.backends = self.weboob.backend_instances # chose one backend (enough for most tests) self.backend_instance = choice(self.backends.keys()) self.backend = self.backends[self.backend_instance] def run(self, result): """ Call the parent run() for each backend instance. Skip the test if we have no backends. """ # This is a hack to fix an issue with nosetests running # with many tests. The default is 1000. sys.setrecursionlimit(10000) try: if not len(self.backends): result.startTest(self) result.stopTest(self) raise SkipTest('No backends configured for this module.') TestCase.run(self, result) finally: self.weboob.deinit() def shortDescription(self): """ Generate a description with the backend instance name. """ # do not use TestCase.shortDescription as it returns None return '%s [%s]' % (str(self), self.backend_instance)
class MyThread(Thread): daemon = True def __init__(self, bot): Thread.__init__(self) self.weboob = Weboob(storage=StandardStorage(STORAGE_FILE)) self.weboob.load_backends() self.bot = bot self.bot.set_weboob(self.weboob) def run(self): for ev in self.bot.joined.itervalues(): ev.wait() self.weboob.repeat(300, self.check_board) self.weboob.repeat(600, self.check_dlfp) self.weboob.repeat(600, self.check_twitter) self.weboob.loop() def find_keywords(self, text): for word in [ 'weboob', 'videoob', 'havesex', 'havedate', 'monboob', 'boobmsg', 'flatboob', 'boobill', 'pastoob', 'radioob', 'translaboob', 'traveloob', 'handjoob', 'boobathon', 'boobank', 'boobtracker', 'comparoob', 'wetboobs', 'webcontentedit', 'weboorrents', 'assnet', 'budget insight', 'budget-insight', 'budgetinsight', 'budgea']: if word in text.lower(): return word return None def check_twitter(self): nb_tweets = 10 for backend in self.weboob.iter_backends(module='twitter'): for thread in list(itertools.islice(backend.iter_resources(None, ['search', 'weboob']), 0, nb_tweets)): if not backend.storage.get('lastpurge'): backend.storage.set('lastpurge', datetime.now() - timedelta(days=60)) backend.storage.save() if thread.id not in backend.storage.get('seen', default={}) and\ thread.date > backend.storage.get('lastpurge'): _item = thread.id.split('#') url = 'https://twitter.com/%s/status/%s' % (_item[0], _item[1]) for msg in self.bot.on_url(url): self.bot.send_message('%s: %s' % (_item[0], url)) self.bot.send_message(msg) backend.set_message_read(backend.fill_thread(thread, ['root']).root) def check_dlfp(self): for msg in self.weboob.do('iter_unread_messages', backends=['dlfp']): word = self.find_keywords(msg.content) if word is not None: url = msg.signature[msg.signature.find('https://linuxfr'):] self.bot.send_message('[DLFP] %s talks about %s: %s' % ( msg.sender, word, url)) self.weboob[msg.backend].set_message_read(msg) def check_board(self): def iter_messages(backend): with backend.browser: return backend.browser.iter_new_board_messages() for msg in self.weboob.do(iter_messages, backends=['dlfp']): word = self.find_keywords(msg.message) if word is not None and msg.login != 'moules': message = msg.message.replace(word, '\002%s\002' % word) self.bot.send_message('[DLFP] <%s> %s' % (msg.login, message)) def stop(self): self.weboob.want_stop() self.weboob.deinit()
class MyThread(Thread): daemon = True def __init__(self, bot): Thread.__init__(self) self.weboob = Weboob(storage=StandardStorage(STORAGE_FILE)) self.weboob.load_backends() self.bot = bot self.bot.set_weboob(self.weboob) def run(self): for ev in self.bot.joined.values(): ev.wait() self.weboob.repeat(5, self.check_tasks) self.weboob.repeat(300, self.check_board) self.weboob.repeat(600, self.check_dlfp) self.weboob.repeat(600, self.check_twitter) self.weboob.loop() def find_keywords(self, text): for word in [ 'weboob', 'videoob', 'havesex', 'havedate', 'monboob', 'boobmsg', 'flatboob', 'boobill', 'pastoob', 'radioob', 'translaboob', 'traveloob', 'handjoob', 'boobathon', 'boobank', 'boobtracker', 'comparoob', 'wetboobs', 'webcontentedit', 'weboorrents', 'assnet', 'budget insight', 'budget-insight', 'budgetinsight', 'budgea']: if word in text.lower(): return word return None def check_twitter(self): nb_tweets = 10 for backend in self.weboob.iter_backends(module='twitter'): for thread in list(itertools.islice(backend.iter_resources(None, ['search', 'weboob']), 0, nb_tweets)): if not backend.storage.get('lastpurge'): backend.storage.set('lastpurge', datetime.now() - timedelta(days=60)) backend.storage.save() if thread.id not in backend.storage.get('seen', default={}) and\ thread.date > backend.storage.get('lastpurge'): _item = thread.id.split('#') url = 'https://twitter.com/%s/status/%s' % (_item[0], _item[1]) for msg in self.bot.on_url(url): self.bot.send_message('%s: %s' % (_item[0], url)) self.bot.send_message(msg) backend.set_message_read(backend.fill_thread(thread, ['root']).root) def check_dlfp(self): for msg in self.weboob.do('iter_unread_messages', backends=['dlfp']): word = self.find_keywords(msg.content) if word is not None: url = msg.signature[msg.signature.find('https://linuxfr'):] self.bot.send_message('[DLFP] %s talks about %s: %s' % ( msg.sender, word, url)) self.weboob[msg.backend].set_message_read(msg) def check_board(self): def iter_messages(backend): return backend.browser.iter_new_board_messages() for msg in self.weboob.do(iter_messages, backends=['dlfp']): word = self.find_keywords(msg.message) if word is not None and msg.login != 'moules': message = msg.message.replace(word, '\002%s\002' % word) self.bot.send_message('[DLFP] <%s> %s' % (msg.login, message)) def check_tasks(self): for task in list(self.bot.tasks_queue): if task.datetime < datetime.now(): self.bot.send_message(task.message, task.channel) self.bot.tasks_queue.remove(task) def stop(self): self.weboob.want_stop() self.weboob.deinit()