From: Ian Jackson Date: Sun, 17 May 2009 13:35:15 +0000 (+0100) Subject: Periodically refresh pirate info X-Git-Tag: 1.0~25 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=commitdiff_plain;h=1c73d435c7cd125d11583573f5b2d130be164520 Periodically refresh pirate info --- diff --git a/yoweb-scrape b/yoweb-scrape index 0360745..a943f3c 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: