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_message_id: 1367
send_to_chats:
gooanimemes:
goodanimemes:
subreddits:
- goodanimemes
cron_duration: 0 * * * *

View File

@ -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)