From a1f172454d58a6ed8cf94223580e47a84ae2d3d0 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 14 Sep 2015 19:51:16 +0200 Subject: fb.py: display_history: Handle multipastes Signed-off-by: Florian Pritz --- fb.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/fb.py b/fb.py index 58e80f7..2d057e2 100755 --- a/fb.py +++ b/fb.py @@ -530,12 +530,40 @@ class FBClient: def display_history(self): + timeFormat = '%a, %d %b %Y %H:%M:%S +0000' resp = self.curlw.send_post("/file/history") - items = resp["items"] - timeFormat = locale.nl_langinfo(locale.D_T_FMT) + + multipasteItems = resp['multipaste_items'] + if not multipasteItems: + multipasteItems = {} + + items = resp['items'] + if not items: + items = {} + + items = list(items.values()) + multipasteItems = list(multipasteItems.values()) + + for item in multipasteItems: + item['id'] = item['url_id'] + item['filename'] = '%s file(s)' % (len(item['items'])) + item['mimetype'] = '' + item['hash'] = '' + # sum filesize of all items + item['filesize'] = str(sum([int(resp['items'][i]['filesize']) for i in item['items'].keys()])) + items.append(item) + + items.sort(key=lambda s: s['date']) + itemsTable = [['ID', 'Filename', 'Mimetype', 'Date', 'Hash', 'Size']] - # TODO: sort items by date or something. currently they are in random order - itemsTable += [[i['id'], i['filename'], i['mimetype'], datetime.datetime.fromtimestamp(int(i['date'])).strftime(timeFormat), i['hash'], i['filesize']] for i in items.values()] + itemsTable += [[ + i['id'], + i['filename'], + i['mimetype'], + datetime.datetime.fromtimestamp(int(i['date'])).strftime(timeFormat), + i['hash'], + i['filesize' + ]] for i in items] print_table(itemsTable) def display_version(self): -- cgit v1.2.3-24-g4f1b