From 219ff4e88775fe9e350d584b2d62b290c4a3f68a Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Sat, 18 Feb 2017 12:45:15 +0000 Subject: [PATCH] Show update times for shopping list. --- bot.py | 9 +++++++++ plugin/shopping/shopping.py | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index f6aeb4b..d2c74f2 100644 --- a/bot.py +++ b/bot.py @@ -578,6 +578,15 @@ def set_role(member, role, minimum = 1): def iso8601(timestamp): return datetime.datetime.utcfromtimestamp(timestamp).isoformat()[:19] + 'Z' +def ago(timestamp): + now = int(time.time()) + if now < timestamp: + return 'in the future' + elif now > timestamp: + return '{} ago'.format(unparse_seconds(now - timestamp)) + else: + return 'now' + def digest(text): return hashlib.sha224(text.encode('utf-8')).hexdigest() diff --git a/plugin/shopping/shopping.py b/plugin/shopping/shopping.py index 6b5afb0..76d3953 100644 --- a/plugin/shopping/shopping.py +++ b/plugin/shopping/shopping.py @@ -259,9 +259,21 @@ class Shopping(object): params['sellingShipIdsString'] = ','.join([str(s['id']) for s in ships]) return params - def format_station(self, station, reference_coords = None): + def format_station(self, station, params, reference_coords = None): text = '' + market_updated = station['market_updated_at'] + shipyard_updated = station['shipyard_updated_at'] + updated = shipyard_updated + if shipyard_updated is None or 'sellsCommodityIds' in params: + if market_updated is None: + updated = shipyard_updated + else: + updated = market_updated + if shipyard_updated is not None: + if 'sellingModulesIdsString' in params or 'sellingShipIdsString' in params: + updated = min(market_updated, shipyard_updated) + system = station['system'] if reference_coords is not None: @@ -275,6 +287,8 @@ class Shopping(object): text += '{}Ls from *{}* star'.format(station['distance_to_star'], system['name']) else: text += 'in *{}*'.format(system['name']) + if updated is not None: + text += ' updated {}'.format(bot.ago(updated)) return text @asyncio.coroutine @@ -318,7 +332,7 @@ class Shopping(object): log.info(params) lines = [] for station in eddb.find_station(params, 'system'): - lines.append(self.format_station(station, reference_coords)) + lines.append(self.format_station(station, params, reference_coords)) if not len(lines): lines = ['*shrugs*'] if not message.channel.is_private: -- 2.7.4