mirror of https://git.48k.eu/ogcli/
live: use human readable date in live list
Parse the unix timestamp into a human readable format like "2024-11-25 12:28:19". Make print_json() print from string and from a json object to enable manipulation of data before printing.master
parent
12d965ce1c
commit
80a68ceb5a
|
@ -8,6 +8,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from cli.config import cfg, OG_CLI_CFG_PATH
|
from cli.config import cfg, OG_CLI_CFG_PATH
|
||||||
|
from datetime import datetime
|
||||||
from cli.utils import *
|
from cli.utils import *
|
||||||
import requests
|
import requests
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -23,6 +24,15 @@ class OgLive():
|
||||||
]
|
]
|
||||||
tmp_extension = '.tmp'
|
tmp_extension = '.tmp'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse_timestamps(payload):
|
||||||
|
for elem in payload['oglive']:
|
||||||
|
if 'date' in elem:
|
||||||
|
timestamp = elem['date']
|
||||||
|
readable_date = datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
elem['date'] = readable_date
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_local_live_dir():
|
def _get_local_live_dir():
|
||||||
local_live_dir = cfg.get('local_live', '/var/www/html/ogrelive')
|
local_live_dir = cfg.get('local_live', '/var/www/html/ogrelive')
|
||||||
|
@ -155,7 +165,10 @@ class OgLive():
|
||||||
res = rest.get('/oglive/list')
|
res = rest.get('/oglive/list')
|
||||||
if not res:
|
if not res:
|
||||||
return 1
|
return 1
|
||||||
print_json(res.text)
|
|
||||||
|
live_data = json.loads(res.text)
|
||||||
|
OgLive._parse_timestamps(live_data)
|
||||||
|
print_json(live_data)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -49,8 +49,11 @@ def reorder_json_tree(payload):
|
||||||
payload[k] = val
|
payload[k] = val
|
||||||
reorder_json_tree(val)
|
reorder_json_tree(val)
|
||||||
|
|
||||||
def print_json(text):
|
def print_json(data):
|
||||||
payload = json.loads(text)
|
if isinstance(data, (dict, list)):
|
||||||
|
payload = data
|
||||||
|
else:
|
||||||
|
payload = json.loads(data)
|
||||||
reorder_json_tree(payload)
|
reorder_json_tree(payload)
|
||||||
print(json.dumps(payload, indent=2, ensure_ascii=False))
|
print(json.dumps(payload, indent=2, ensure_ascii=False))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue