X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yoweb-scrape;h=03607451167a1d831c77f8137ad525e8783388ec;hb=c1f55148710340aad66796dab67e5b7376f04f9b;hp=c3e6d73513adc3d5516252d8bd5c06ef706a26bd;hpb=7b1ebd0829f7e41fd3299cc1400c83a0c89a7552;p=ypp-sc-tools.db-test.git diff --git a/yoweb-scrape b/yoweb-scrape index c3e6d73..0360745 100755 --- a/yoweb-scrape +++ b/yoweb-scrape @@ -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 @@ -610,13 +611,17 @@ class ChatLogTracker: del v[pirate] del self._pl[pirate] + def disembark_me(why): + self._disembark_myself() + return d('disembark-me '+why) + m = rm('Going aboard the (\\S.*\\S)\\.\\.\\.$') if m: dm = ['boarding'] 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) @@ -706,19 +711,35 @@ class ChatLogTracker: m = rm('(\\w+) officer chats, "(.*)"$') if m: return chat_metacmd('officer') + m = rm('Ye accepted the offer to job with ') + if m: return disembark_me('jobbing') + + m = rm('Ye hop on the ferry and are whisked away ') + if m: return disembark_me('ferry') + + m = rm('Whisking away to yer home on the magical winds') + if m: return disembark_me('home') + m = rm('Game over\\. Winners: ([A-Za-z, ]+)\\.$') if m: pl = m.group(1).split(', ') if not self._myself.name in pl: - return d('lost boarding battle') + return d('lost melee') for pn in pl: if ' ' in pn: continue - ob_x(pn,'won boarding battle') - return d('won boarding battle') + ob_x(pn,'won melee') + return d('won melee') m = rm('(\\w+) is eliminated\\!') if m: return ob1('eliminated in fray'); + m = rm('(\\w+) has driven \w+ from the ship\\!') + if m: return ob1('boarder repelled'); + + m = rm('\w+ has bested (\\w+), and turns'+ + ' to the rest of the ship\\.') + if m: return ob1('boarder unrepelled'); + m = rm('(\\w+) has left the vessel\.') if m: pirate = m.group(1) @@ -787,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 ---------- @@ -855,9 +884,9 @@ def prep_chat_log(args, bu, if not match: bu('chat log filename is not in expected format') (pirate, ocean) = match.groups() fetcher.default_ocean(ocean) - - myself = PirateInfo(pirate,max_myself_age) + progress.show_init(pirate, fetcher.ocean) + myself = PirateInfo(pirate,max_myself_age) track = ChatLogTracker(myself, logfn) opts.debug -= 2 @@ -954,21 +983,29 @@ def do_ship_aid(args, bu): displayer.realstart() + def find_vessel(): + vn = track.vesselname() + if vn: return (vn, " on board the %s" % vn) + vn = track.lastvesselname() + if vn: return (vn, " ashore from the %s" % vn) + return (None, " not on a vessel") + + displayer.show(track.myname() + find_vessel()[1] + '...') + while True: track.catchup() now = time.time() - s = "%s" % track.myname() - - vn = track.vessel() - if vn is None: s += " not on a vessel?!" - else: s += " on board the %s" % vn + (vn, s) = find_vessel() + s = track.myname() + s s += " at %s\n" % time.strftime("%Y-%m-%d %H:%M:%S") tbl = StandingsTable() tbl.headings() - for pa in track.aboard(): + aboard = track.aboard(vn) + + for pa in aboard: pi = pa.pirate_info() xs = ''