ppf: add format_duration helper and stale log improvements
- Add format_duration() for compact time display - Improve stale proxy logging with duration info
This commit is contained in:
20
ppf.py
20
ppf.py
@@ -32,6 +32,23 @@ signal.signal(signal.SIGTERM, sigterm_handler)
|
|||||||
|
|
||||||
config = Config()
|
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):
|
def import_from_file(fn, sqlite):
|
||||||
with open(fn, 'r') as f:
|
with open(fn, 'r') as f:
|
||||||
urls = [ url for url in f.read().split('\n') if url ]
|
urls = [ url for url in f.read().split('\n') if url ]
|
||||||
@@ -156,7 +173,8 @@ class Leechered(threading.Thread):
|
|||||||
self.hash_unchanged = True
|
self.hash_unchanged = True
|
||||||
self.proxylist = []
|
self.proxylist = []
|
||||||
self.stale_count += 1
|
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
|
# 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.execute = (self.error, self.stale_count, int(time.time()), self.retrievals, self.proxies_added, self.content_type, self.url)
|
||||||
self.status = 'ok'
|
self.status = 'ok'
|
||||||
|
|||||||
Reference in New Issue
Block a user