diff --git a/hbd b/hbd
index 5117ff2..1396c7b 100755
--- a/hbd
+++ b/hbd
@@ -81,18 +81,18 @@ lastfm=["","",""]
tcss = """
"""
@@ -268,25 +268,25 @@ RECIPIENT = "+14168226179"
def pushsignal(msg, title="hbd", recipient=RECIPIENT):
- message = f'"{title}: {msg}"'
- CLI = [
- "/usr/bin/ssh", "andreas@w02",
- "/usr/local/bin/signal-cli", "-u", USER,
- "send", "-m", message,
-# "-g", GROUP,
- recipient,
- ]
+ message = f'"{title}: {msg}"'
+ CLI = [
+ "/usr/bin/ssh", "andreas@w02",
+ "/usr/local/bin/signal-cli", "-u", USER,
+ "send", "-m", message,
+# "-g", GROUP,
+ recipient,
+ ]
- if verbose: print(f"DBG cli: {CLI}")
- res = subprocess.run(CLI, shell=False, capture_output=True)
- rc = res.returncode == 0
- print(res.stdout.decode())
+ if verbose: print(f"DBG cli: {CLI}")
+ res = subprocess.run(CLI, shell=False, capture_output=True)
+ rc = res.returncode == 0
+ print(res.stdout.decode())
- if not rc:
- print(f"signalcli failed: {res.stderr.decode()}")
- else:
- if verbose: print(f"signalcli msg sent, res {res.stdout.decode()}")
- return rc
+ if not rc:
+ print(f"signalcli failed: {res.stderr.decode()}")
+ else:
+ if verbose: print(f"signalcli msg sent, res {res.stdout.decode()}")
+ return rc
# nsupdate: set the DNS A record for a fqdn
@@ -855,22 +855,22 @@ async def ws_serve(websocket, path):
except (
websockets.exceptions.ConnectionClosedOK,
websockets.exceptions.ConnectionClosedError) as e:
- print(f'ws closed: {e}')
+ if verbose: print(f'ws closed: {e}')
break
- print(f"< {name} at {path}")
+ if verbose: print(f"initial {name} at {path}")
+ # send initial set of hosts and messages
+ # hosts in sorted order
for h in sorted(hbdclass.Host.hosts):
jmsg = json.dumps({'type': 'host', 'data': hbdclass.Host.hosts[h].stateinfo() })
await websocket.send(jmsg)
+ # messages in reverse order
for m in msgs[len(msgs)-20:]:
jmsg = json.dumps({'type': 'message', 'data': m })
await websocket.send(jmsg)
if verbose: print(f"DBG ws_serve: close {remote_address}")
await websocket.wait_closed()
-# try:
-# del ws_connections[websocket]
-# except Exception as e:
-# print(f"warning: failed to delete websocket: {e}")
+
def websocketupdater():
loop.run_forever()