Skip to content

Commit

Permalink
♻️ refactor(librecoll): Extract formatkeys function.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Oct 5, 2023
1 parent b426a57 commit a24fd5a
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions .bin/librecoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -38,13 +22,33 @@ 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,
'hint': hint,
'filename': 'unknown',
**doc.items()
}

return ' '.join(formatarray).format(**keys)

0 comments on commit a24fd5a

Please sign in to comment.