uhoh uhoh - 4 months ago 10
Python Question

How can I detect the method to request data from this site?

UPDATE: I've put together the following script to use the url for the XML without the time-code-like suffix as recommended in the answer below, and report the downlink powers which clearly fluctuate on the website. I'm getting three hour old, unvarying data.

So it looks like I need to properly construct that (time code? authorization? secret password?) in order to do this successfully. Like I say in the comment below, "I don't want to do anything that's not allowed and welcome - NASA has enough challenges already trying to talk to a forty year old spacecraft 20 billion kilometers away!"

def dictify(r,root=True):
"""from: http://stackoverflow.com/a/30923963/3904031"""

if root:
return {r.tag : dictify(r, False)}
d=copy(r.attrib)
if r.text:
d["_text"]=r.text
for x in r.findall("./*"):
if x.tag not in d:
d[x.tag]=[]
d[x.tag].append(dictify(x,False))
return d

import xml.etree.ElementTree as ET
from copy import copy
import urllib2

url = 'https://eyes.nasa.gov/dsn/data/dsn.xml'

contents = urllib2.urlopen(url).read()
root = ET.fromstring(contents)
DSNdict = dictify(root)
dishes = DSNdict['dsn']['dish']
dp_dict = dict()
for dish in dishes:
powers = [float(sig['power']) for sig in dish['downSignal'] if sig['power']]
dp_dict[dish['name']] = powers

print dp_dict['DSS26']





I'd like to keep track of which spacecraft that the NASA Deep Space Network (DSN) is communicating with, say once per minute.

I learned how to do something similar from Flight Radar 24 from the answer to my previous question, which also still represents my current skills in getting data from web sites.

With FR24 I had explanations in this blog as a great place to start. I have opened the page with the Developer Tools function in the Chrome browser, and I can see that data for items such as dishes, spacecraft and associated numerical data are requested as an XML with urls such as

https://eyes.nasa.gov/dsn/data/dsn.xml?r=293849023


so it looks like I need to construct the integer (time code? authorization? secret password?) after the
r=
once a minute.

My Question: Using python, how could I best find out what that integer represents, and how to generate it in order to correctly request data once per minute?

enter image description here

above: screen shot montage from NASA's DSN Now page https://eyes.nasa.gov/dsn/dsn.html see also this question

Answer

Using a random number (or a timestamp...) in a get parameter tricks the browser into really making the request (instead of using the browser cache).

This method is some kind of "hack" the webdevs use so that they are sure the request actually happens.

Since you aren't using a web browser, I'm pretty sure you could totally ignore this parameter, and still get the refreshed data.

--- Edit ---

Actually r seems to be required, and has to be updated.

#!/bin/bash
wget https://eyes.nasa.gov/dsn/data/dsn.xml?r=$(date +%s) -O a.xml -nv
while true; do
  sleep 1
  wget https://eyes.nasa.gov/dsn/data/dsn.xml?r=$(date +%s) -O b.xml -nv
  diff a.xml b.xml
  cp b.xml a.xml -f
done

You don't need to emulate a browser. Simply set r to anything and increment it. (Or use a timestamp)