Skip to content

Commit

Permalink
Encode datetimes as ISO formatted strings for sending to frontend (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
aywaldron authored and Futabay committed May 19, 2020
1 parent 7740371 commit ab010e2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,16 @@ def get_packet_delta(pkt_defn, packet):
return delta, dntoeus


def replace_datetimes(delta):
"""Replace datetime objects with ISO formatted
strings for JSON serialization"""
for key, val in delta.items():
if type(val) is datetime:
delta[key] = val.isoformat()

return delta


@App.route('/tlm/realtime')
def handle():
"""Return telemetry packets in realtime to client"""
Expand All @@ -759,6 +769,8 @@ def handle():
break

delta, dntoeus = get_packet_delta(pkt_defn, data)
delta = replace_datetimes(delta)
log.info(delta)

wsock.send(json.dumps({
'packet': pkt_defn.name,
Expand Down

0 comments on commit ab010e2

Please sign in to comment.