comparison sat_frontends/jp/cmd_blog.py @ 3667:9ca19b317293

CLI: move `format_time` to `common` + add timezone
author Goffi <goffi@goffi.org>
date Wed, 08 Sep 2021 17:58:48 +0200
parents bef32f3ccc06
children a6dfd3db372b
comparison
equal deleted inserted replaced
3666:342e3ddefd23 3667:9ca19b317293
20 20
21 import json 21 import json
22 import sys 22 import sys
23 import os.path 23 import os.path
24 import os 24 import os
25 import time
26 import tempfile 25 import tempfile
27 import subprocess 26 import subprocess
28 import asyncio 27 import asyncio
29 from asyncio.subprocess import DEVNULL 28 from asyncio.subprocess import DEVNULL
30 from pathlib import Path 29 from pathlib import Path
288 def format_tags(self, item, keys): 287 def format_tags(self, item, keys):
289 tags = item.pop("tags", []) 288 tags = item.pop("tags", [])
290 return ", ".join(tags) 289 return ", ".join(tags)
291 290
292 def format_updated(self, item, keys): 291 def format_updated(self, item, keys):
293 return self.format_time(item["updated"]) 292 return common.format_time(item["updated"])
294 293
295 def format_published(self, item, keys): 294 def format_published(self, item, keys):
296 return self.format_time(item["published"]) 295 return common.format_time(item["published"])
297 296
298 def format_url(self, item, keys): 297 def format_url(self, item, keys):
299 return uri.buildXMPPUri( 298 return uri.buildXMPPUri(
300 "pubsub", 299 "pubsub",
301 subtype="microblog", 300 subtype="microblog",
370 self.disp(header + value) 369 self.disp(header + value)
371 # we want a separation line after each item but the last one 370 # we want a separation line after each item but the last one
372 if idx < len(items) - 1: 371 if idx < len(items) - 1:
373 print("") 372 print("")
374 373
375 def format_time(self, timestamp):
376 """return formatted date for timestamp
377
378 @param timestamp(str,int,float): unix timestamp
379 @return (unicode): formatted date
380 """
381 fmt = "%d/%m/%Y %H:%M:%S"
382 return time.strftime(fmt, time.localtime(float(timestamp)))
383
384 def fancy_output(self, data): 374 def fancy_output(self, data):
385 """display blog is a nice to read way 375 """display blog is a nice to read way
386 376
387 this output doesn't use keys filter 377 this output doesn't use keys filter
388 """ 378 """
411 print((A.color(A.BOLD, A.FG_CYAN, item["title"]))) 401 print((A.color(A.BOLD, A.FG_CYAN, item["title"])))
412 meta = [] 402 meta = []
413 if author: 403 if author:
414 meta.append(A.color(A.FG_YELLOW, author)) 404 meta.append(A.color(A.FG_YELLOW, author))
415 if published: 405 if published:
416 meta.append(A.color(A.FG_YELLOW, "on ", self.format_time(published))) 406 meta.append(A.color(A.FG_YELLOW, "on ", common.format_time(published)))
417 if updated != published: 407 if updated != published:
418 meta.append( 408 meta.append(
419 A.color(A.FG_YELLOW, "(updated on ", self.format_time(updated), ")") 409 A.color(A.FG_YELLOW, "(updated on ", common.format_time(updated), ")")
420 ) 410 )
421 print((" ".join(meta))) 411 print((" ".join(meta)))
422 if tags: 412 if tags:
423 print((A.color(A.FG_MAGENTA, ", ".join(tags)))) 413 print((A.color(A.FG_MAGENTA, ", ".join(tags))))
424 if (title or tags) and content: 414 if (title or tags) and content: