Show update times for shopping list.
authorCMDR furrycat <elite@furrycat.net>
Sat, 18 Feb 2017 12:45:15 +0000 (12:45 +0000)
committerCMDR furrycat <elite@furrycat.net>
Sat, 18 Feb 2017 12:45:15 +0000 (12:45 +0000)
bot.py
plugin/shopping/shopping.py

diff --git a/bot.py b/bot.py
index f6aeb4b..d2c74f2 100644 (file)
--- 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()
 
index 6b5afb0..76d3953 100644 (file)
@@ -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: