chiark / gitweb /
show last vessel if we aren't on a vessel
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 17 May 2009 12:56:49 +0000 (13:56 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 17 May 2009 12:56:49 +0000 (13:56 +0100)
TODO
yoweb-scrape

diff --git a/TODO b/TODO
index ffe6b98..c4afe73 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,3 +1,2 @@
 yoweb-scrape
        improve the docs
-       ship-aid should show last vessel if we're not on a vessel
index b12b503..ed9533e 100755 (executable)
@@ -438,6 +438,7 @@ class ChatLogTracker:
                self._progress = [0, os.fstat(self._f.fileno()).st_size]
                self._disembark_myself()
                self._need_redisplay = False
+               self._lastvessel = None
 
        def _disembark_myself(self):
                self._v = None
@@ -620,7 +621,7 @@ class ChatLogTracker:
                        pn = self._myself.name
                        vn = m.group(1)
                        v = self._vessel_lookup(vn, timestamp, dm, create=True)
-                       self._vessel = vn
+                       self._lastvessel = self._vessel = vn
                        self._v = v
                        ob_x(pn, 'we boarded')
                        self.expire_garbage(timestamp)
@@ -807,14 +808,22 @@ class ChatLogTracker:
        def myname(self):
                # returns our pirate name
                return self._myself.name
-       def vessel(self):
-               # returns the vessel we're aboard or None
+       def vesselname(self):
+               # returns the vessel name we're aboard or None
                return self._vessel
-       def aboard(self):
-               # returns a list of PirateAboard sorted by name
-               if self._v is None: return []
-               return [ self._v[pn]
-                        for pn in sorted(self._v.keys())
+       def lastvesselname(self):
+               # returns the last vessel name we were aboard or None
+               return self._lastvessel
+       def aboard(self, vesselname=True):
+               # returns a list of PirateAboard the vessel
+               #  sorted by pirate name
+               #  you can pass this None and you'll get []
+               #  or True for the current vessel (which is the default)
+               if vesselname is True: v = self._v
+               else: v = self._vl.get(vesselname.title())
+               if v is None: return []
+               return [ v[pn]
+                        for pn in sorted(v.keys())
                         if not pn.startswith('#') ]
 
 #---------- implementations of actual operation modes ----------
@@ -980,9 +989,18 @@ def do_ship_aid(args, bu):
 
                s = "%s" % track.myname()
 
-               vn = track.vessel()
-               if vn is None: s += " not on a vessel"
-               else: s += " on board the %s" % vn
+               vn = track.vesselname()
+               if vn is not None:
+                       s += " on board the %s" % vn
+
+               if vn is None:
+                       vn = track.lastvesselname()
+                       if vn is not None:
+                               s += " ashore from the %s" % vn
+
+               if vn is None:
+                       s += " not on a vessel"
+
                s += " at %s\n" % time.strftime("%Y-%m-%d %H:%M:%S")
 
                tbl = StandingsTable()