Skip to content

Commit 6fbbc3a

Browse files
committed
new example for pycot from igs
1 parent 84cb505 commit 6fbbc3a

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

examples/pycot-from-json-igs.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Data Sourced from network.igs.org
2+
import json
3+
import CoT
4+
import datetime
5+
import socket
6+
7+
def generate_cot_event(station):
8+
# Required fields
9+
uid = station.get("name", "UNKNOWN")
10+
lat, lon, hae = station.get("llh", [0, 0, 0])
11+
12+
now = datetime.datetime.now(datetime.timezone.utc)
13+
stale = now + datetime.timedelta(minutes=90)
14+
15+
# Optional metadata
16+
contact = {"callsign": uid}
17+
remarks_parts = [
18+
f"Receiver: {station.get('receiver_type')}",
19+
f"Antenna: {station.get('antenna_type')}",
20+
f"Firmware: {station.get('firmware')}",
21+
f"City: {station.get('city')}",
22+
f"Country: {station.get('country')}",
23+
f"Serial: {station.get('serial_number')}",
24+
]
25+
remarks = "\n".join(filter(None, remarks_parts))
26+
27+
# Build CoT event
28+
event = CoT.Event(
29+
version="2.0",
30+
type="a-u-P-S", # Arbitrary MIL-STD-2525C type for unit
31+
uid=uid,
32+
time=now,
33+
start=now,
34+
stale=stale,
35+
how="m-g", # machine generated
36+
qos="2-i-c",
37+
access="Undefined",
38+
point=CoT.Point(
39+
lat=lat,
40+
lon=lon,
41+
hae=hae,
42+
ce=9999999,
43+
le=9999999,
44+
),
45+
detail={
46+
"contact": contact,
47+
"remarks": CoT.models.Remarks(
48+
text=remarks,
49+
)
50+
}
51+
)
52+
return event.xml()
53+
54+
def main():
55+
# Downloaded from network.igs.org
56+
with open("igs_stations.json", "r") as f:
57+
stations = json.load(f)
58+
59+
for station in stations:
60+
cot_xml = generate_cot_event(station)
61+
print(cot_xml)
62+
TAK_IP = "0.0.0.0"
63+
TAK_PORT = 9090
64+
65+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
66+
sock.connect((TAK_IP, TAK_PORT))
67+
68+
sock.sendall(bytes(cot_xml, encoding="utf-8"))
69+
70+
if __name__ == "__main__":
71+
main()

0 commit comments

Comments
 (0)