From a24fd5a65b7abfd5742e8308416e5c19b12d9eea Mon Sep 17 00:00:00 2001 From: make-github-pseudonymous-again <5165674+make-github-pseudonymous-again@users.noreply.github.com> Date: Fri, 6 Oct 2023 01:16:09 +0200 Subject: [PATCH] :recycle: refactor(librecoll): Extract formatkeys function. --- .bin/librecoll.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/.bin/librecoll.py b/.bin/librecoll.py index a1617f4..cc4f85f 100644 --- a/.bin/librecoll.py +++ b/.bin/librecoll.py @@ -4,22 +4,6 @@ def formatdoc(doc): - path = doc.url[7:] - hint = '/'.join(map(lambda x : x[:2], path.split('/')[3:-1])) - - try: - timestamp = arrow.get(doc.mtime) - htime = timestamp.humanize() - hdate = timestamp.format('YYYY-MM-DDTHH:mm:ssZZ') - except Exception as e: - htime = 'unknown' - hdate = 'unknown' - - try: - hbytes = humanbytes(int(doc.fbytes)) - except Exception as e: - hbytes = 'unknown' - formatarray = ['{htime}', '>'] if doc.title: @@ -38,7 +22,29 @@ def formatdoc(doc): formatarray.append('--') formatarray.append('d@te:{hdate}') - keys = { + keys = formatkeys(doc) + return ' '.join(formatarray).format(**keys) + + +def formatkeys(doc): + + path = doc.url[7:] + hint = '/'.join(map(lambda x : x[:2], path.split('/')[3:-1])) + + try: + timestamp = arrow.get(doc.mtime) + htime = timestamp.humanize() + hdate = timestamp.format('YYYY-MM-DDTHH:mm:ssZZ') + except Exception: + htime = 'unknown' + hdate = 'unknown' + + try: + hbytes = humanbytes(int(doc.fbytes)) + except Exception: + hbytes = 'unknown' + + return { 'hbytes': hbytes, 'htime': htime, 'hdate': hdate, @@ -46,5 +52,3 @@ def formatdoc(doc): 'filename': 'unknown', **doc.items() } - - return ' '.join(formatarray).format(**keys)