From: CMDR furrycat Date: Sat, 15 Apr 2017 19:49:13 +0000 (+0100) Subject: Report on systems with stale influence data. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=1df84af048e50ec5abd0fda70fad11b1c08f044f;p=furrycat%2Fcatbot.git Report on systems with stale influence data. --- diff --git a/plugin/faction/faction.py b/plugin/faction/faction.py index 6ab7bc9..dfbb241 100644 --- a/plugin/faction/faction.py +++ b/plugin/faction/faction.py @@ -294,7 +294,9 @@ class Faction(DBConnection): async def show_faction_cache(self, message): cursor = self.query('select faction_id, name from faction_names') lines = [] + faction_ids = [] for row in cursor.fetchall(): + faction_ids.append(row['faction_id']) lines.append('Faction **{}** #{}'.format(row['name'], row['faction_id'])) cursor = self.query('select eddb_id, name from faction_systems') for row in cursor.fetchall(): @@ -305,6 +307,8 @@ class Faction(DBConnection): self.close_db() if len(lines): await bot.say_many(message.channel, lines) + for tracked in self.tracked_factions: + await self.report_stale_influence(message.channel, name = tracked.name) async def list_tracked_factions(self, message): results = [] @@ -459,6 +463,7 @@ class Faction(DBConnection): self.update_tracked_faction(tracked.id, **update) await self.report_faction_influence(channel, name = tracked.name, yelp_if_no_data = False) + await self.report_stale_influence(channel, name = tracked.name) async def get_faction(self, destination, name): factions = eddb.find_faction(name) @@ -862,6 +867,27 @@ class Faction(DBConnection): self.close_db() return ret + async def report_stale_influence(self, destination, *, id = None, name = None): + if id is None: + id = self.get_faction_id(name) + if id is None: + log.error("Can't report stale influence of unknown faction {}".format(name)) + return False + + cutoff = 86400 * 2 + cursor = self.query('select s.name as system_name, max(timestamp) as latest from faction_influence i left join faction_systems s using(eddb_id) where faction_id=? group by eddb_id, faction_id having latest < ?', [id, self.now() - cutoff]) + lines = [] + for row in cursor.fetchall(): + if not len(lines): + lines = ['__Stale influence data in__'] + lines.append('**{}** last updated at *{}*'.format(row['system_name'], bot.iso8601(row['latest']))) + if len(lines): + await bot.say_many(destination, lines) + else: + log.info('No stale influence for {}'.format(name if name is not None else id)) + self.close_db() + return True + async def show_influence_report(self, message, args): name = args[0] if name == 'in':