Skip to content

Commit a24fd5a

Browse files
♻️ refactor(librecoll): Extract formatkeys function.
1 parent b426a57 commit a24fd5a

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

.bin/librecoll.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@
44

55
def formatdoc(doc):
66

7-
path = doc.url[7:]
8-
hint = '/'.join(map(lambda x : x[:2], path.split('/')[3:-1]))
9-
10-
try:
11-
timestamp = arrow.get(doc.mtime)
12-
htime = timestamp.humanize()
13-
hdate = timestamp.format('YYYY-MM-DDTHH:mm:ssZZ')
14-
except Exception as e:
15-
htime = 'unknown'
16-
hdate = 'unknown'
17-
18-
try:
19-
hbytes = humanbytes(int(doc.fbytes))
20-
except Exception as e:
21-
hbytes = 'unknown'
22-
237
formatarray = ['{htime}', '>']
248

259
if doc.title:
@@ -38,13 +22,33 @@ def formatdoc(doc):
3822
formatarray.append('--')
3923
formatarray.append('d@te:{hdate}')
4024

41-
keys = {
25+
keys = formatkeys(doc)
26+
return ' '.join(formatarray).format(**keys)
27+
28+
29+
def formatkeys(doc):
30+
31+
path = doc.url[7:]
32+
hint = '/'.join(map(lambda x : x[:2], path.split('/')[3:-1]))
33+
34+
try:
35+
timestamp = arrow.get(doc.mtime)
36+
htime = timestamp.humanize()
37+
hdate = timestamp.format('YYYY-MM-DDTHH:mm:ssZZ')
38+
except Exception:
39+
htime = 'unknown'
40+
hdate = 'unknown'
41+
42+
try:
43+
hbytes = humanbytes(int(doc.fbytes))
44+
except Exception:
45+
hbytes = 'unknown'
46+
47+
return {
4248
'hbytes': hbytes,
4349
'htime': htime,
4450
'hdate': hdate,
4551
'hint': hint,
4652
'filename': 'unknown',
4753
**doc.items()
4854
}
49-
50-
return ' '.join(formatarray).format(**keys)

0 commit comments

Comments
 (0)