ages.append(age)
return ages
- def _rate_limit_cache_clean(self, now):
+ def need_wait(self, now):
ages = self._cache_scan(now)
ages.sort()
debug('Fetcher ages ' + `ages`)
need_wait = max(need_wait, min_age - age)
min_age += 3
min_age *= 1.25
+ return need_wait
+
+ def _rate_limit_cache_clean(self, now):
+ need_wait = self.need_wait(now)
if need_wait > 0:
debug('Fetcher wait %d' % need_wait)
time.sleep(need_wait)
crew_rank_re = regexp.compile('/yoweb/images/crew')
for row in tbl.contents:
# findAll(recurse=False)
- if isinstance(row, unicode):
+ if isinstance(row,basestring):
continue
is_rank = row.find('img', attrs={'src': crew_rank_re})
if not isinstance(puzzle,list): puzzle = [puzzle]
try: standing = max([pi.standings[p] for p in puzzle])
except KeyError: return '?'
+ if isinstance(standing,basestring): return standing
if not standing: return ''
s = ''
if self._cw > 4:
# pa.gunner
# pa.last_chat_time
# pa.last_chat_chan
- def __init__(pa, v, time, event):
+ # pa.pi
+
+ def __init__(pa, pn, v, time, event):
+ pa.pn = pn
pa.v = v
pa.last_time = time
pa.last_event = event
pa.last_chat_time = None
pa.last_chat_chan = None
pa.gunner = False
+ pa.pi = None
+
+ def pirate_info(self):
+ if not pa.pi and not fetcher.need_wait(time.time):
+ pa.pi = PirateInfo(pa.name, 3600)
+ return pa.pi
class ChatLogTracker:
def __init__(self, myself_pi, logfn):
pa.last_event = event
else:
if pa is not None: del pa.v[pirate]
- pa = PirateAboard(self._v, timestamp, event)
+ pa = PirateAboard(pirate, self._v, timestamp, event)
self._pl[pirate] = pa
self._v[pirate] = pa
self._v['#lastaboard'] = timestamp
def catchup(self, progress=None):
while True:
more = self._f.readline()
- if not more: return
+ if not more: break
self._progress[0] += len(more)
- if progress is not None:
- progress(*self._progress)
+ if progress: progress.progress(*self._progress)
self._lbuf += more
if self._lbuf.endswith('\n'):
self.chatline(self._lbuf.rstrip())
self._lbuf = ''
-
-def do_track_chat_log(args, bu):
- if len(args) != 1: bu('ship-aid takes only chat log filename')
+ if progress: progress.caughtup()
+
+class ProgressPrintPercentage:
+ def __init__(self, f=sys.stdout): self._f = f
+ def progress(self,done,total):
+ self._f.write("scan chat logs %3d%%\r" % ((done*100) / total))
+ self._f.flush()
+ def caughtup(self):
+ self._f.write(' \r')
+ self._f.flush()
+
+def simple_printer(x): print x
+
+def run_chat_log(args, bu, progress=ProgressPrintPercentage(),
+ display=simple_printer, max_myself_age=3600):
+ if len(args) != 1: bu('this action takes only chat log filename')
logfn = args[0]
logfn_re = '(?:.*/)?([A-Z][a-z]+)_([a-z]+)_chat-log-\\w+$'
match = regexp.match(logfn_re, logfn)
- if not match: bu('ship-aid chat log filename is not in default format')
+ if not match: bu('chat log filename is not in default format')
(pirate, fetcher.ocean) = match.groups()
-
- track = ChatLogTracker(pirate, logfn)
- myself_pi = PirateInfo(pirate,3600)
+
+ myself_pi = PirateInfo(pirate,max_myself_age)
track = ChatLogTracker(myself_pi, logfn)
- def pprogress(done,total):
- sys.stdout.write("scan chat logs %3d%%\r" %
- ((done*100) / total))
- sys.stdout.flush()
-
- track.catchup(pprogress)
- sys.stdout.write(' \r')
-
+ track.catchup(progress)
while True:
track.catchup()
if track.need_redisplay:
- print track
+ display(track)
track.need_redisplay = False
time.sleep(1)
+def do_track_chat_log(args, bu):
+ run_chat_log(args, bu)
+
+#def do_ship_aid(args, bu):
+
def main():
global opts, fetcher
ao('--ship-duty', action='store_true', dest='ship_duty',
help='show ship duty station puzzles')
+ ao('--all-puzzles', action='store_false', dest='ship_duty',
+ help='show all puzzles, not just ship duty stations')
(opts,args) = pa.parse_args()
random.seed()