jp (blog/get): fancy output prints author, published and updated if verbosity > 1 and tags if verbosity > 2 + format published and updated
This commit is contained in:
parent
bb6d71d857
commit
bc8c6d34ca
1 changed files with 35 additions and 3 deletions
|
|
@ -224,6 +224,12 @@ class Get(base.CommandBase):
|
|||
tags = data_format.dict2iter('tag', item, pop=True)
|
||||
return u', '.join(tags)
|
||||
|
||||
def format_updated(self, item, keys):
|
||||
return self.format_time(item['updated'])
|
||||
|
||||
def format_published(self, item, keys):
|
||||
return self.format_time(item['published'])
|
||||
|
||||
def get_keys(self):
|
||||
"""return keys to display according to verbosity or explicit key request"""
|
||||
verbosity = self.args.verbose
|
||||
|
|
@ -240,7 +246,7 @@ class Get(base.CommandBase):
|
|||
if verbosity == 0:
|
||||
return (u'title', u'content')
|
||||
elif verbosity == 1:
|
||||
return (u"title", u"tags", u"author", u"author_jid", u"author_email", u"author_jid_verified", u"content")
|
||||
return (u"title", u"tags", u"author", u"author_jid", u"author_email", u"author_jid_verified", u"published", u"updated", u"content")
|
||||
else:
|
||||
return MB_KEYS
|
||||
|
||||
|
|
@ -276,6 +282,15 @@ class Get(base.CommandBase):
|
|||
if idx < len(items)-1:
|
||||
print(u'')
|
||||
|
||||
def format_time(self, timestamp):
|
||||
"""return formatted date for timestamp
|
||||
|
||||
@param timestamp(str,int,float): unix timestamp
|
||||
@return (unicode): formatted date
|
||||
"""
|
||||
fmt = u"%d/%m/%Y %H:%M:%S"
|
||||
return time.strftime(fmt, time.localtime(float(timestamp)))
|
||||
|
||||
def fancy_output(self, data):
|
||||
"""display blog is a nice to read way
|
||||
|
||||
|
|
@ -284,19 +299,36 @@ class Get(base.CommandBase):
|
|||
# thanks to http://stackoverflow.com/a/943921
|
||||
rows, columns = map(int, os.popen('stty size', 'r').read().split())
|
||||
items, metadata = data
|
||||
verbosity = self.args.verbose
|
||||
sep = A.color(A.FG_BLUE, columns * u'▬')
|
||||
if items:
|
||||
print(u'\n' + sep + '\n')
|
||||
|
||||
for idx, item in enumerate(items):
|
||||
title = item.get(u'title')
|
||||
tags = list(data_format.dict2iter('tag', item, pop=True))
|
||||
if verbosity > 0:
|
||||
author = item[u'author']
|
||||
published, updated = item[u'published'], item.get('updated')
|
||||
else:
|
||||
author = published = updated = None
|
||||
if verbosity > 1:
|
||||
tags = list(data_format.dict2iter('tag', item, pop=True))
|
||||
else:
|
||||
tags = None
|
||||
content = item.get(u'content')
|
||||
|
||||
if title:
|
||||
print(A.color(A.BOLD, A.FG_CYAN, item[u'title']))
|
||||
meta = []
|
||||
if author:
|
||||
meta.append(A.color(A.FG_YELLOW, author))
|
||||
if published:
|
||||
meta.append(A.color(A.FG_YELLOW, u'on ', self.format_time(published)))
|
||||
if updated != published:
|
||||
meta.append(A.color(A.FG_YELLOW, u'(updated on ', self.format_time(updated), u')'))
|
||||
print(u' '.join(meta))
|
||||
if tags:
|
||||
print(A.color(A.FG_YELLOW, u', '.join(tags)))
|
||||
print(A.color(A.FG_MAGENTA, u', '.join(tags)))
|
||||
if (title or tags) and content:
|
||||
print("")
|
||||
if content:
|
||||
|
|
|
|||
Loading…
Reference in a new issue