From 1c73d435c7cd125d11583573f5b2d130be164520 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 17 May 2009 14:35:15 +0100 Subject: [PATCH] Periodically refresh pirate info --- yoweb-scrape | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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: -- 2.30.2