Moved exception handling to poll_account, fix #10 really?

This commit is contained in:
Ville Ranki 2020-01-05 00:03:37 +02:00
parent d8d38415d1
commit 7ac37e1831
1 changed files with 17 additions and 16 deletions

View File

@ -29,8 +29,19 @@ class MatrixModule:
if now >= self.next_poll_time.get(roomid):
accounts = self.account_rooms[roomid]
for account in accounts:
try:
await self.poll_account(bot, account, roomid, send_messages)
self.first_run = False
async def poll_account(self, bot, account, roomid, send_messages):
try:
medias = self.instagram.get_medias(account, 5)
for media in medias:
if send_messages:
if media.identifier not in self.known_ids:
await bot.send_html(bot.get_room_by_id(roomid), f'<a href="{media.link}">Instagram {account}:</a> {media.caption}', f'{account}: {media.caption} {media.link}')
self.known_ids.add(media.identifier)
except InstagramNotFoundException:
print('ig error: there is ', account,
' account that does not exist - deleting from room')
@ -40,16 +51,6 @@ class MatrixModule:
print('Polling instagram account failed:')
traceback.print_exc(file=sys.stderr)
self.first_run = False
async def poll_account(self, bot, account, roomid, send_messages):
medias = self.instagram.get_medias(account, 5)
for media in medias:
if send_messages:
if media.identifier not in self.known_ids:
await bot.send_html(bot.get_room_by_id(roomid), f'<a href="{media.link}">Instagram {account}:</a> {media.caption}', f'{account}: {media.caption} {media.link}')
self.known_ids.add(media.identifier)
polldelay = timedelta(minutes=30 + randrange(30))
self.next_poll_time[roomid] = datetime.now() + polldelay