# Convert to list because we will be sharing the cursor.
for announcement in list(db.get_announcements(client)):
yield from announce(announcement)
+
+ # Delete old announcements.
+ now = int(time.time())
+ for announcement in db.get_all_announcements(client):
+ if announcement['asap'] == 'true':
+ # Don't delete announcements that were requested ASAP.
+ continue
+ if not announcement['last_spoke']:
+ # Don't delete announcements that haven't played yet.
+ continue
+ if now - announcement['last_spoke'] < max(announcement['interval'], 86400):
+ # Don't delete announcements that aren't old.
+ continue
+ if announcement['interval']:
+ if not announcement['end_date']:
+ # Don't delete ongoing announcements.
+ continue
+ if announcement['end_date'] > now:
+ # Don't delete announcements that still have time to run.
+ continue
+ if dryrun:
+ log.info("Would delete old announcement {}".format(announcement['id']))
+ else:
+ if db.delete_announcement(client, announcement['id']):
+ log.info('Deleted old announcement {}'.format(announcement['id']))
+ else:
+ log.info('Failed to delete old announcement {}'.format(announcement['id']))
+
yield from asyncio.sleep(waittime)
@asyncio.coroutine