comparison sat_frontends/jp/cmd_blog.py @ 3715:b9718216a1c0 0.9

merge bookmark 0.9
author Goffi <goffi@goffi.org>
date Wed, 01 Dec 2021 16:13:31 +0100
parents 9ca19b317293
children a6dfd3db372b
comparison
equal deleted inserted replaced
3714:af09b5aaa5d7 3715:b9718216a1c0
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
249 self, 248 self,
250 host, 249 host,
251 "get", 250 "get",
252 use_verbose=True, 251 use_verbose=True,
253 use_pubsub=True, 252 use_pubsub=True,
254 pubsub_flags={C.MULTI_ITEMS}, 253 pubsub_flags={C.MULTI_ITEMS, C.CACHE},
255 use_output=C.OUTPUT_COMPLEX, 254 use_output=C.OUTPUT_COMPLEX,
256 extra_outputs=extra_outputs, 255 extra_outputs=extra_outputs,
257 help=_("get blog item(s)"), 256 help=_("get blog item(s)"),
258 ) 257 )
259 258
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:
598 588
599 async def getItemData(self, service, node, item): 589 async def getItemData(self, service, node, item):
600 items = [item] if item else [] 590 items = [item] if item else []
601 591
602 mb_data = data_format.deserialise( 592 mb_data = data_format.deserialise(
603 await self.host.bridge.mbGet(service, node, 1, items, {}, self.profile) 593 await self.host.bridge.mbGet(
594 service, node, 1, items, data_format.serialise({}), self.profile
595 )
604 ) 596 )
605 item = mb_data["items"][0] 597 item = mb_data["items"][0]
606 598
607 try: 599 try:
608 content = item["content_xhtml"] 600 content = item["content_xhtml"]