def test_unset(self): config.unset((), "a") config.unset(("b", ), "c") config.unset(("a", ), "d") config.unset(("b", ), "d") config.unset(("c", ), "d") self.assertEqual(config.get((), "a"), None) self.assertEqual(config.get(("b", ), "a"), 2) self.assertEqual(config.get(("b", ), "c"), None) self.assertEqual(config.get(("a", ), "d"), None) self.assertEqual(config.get(("b", ), "d"), None) self.assertEqual(config.get(("c", ), "d"), None)
def test_accumulate(self): self.assertEqual(config.accumulate((), "l"), []) config.set(() , "l", [5, 6]) config.set(("c",) , "l", [3, 4]) config.set(("c", "c"), "l", [1, 2]) self.assertEqual( config.accumulate((), "l") , [5, 6]) self.assertEqual( config.accumulate(("c",), "l") , [3, 4, 5, 6]) self.assertEqual( config.accumulate(("c", "c"), "l"), [1, 2, 3, 4, 5, 6]) config.set(("c",), "l", None) config.unset(("c", "c"), "l") self.assertEqual( config.accumulate((), "l") , [5, 6]) self.assertEqual( config.accumulate(("c",), "l") , [5, 6]) self.assertEqual( config.accumulate(("c", "c"), "l"), [5, 6])
def test_unset(self): config.unset(["a"]) config.unset(["b", "c"]) config.unset(["c", "d"]) self.assertEqual(config.get(["a"]), None) self.assertEqual(config.get(["b", "a"]), 2) self.assertEqual(config.get(["b", "c"]), None)
async def _main_task(params): try: bot = Bot(params['BOT_TOKEN']) msg = params['message'] chat_id = msg['chat']['id'] msg_txt = msg.get('text') print(msg) if not msg_txt: await bot.send_message(chat_id, 'Please send me url to image') return if msg_txt == '/start': await bot.send_message( chat_id, 'Send me url to image and i\'ll upload it to telegram') return if msg_txt == '/version': await bot.send_message(chat_id, 'gallery-dl version: ' + gdl_version) return cmd = cmd_from_message(msg) if cmd is not None: if cmd == 'all': # retrieve all avalibale links config.unset(("extractor", ), "image-range") elif cmd == 'p': # granular image links extraction pic_range_re = re.compile('([0-9]+)(-([0-9]+))?') pic_range_match = pic_range_re.search(msg_txt) if pic_range_match is None: await bot.send_message( chat_id, 'Wrong command, correct example: /p 3-10 manga.com/chapter1' ) return start, _, end = pic_range_match.groups() if end is None: config.set(("extractor", ), "image-range", start) elif int(start) > int(end): await bot.send_message( chat_id, 'Start number bigger then end, correct example: /p 3-10 manga.com/chapter1' ) return else: config.set(("extractor", ), "image-range", start + '-' + end) try: await handle_request(bot, chat_id, msg_txt) except NoUrlError: if msg['chat']['type'] == 'private': if cmd is not None: if cmd == 'all': await bot.send_message( chat_id, 'Wrong command, correct example: /all manga.com/chapter1' ) elif cmd == 'p': await bot.send_message( chat_id, 'Wrong command, correct example: /p 3-10 manga.com/chapter1' ) else: await bot.send_message( chat_id, 'Couldn\'t find any url in message, send me one') print('No url in message') finally: config.set(("extractor", ), "image-range", "1") except asyncio.CancelledError: try: if msg['chat']['type'] == 'private': await bot.send_message(chat_id, 'Request timeout') except TelegramAPIError as e: print(e.__class__.__name__ + ': ' + str(e)) raise except exception.NoExtractorError: try: if msg['chat']['type'] == 'private': await bot.send_message(chat_id, 'ERROR: Unsupported URL') except TelegramAPIError as e: print(e.__class__.__name__ + ': ' + str(e)) except Exception as e: try: if msg['chat']['type'] == 'private': await bot.send_message(chat_id, 'ERROR: ' + str(e)) except TelegramAPIError as e: print(e.__class__.__name__ + ': ' + str(e)) traceback.print_exc()