commit 6f9d14995908b95c8f93bad0f7ea68a77cc3aef0
parent 67d9474a8e8befb50244f7be0ee9a53b045739b3
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 11 Jan 2026 17:03:27 +0000
write data to file
Diffstat:
| M | shore.py | | | 36 | +++++++++++++++++++++++++----------- |
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/shore.py b/shore.py
@@ -6,6 +6,9 @@ import sys
import socket
import threading
import select
+import datetime
+from pathlib import Path
+import os
peer_hostname = None
peer_thread = None
@@ -19,6 +22,13 @@ hosts = {
"eculogical3.local" : None
}
+def output_pathname():
+ root = Path(os.getenv("HOME"))
+ dir = root / "storage" / "capital-shore"
+ dir.mkdir(0o777, False, True)
+ name = datetime.datetime.utcfromtimestamp(int(time.time())).isoformat() + ".raw"
+ return dir / name
+
def recording_thread_main():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect((peer_hostname, 5000))
@@ -26,17 +36,21 @@ def recording_thread_main():
interval = 500
global bytes_recorded
bytes_recorded = 0
- while started:
- print("sending subscribe")
- b = bytes([interval >> 8, interval & 0xff, 0x54, 0x11, 0, 25] )
- sock.send(b)
- timeout = time.time() + 60
- while started and time.time() < timeout:
- ready = select.select([sock], [], [], timeout - time.time())
- if ready[0]:
- data = sock.recv(4000)
- bytes_recorded = bytes_recorded + len(data)
- print(f"got data {len(data)}" )
+
+ with open(output_pathname(), "wb") as outf:
+ while started:
+ print("sending subscribe")
+ b = bytes([interval >> 8, interval & 0xff, 0x54, 0x11, 0, 25] )
+ sock.send(b)
+ timeout = time.time() + 60
+ while started and time.time() < timeout:
+ ready = select.select([sock], [], [], timeout - time.time())
+ if ready[0]:
+ data = sock.recv(4000)
+ bytes_recorded = bytes_recorded + len(data)
+ outf.write(data)
+ outf.flush()
+
sock.close()
print("recording thread terminated")