chiark / gitweb /
tracker seems to work
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 16 May 2009 18:53:21 +0000 (19:53 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 16 May 2009 18:53:21 +0000 (19:53 +0100)
yoweb-scrape

index 1f5486e..3e77ffd 100755 (executable)
@@ -321,10 +321,12 @@ class StandingsTable:
                self.s = ''
                self._cw = col_width-1
 
-       def _pline(self, pirate, puzstrs):
+       def _pline(self, pirate, puzstrs, extra):
                self.s += ' %-*s' % (max(max_pirate_namelen, 14), pirate)
                for v in puzstrs:
                        self.s += ' %-*.*s' % (self._cw,self._cw, v)
+               if extra:
+                       self.s += ' ' + extra
                self.s += '\n'
 
        def _puzstr(self, pi, puzzle):
@@ -352,14 +354,14 @@ class StandingsTable:
                        spc = name.find(' ')
                        if spc < 0: return name
                        return name[0:min(4,spc)] + name[spc+1:]
-               self._pline('', map(puzn_redact, self._puzzles))
+               self._pline('', map(puzn_redact, self._puzzles), None)
        def literalline(self, line):
                self.s += line + '\n'
-       def pirate_dummy(self, name, standingstring):
-               self._pline(name, standingstring * len(self._puzzles))
-       def pirate(self, pi):
+       def pirate_dummy(self, name, standingstring, extra=None):
+               self._pline(name, standingstring * len(self._puzzles), extra)
+       def pirate(self, pi, extra=None):
                puzstrs = [self._puzstr(pi,puz) for puz in self._puzzles]
-               self._pline(pi.name, puzstrs)
+               self._pline(pi.name, puzstrs, extra)
 
        def results(self):
                return self.s
@@ -529,13 +531,13 @@ class ChatLogTracker:
                m = rm('You have ordered (\\w+) to do some (\\S.*\\S)\\.$')
                if m:
                        (who,what) = m.groups()
-                       pa = ob_x(who,'ordered '+what)
+                       pa = ob_x(who,'ord '+what)
                        if what == 'Gunning':
                                pa.gunner = True
                        return d('duty order')
 
                m = rm('(\\w+) abandoned a (\\S.*\\S) station\\.$')
-               if m: oba('stopped'); return d('stopped')
+               if m: oba('stopped'); return d("end")
 
                def chat(what):
                        who = m.group(1)
@@ -687,6 +689,12 @@ def do_track_chat_log(args, bu):
                        print track
                time.sleep(1)
 
+def format_time_interval(ti):
+       if ti < 120: return '%d:%02d' % (ti / 60, ti % 60)
+       if ti < 7200: return '%2dm' % (ti / 60)
+       if ti < 86400: return '%dh' % (ti / 3600)
+       return '%dd' % (ti / 86400)
+
 def do_ship_aid(args, bu):
        if opts.ship_duty is None: opts.ship_duty = True
 
@@ -694,15 +702,20 @@ def do_ship_aid(args, bu):
 
        rotate_nya = '/-\\'
 
+       def timeevent(t,e):
+               if t is None: return ' ' * 22
+               return " %-4s %-16s" % (format_time_interval(now - t),e)
+
        while True:
                track.catchup()
                now = time.time()
-               sys.stdout.write("\n\n%s" % track.myname())
+
+               s = "%s" % track.myname()
 
                vn = track.vessel()
-               if vn is None: print " ...?"; return
+               if vn is None: print s + " ...?"; return
 
-               print " on board the %s at %s\n" % (
+               s += " on board the %s at %s\n" % (
                        vn, time.strftime("%Y-%m-%d %H:%M:%S"))
 
                tbl = StandingsTable()
@@ -710,12 +723,20 @@ def do_ship_aid(args, bu):
 
                for pa in track.aboard():
                        pi = pa.pirate_info()
+
+                       xs = ''
+                       xs += timeevent(pa.last_time, pa.last_event)
+                       xs += timeevent(pa.last_chat_time, pa.last_chat_chan)
+
                        if pi is None:
-                               tbl.pirate_dummy(pa.name, rotate_nya[0])
+                               tbl.pirate_dummy(pa.name, rotate_nya[0], xs)
                        else:
-                               tbl.pirate(pi)
+                               tbl.pirate(pi, xs)
+
+               s += tbl.results()
+
+               print '\n\n', s;
 
-               print tbl.results()
                time.sleep(1)
                rotate_nya = rotate_nya[1:2] + rotate_nya[0]