From 1ea76cd902cfc19986389a52adda70a8bb4555db Mon Sep 17 00:00:00 2001 From: SetazeR Date: Mon, 15 Jul 2019 14:00:38 +0700 Subject: [PATCH] remove unnecessary loop definitions --- examples/broadcast_example.py | 5 ++--- examples/callback_data_factory.py | 4 ++-- examples/check_user_language.py | 4 ++-- examples/finite_state_machine_example.py | 6 ++---- examples/inline_bot.py | 5 ++--- examples/media_group.py | 5 ++--- examples/middleware_and_antiflood.py | 6 ++---- examples/payments.py | 5 ++--- examples/proxy_and_emojize.py | 5 ++--- examples/throtling_example.py | 5 ++--- examples/webhook_example.py | 3 +-- examples/webhook_example_2.py | 3 +-- 12 files changed, 22 insertions(+), 34 deletions(-) diff --git a/examples/broadcast_example.py b/examples/broadcast_example.py index 9e654d44..2891bb30 100644 --- a/examples/broadcast_example.py +++ b/examples/broadcast_example.py @@ -9,9 +9,8 @@ API_TOKEN = 'BOT TOKEN HERE' logging.basicConfig(level=logging.INFO) log = logging.getLogger('broadcast') -loop = asyncio.get_event_loop() -bot = Bot(token=API_TOKEN, loop=loop, parse_mode=types.ParseMode.HTML) -dp = Dispatcher(bot, loop=loop) +bot = Bot(token=API_TOKEN, parse_mode=types.ParseMode.HTML) +dp = Dispatcher(bot) def get_users(): diff --git a/examples/callback_data_factory.py b/examples/callback_data_factory.py index 3dd7d35e..8fd197df 100644 --- a/examples/callback_data_factory.py +++ b/examples/callback_data_factory.py @@ -13,8 +13,8 @@ logging.basicConfig(level=logging.INFO) API_TOKEN = 'BOT TOKEN HERE' -loop = asyncio.get_event_loop() -bot = Bot(token=API_TOKEN, loop=loop, parse_mode=types.ParseMode.HTML) + +bot = Bot(token=API_TOKEN, parse_mode=types.ParseMode.HTML) storage = MemoryStorage() dp = Dispatcher(bot, storage=storage) dp.middleware.setup(LoggingMiddleware()) diff --git a/examples/check_user_language.py b/examples/check_user_language.py index bd0ba7f9..f59246cf 100644 --- a/examples/check_user_language.py +++ b/examples/check_user_language.py @@ -11,8 +11,8 @@ API_TOKEN = 'BOT TOKEN HERE' logging.basicConfig(level=logging.INFO) -loop = asyncio.get_event_loop() -bot = Bot(token=API_TOKEN, loop=loop, parse_mode=types.ParseMode.MARKDOWN) + +bot = Bot(token=API_TOKEN, parse_mode=types.ParseMode.MARKDOWN) dp = Dispatcher(bot) diff --git a/examples/finite_state_machine_example.py b/examples/finite_state_machine_example.py index 90ab8aba..66f89fb2 100644 --- a/examples/finite_state_machine_example.py +++ b/examples/finite_state_machine_example.py @@ -11,9 +11,7 @@ from aiogram.utils import executor API_TOKEN = 'BOT TOKEN HERE' -loop = asyncio.get_event_loop() - -bot = Bot(token=API_TOKEN, loop=loop) +bot = Bot(token=API_TOKEN) # For example use simple MemoryStorage for Dispatcher. storage = MemoryStorage() @@ -117,4 +115,4 @@ async def process_gender(message: types.Message, state: FSMContext): if __name__ == '__main__': - executor.start_polling(dp, loop=loop, skip_updates=True) + executor.start_polling(dp, skip_updates=True) diff --git a/examples/inline_bot.py b/examples/inline_bot.py index 4a771210..f1a81bb4 100644 --- a/examples/inline_bot.py +++ b/examples/inline_bot.py @@ -7,8 +7,7 @@ API_TOKEN = 'BOT TOKEN HERE' logging.basicConfig(level=logging.DEBUG) -loop = asyncio.get_event_loop() -bot = Bot(token=API_TOKEN, loop=loop) +bot = Bot(token=API_TOKEN) dp = Dispatcher(bot) @@ -21,4 +20,4 @@ async def inline_echo(inline_query: types.InlineQuery): if __name__ == '__main__': - executor.start_polling(dp, loop=loop, skip_updates=True) + executor.start_polling(dp, skip_updates=True) diff --git a/examples/media_group.py b/examples/media_group.py index b1f5246a..eafbac6a 100644 --- a/examples/media_group.py +++ b/examples/media_group.py @@ -4,8 +4,7 @@ from aiogram import Bot, Dispatcher, executor, filters, types API_TOKEN = 'BOT TOKEN HERE' -loop = asyncio.get_event_loop() -bot = Bot(token=API_TOKEN, loop=loop) +bot = Bot(token=API_TOKEN) dp = Dispatcher(bot) @@ -40,4 +39,4 @@ async def send_welcome(message: types.Message): if __name__ == '__main__': - executor.start_polling(dp, loop=loop, skip_updates=True) + executor.start_polling(dp, skip_updates=True) diff --git a/examples/middleware_and_antiflood.py b/examples/middleware_and_antiflood.py index c579aecc..4a0cc491 100644 --- a/examples/middleware_and_antiflood.py +++ b/examples/middleware_and_antiflood.py @@ -9,12 +9,10 @@ from aiogram.utils.exceptions import Throttled TOKEN = 'BOT TOKEN HERE' -loop = asyncio.get_event_loop() - # In this example Redis storage is used storage = RedisStorage2(db=5) -bot = Bot(token=TOKEN, loop=loop) +bot = Bot(token=TOKEN) dp = Dispatcher(bot, storage=storage) @@ -119,4 +117,4 @@ if __name__ == '__main__': dp.middleware.setup(ThrottlingMiddleware()) # Start long-polling - executor.start_polling(dp, loop=loop) + executor.start_polling(dp) diff --git a/examples/payments.py b/examples/payments.py index e8e37011..a01fbaf3 100644 --- a/examples/payments.py +++ b/examples/payments.py @@ -9,9 +9,8 @@ from aiogram.utils import executor BOT_TOKEN = 'BOT TOKEN HERE' PAYMENTS_PROVIDER_TOKEN = '123456789:TEST:1234567890abcdef1234567890abcdef' -loop = asyncio.get_event_loop() bot = Bot(BOT_TOKEN) -dp = Dispatcher(bot, loop=loop) +dp = Dispatcher(bot) # Setup prices prices = [ @@ -96,4 +95,4 @@ async def got_payment(message: types.Message): if __name__ == '__main__': - executor.start_polling(dp, loop=loop) + executor.start_polling(dp) diff --git a/examples/proxy_and_emojize.py b/examples/proxy_and_emojize.py index 7e4452ee..17e33872 100644 --- a/examples/proxy_and_emojize.py +++ b/examples/proxy_and_emojize.py @@ -25,8 +25,7 @@ GET_IP_URL = 'http://bot.whatismyipaddress.com/' logging.basicConfig(level=logging.INFO) -loop = asyncio.get_event_loop() -bot = Bot(token=API_TOKEN, loop=loop, proxy=PROXY_URL) +bot = Bot(token=API_TOKEN, proxy=PROXY_URL) dp = Dispatcher(bot) @@ -62,4 +61,4 @@ async def cmd_start(message: types.Message): if __name__ == '__main__': - start_polling(dp, loop=loop, skip_updates=True) + start_polling(dp, skip_updates=True) diff --git a/examples/throtling_example.py b/examples/throtling_example.py index b979a979..2641b44b 100644 --- a/examples/throtling_example.py +++ b/examples/throtling_example.py @@ -17,8 +17,7 @@ API_TOKEN = 'BOT TOKEN HERE' logging.basicConfig(level=logging.INFO) -loop = asyncio.get_event_loop() -bot = Bot(token=API_TOKEN, loop=loop) +bot = Bot(token=API_TOKEN) # Throttling manager does not work without Leaky Bucket. # Then need to use storages. For example use simple in-memory storage. @@ -40,4 +39,4 @@ async def send_welcome(message: types.Message): if __name__ == '__main__': - start_polling(dp, loop=loop, skip_updates=True) + start_polling(dp, skip_updates=True) diff --git a/examples/webhook_example.py b/examples/webhook_example.py index 86520988..0f6ae3cd 100644 --- a/examples/webhook_example.py +++ b/examples/webhook_example.py @@ -37,8 +37,7 @@ WEBAPP_PORT = 3001 BAD_CONTENT = ContentTypes.PHOTO & ContentTypes.DOCUMENT & ContentTypes.STICKER & ContentTypes.AUDIO -loop = asyncio.get_event_loop() -bot = Bot(TOKEN, loop=loop) +bot = Bot(TOKEN) storage = MemoryStorage() dp = Dispatcher(bot, storage=storage) diff --git a/examples/webhook_example_2.py b/examples/webhook_example_2.py index 75b29c75..e2d9225c 100644 --- a/examples/webhook_example_2.py +++ b/examples/webhook_example_2.py @@ -18,8 +18,7 @@ WEBAPP_PORT = 3001 logging.basicConfig(level=logging.INFO) -loop = asyncio.get_event_loop() -bot = Bot(token=API_TOKEN, loop=loop) +bot = Bot(token=API_TOKEN) dp = Dispatcher(bot)