chiark / gitweb /
WIP chat tracking
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 16 May 2009 14:05:41 +0000 (15:05 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 16 May 2009 14:05:41 +0000 (15:05 +0100)
yoweb-scrape

index ca174e2..462bd01 100755 (executable)
@@ -433,25 +433,28 @@ class ShipCrewTracker:
                                del self._pl[p]
                self._v = {'#lastaboard': timestamp}
 
-       def _warn(self, m):
-               pass
+       def _debug_line_disposition(self,timestamp,l,m):
+               debug('SCT %-13s %-30s %s' % (timestamp,m,l))
 
        def chatline(self,l):
                rm = lambda re: regexp.match(re,l)
+               d = lambda m: self._debug_line_disposition(timestamp,l,m)
+               timestamp = None
+
                m = rm('=+ (\\d+)/(\\d+)/(\\d+) =+$')
                if m:
                        self._date = m.groups()
-                       return
+                       return d('date '+`self._date`)
+
                if self._date is None:
-                       return
+                       return d('date unset')
+
                m = rm('\\[(\d\d):(\d\d):(\d\d)\\] ')
                if not m:
-                       self._warn('undated? '+l)
-                       return
+                       return d('no timestamp')
 
                time_tuple = [int(x) for x in self._date + m.groups()]
                time_tuple += (-1,-1,-1)
-               print `time_tuple`
                timestamp = time.mktime(time_tuple)
                l = l[l.find(' ')+1:]
 
@@ -463,28 +466,33 @@ class ShipCrewTracker:
                m = rm('Going aboard the (\\S.*\\S)\\.\\.\\.$')
                if m:
                        self._vessel = m.group(1)
+                       dm = 'boarding'
                        try:             self._v = self._vl[self._vessel]
-                       except KeyError: self._v = None
+                       except KeyError: self._v = None; dm += ' new'
                        if self._v is not None:  la = self._v['#lastaboard']
-                       else:                    la = 0
+                       else:                    la = 0; dm += ' ?la'
                        if timestamp - la > 3600:
                                self.clear_vessel(timestamp)
+                               dm += ' stale'
+                       self._vl[self._vessel] = self._v
                        ob(self._myself.name, 'we boarded')
+                       return d(dm)
 
-               if self._v is None: return
+               if self._v is None:
+                       return d('no vessel')
 
                m = rm('You have ordered (\\w+) to do some (\\S.*\\S)\\.$')
                if m:
                        pa = oba(m, 'ordered')
                        if m.group(2) == 'Gunning':
                                pa.gunner = True
-                       return
+                       return d('duty order')
 
                m = rm('(\\w+) abandoned a (\\S.*\\S) station\\.$')
-               if m: oba(m,'abandoned'); return
+               if m: oba(m,'abandoned'); return d('abandoned')
 
                m = rm('(\\w+) says, "')
-               if m: ob(m.group(1), 'talked'); return
+               if m: ob(m.group(1), 'talked'); return d('talked')
 
                m = rm('(\\w+) has left the vessel\.')
                if m:
@@ -492,9 +500,9 @@ class ShipCrewTracker:
                        ob(who, 'disembarked')
                        del self._v[who]
                        del self._pl[who]
-                       return
+                       return d('disembarked')
 
-               return
+               return d('not matched')
 
 def do_ship_aid(args, bu):
        if len(args) != 1: bu('ship-aid takes only chat log filename')
@@ -508,18 +516,14 @@ def do_ship_aid(args, bu):
        f = file(logfn)
        l = ''
        while True:
-               print "1>"+l+"<"
                l += f.readline()
                if l.endswith('\n'):
-                       l.rstrip()
-                       print "2>"+l+"<"
-                       track.chatline(l)
+                       track.chatline(l.rstrip())
 #                      print `track.__dict__`
                        l = ''
                        continue
                if l:
                        continue
-               print "3>EOF<"
                print `track.__dict__`
                os.sleep(1)