From d878c80a645e4932d036f17b7b2a19ea7d4f54d7 Mon Sep 17 00:00:00 2001 From: blank X Date: Wed, 16 Sep 2020 18:59:34 +0700 Subject: [PATCH] Attempt to fix unknown bug where telethon disconnects without reconnecting --- example_config.yaml | 2 +- redditbot.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index eb86d17..a2aaf63 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -11,7 +11,7 @@ config: storage_chat: -1001222674489 storage_message_id: 1367 send_to_chats: - gooanimemes: + goodanimemes: subreddits: - goodanimemes cron_duration: 0 * * * * diff --git a/redditbot.py b/redditbot.py index 66a86be..a021496 100644 --- a/redditbot.py +++ b/redditbot.py @@ -98,9 +98,9 @@ async def main(): async def start_post(): while True: random.shuffle(subreddits) - for subreddit_name in subreddits: - subreddit = reddit.subreddit(subreddit_name) + def _get_submission_blocc(): while True: + subreddit = reddit.subreddit(random.choice(subreddits)) random_post = subreddit.random() cpid = cpp = None if random_post is None: @@ -156,11 +156,9 @@ async def main(): continue chat_sp.append(cpid or random_post.id) print(random_post.id, random_post.shortlink) - break - else: - continue - break + return random_post, cpp try: + random_post, cpp = await client.loop.run_in_executor(_get_submission_blocc) await _actual_start_post(random_post, [chat], cpp, show_nsfw_warning, show_spoilers_warning) except Exception: logging.exception(random_post.id) @@ -191,7 +189,7 @@ async def main(): async def _download_file(filename, url): print(url) - async with session.get(url) as resp: + async with session.get(url, timeout=None) as resp: with open(filename, 'wb') as file: while True: chunk = await resp.content.read(10)