-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsnquery.py
More file actions
101 lines (71 loc) · 3.01 KB
/
dsnquery.py
File metadata and controls
101 lines (71 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import xml.etree.ElementTree as ET
import requests
from datetime import datetime
class DSNQuery:
def __init__(self):
self.getFriendlyNames()
def getFriendlyNames(self):
# get friendly names
friendlyxml = requests.get('https://eyes.nasa.gov/dsn/config.xml')
friendlynames = ET.fromstring(friendlyxml.text)
# make dict of friendlynames
allships = friendlynames.findall("./spacecraftMap/spacecraft")
self.friendlyTranslator = {}
#self.friendlyTranslator = {'dss': 'Debug', 'test': 'Testing'}
for ship in allships:
self.friendlyTranslator[ship.attrib['name']] = ship.attrib['friendlyName']
def poll(self):
# get whos talking
dishxml = requests.get('https://eyes.nasa.gov/dsn/data/dsn.xml')
# this gives us the actual xml object to work with
comms = ET.fromstring(dishxml.text)
# go through each dish
# find all down and upsignals
# add each found spaceship and power/frequency to a list
# translate shortnames to friendlynames
signals = {}
"""
for signal in comms.findall("./dish/upSignal") + comms.findall("./dish/downSignal"):
sDict = {}
name = signal.attrib['spacecraft']
if name == "":
continue
sDict['name'] = name
sDict['friendlyName'] = self.friendlyTranslator[name.lower()]
sDict['power'] = signal.attrib['power'] # in dB
sDict['frequency'] = signal.attrib['frequency'] # in hertz
signals[name] = sDict
"""
for target in comms.findall("./dish/target"):
sDict = {}
name = target.attrib['name'].lower()
if name == "":
continue
sDict['name'] = name
try:
sDict['friendlyName'] = self.friendlyTranslator[name]
except:
print("key " + name + " not found")
continue
sDict['range'] = float(target.attrib['uplegRange']) # in km
signals[name] = sDict
#print(signals)
# remove things we dont care about
for i in ["dss", "test", "testing"]:
try:
signals.pop(i)
except:
pass
#print(signals)
ts = int(comms.findall("timestamp")[0].text) / 1000
timestring = datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
outString = "```python\n<./> " + timestring + " UTC <./>\n"
for item in signals:
outString += signals[item]['friendlyName'].ljust(12)
#if signals[item]['power'] != "":
# outString += " (" + signals[item]['power'] + " dB)"
if signals[item]['range'] != -1:
outString += " (" + str(signals[item]['range']) + " km)"
outString += "\n"
outString += "```"
return outString