diff --git a/ppf.py b/ppf.py index 31adbcd..f866d05 100644 --- a/ppf.py +++ b/ppf.py @@ -32,6 +32,23 @@ signal.signal(signal.SIGTERM, sigterm_handler) config = Config() + +def format_duration(seconds): + """Format seconds into compact human-readable duration.""" + if seconds < 60: + return '%ds' % seconds + elif seconds < 3600: + return '%dm' % (seconds // 60) + elif seconds < 86400: + h, m = divmod(seconds, 3600) + m = m // 60 + return '%dh %dm' % (h, m) if m else '%dh' % h + else: + d, rem = divmod(seconds, 86400) + h = rem // 3600 + return '%dd %dh' % (d, h) if h else '%dd' % d + + def import_from_file(fn, sqlite): with open(fn, 'r') as f: urls = [ url for url in f.read().split('\n') if url ] @@ -156,7 +173,8 @@ class Leechered(threading.Thread): self.hash_unchanged = True self.proxylist = [] self.stale_count += 1 - _log('%s: unchanged (hash match)' % self.url.split('/')[2], 'stale') + next_check = config.ppf.checktime + (self.error + self.stale_count) * config.ppf.perfail_checktime + _log('%s: unchanged (hash match), next in %s' % (self.url.split('/')[2], format_duration(next_check)), 'stale') # Content unchanged - increment stale_count, update check_time self.execute = (self.error, self.stale_count, int(time.time()), self.retrievals, self.proxies_added, self.content_type, self.url) self.status = 'ok'