X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yoweb-scrape;h=4832d1ec34b88226af7c2f8e4eacd1aacadde377;hp=03607451167a1d831c77f8137ad525e8783388ec;hb=ab90a60e9977026cfe91233221d0caf9bcf9d5c0;hpb=c1f55148710340aad66796dab67e5b7376f04f9b diff --git a/yoweb-scrape b/yoweb-scrape index 0360745..4832d1e 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 @@ -247,7 +248,7 @@ u'\\s*\\S*/([-A-Za-z]+)\\s*$|\\s*\\S*/\\S*\\s*\\(ocean\\-wide(?:\\s|\\xa0)+([-A- skl.msg('puzzle "%s" no standing found' % puzzle) continue standing = sl[0] - for i in range(0, len(standingvals)-1): + for i in range(0, len(standingvals)): if standing == standingvals[i]: self.standings[puzzle] = i if not puzzle in self.standings: @@ -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: @@ -521,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 = [] @@ -1064,6 +1080,10 @@ display modes (for --display) apply to ship-aid: ao('--all-puzzles', action='store_false', dest='ship_duty', help='show all puzzles, not just ship duty stations') + ao('--min-cache-reuse', type='int', dest='min_max_age', + metavar='SECONDS', default=60, + help='always reuse cache yoweb data if no older than this') + (opts,args) = pa.parse_args() random.seed() @@ -1081,8 +1101,8 @@ display modes (for --display) apply to ship-aid: except KeyError: pa.error('unknown mode "%s"' % mode) # fixed parameters - opts.min_max_age = 60 - opts.expire_age = 3600 + opts.expire_age = max(3600, opts.min_max_age) + opts.ship_reboard_clearout = 3600 if opts.cache_dir.startswith('~/'):