Skip to content

Commit f91a5da

Browse files
Print timestamps from cose_recent_proposals keys in read_ledger.py (#6943)
Co-authored-by: Amaury Chamayou <[email protected]>
1 parent 7b64e99 commit f91a5da

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

python/src/ccf/read_ledger.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import re
88
import argparse
9+
from datetime import datetime
910
from enum import Enum, auto
1011

1112
from loguru import logger as LOG
@@ -43,11 +44,25 @@ def fmt_json(data):
4344
return json.dumps(json.loads(data), indent=2)
4445

4546

47+
def fmt_cose_recent_timestamp(data):
48+
s = data.decode()
49+
ts, _ = s.split(":")
50+
dt = datetime.fromtimestamp(int(ts))
51+
return f"[{dt.isoformat()}] {s}"
52+
53+
4654
# List of table name regex to key and value format functions (first match is used)
4755
# Callers can specify additional rules (e.g. for application-specific
4856
# public tables) which get looked up first.
4957
default_format_rule = {"key": fmt_raw, "value": fmt_raw}
5058
default_tables_format_rules = [
59+
(
60+
"^public:ccf\\.gov\\.cose_recent_proposals$",
61+
{
62+
"key": fmt_cose_recent_timestamp,
63+
"value": fmt_json,
64+
},
65+
),
5166
(
5267
"^public:ccf\\.internal\\..*$",
5368
{

0 commit comments

Comments
 (0)