X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yoweb-scrape;h=b62ce0037528b1db9684d2484bc3dae9c0250bdb;hp=b12b5032fcb9eb7c09cfdfa867dbd34f57eb8e65;hb=9f80d231a203a0a68b4d8f76d48020fc84adb643;hpb=df5a08b4a0046990ff235a9fdc17262ac071deaa diff --git a/yoweb-scrape b/yoweb-scrape index b12b503..b62ce00 100755 --- a/yoweb-scrape +++ b/yoweb-scrape @@ -89,8 +89,9 @@ class Fetcher: ages.append(age) return ages - def need_wait(self, now): + def need_wait(self, now, imaginary=[]): ages = self._cache_scan(now) + ages += imaginary ages.sort() debug('Fetcher ages ' + `ages`) min_age = 1 @@ -417,8 +418,23 @@ class PirateAboard: pa.pi = None def pirate_info(pa): - if not pa.pi and not fetcher.need_wait(time.time()): - pa.pi = PirateInfo(pa.name, 3600) + now = time.time() + if pa.pi: + age = now - pa.pi_fetched + guide = random.randint(120,240) + if age <= guide: + return pa.pi + debug('PirateAboard refresh %d > %d %s' % ( + age, guide, pa.name)) + imaginary = [2,6] + else: + imaginary = [1] + wait = fetcher.need_wait(now, imaginary) + if wait: + debug('PirateAboard fetcher not ready %d' % wait) + return pa.pi + pa.pi = PirateInfo(pa.name, 600) + pa.pi_fetched = now return pa.pi class ChatLogTracker: @@ -438,6 +454,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 @@ -520,7 +537,7 @@ class ChatLogTracker: if pattern is None: pattern_check = lambda vn: True else: - re = '(?:.* )?%s$' % pattern.lower().replace('*','.*') + re = '(?:.* )?%s$' % pattern.lower().replace('*','.+') pattern_check = regexp.compile(re, regexp.I).match tries = [] @@ -620,7 +637,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 +824,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 ---------- @@ -875,9 +900,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 @@ -974,21 +999,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 = ''