Attempt to fix unknown bug where telethon disconnects without reconnecting

This commit is contained in:
blank X 2020-09-16 18:59:34 +07:00
parent e4f8b37b75
commit d878c80a64
2 changed files with 6 additions and 8 deletions

View File

@ -11,7 +11,7 @@ config:
storage_chat: -1001222674489 storage_chat: -1001222674489
storage_message_id: 1367 storage_message_id: 1367
send_to_chats: send_to_chats:
gooanimemes: goodanimemes:
subreddits: subreddits:
- goodanimemes - goodanimemes
cron_duration: 0 * * * * cron_duration: 0 * * * *

View File

@ -98,9 +98,9 @@ async def main():
async def start_post(): async def start_post():
while True: while True:
random.shuffle(subreddits) random.shuffle(subreddits)
for subreddit_name in subreddits: def _get_submission_blocc():
subreddit = reddit.subreddit(subreddit_name)
while True: while True:
subreddit = reddit.subreddit(random.choice(subreddits))
random_post = subreddit.random() random_post = subreddit.random()
cpid = cpp = None cpid = cpp = None
if random_post is None: if random_post is None:
@ -156,11 +156,9 @@ async def main():
continue continue
chat_sp.append(cpid or random_post.id) chat_sp.append(cpid or random_post.id)
print(random_post.id, random_post.shortlink) print(random_post.id, random_post.shortlink)
break return random_post, cpp
else:
continue
break
try: 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) await _actual_start_post(random_post, [chat], cpp, show_nsfw_warning, show_spoilers_warning)
except Exception: except Exception:
logging.exception(random_post.id) logging.exception(random_post.id)
@ -191,7 +189,7 @@ async def main():
async def _download_file(filename, url): async def _download_file(filename, url):
print(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: with open(filename, 'wb') as file:
while True: while True:
chunk = await resp.content.read(10) chunk = await resp.content.read(10)