2

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: https://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

Community
  • 1
  • 1
uhoh
  • 3,713
  • 6
  • 42
  • 95
  • checking the page it seems sequential, so it's not some secret key... the thing is finding out what it represents. It is probably a number of seconds from some event like the linux timestamp is from 1970/1/1 – Aquiles Jul 23 '16 at 03:59
  • Maybe you could just check a specific time and see the difference between the number and the actual time and just make your queries from there – Aquiles Jul 23 '16 at 04:00
  • 3
    Here it is: Math.floor(new Date().getTime() / 5000) it was in the sites.js file – Aquiles Jul 23 '16 at 04:06
  • It's pretty obvious if you just compare it to the current time: Current number is `293849324`, current time is `1469246735.635`, it's easy to see that's the time*2/10. – Aran-Fey Jul 23 '16 at 04:12
  • @Aquiles nice! So what is that exactly? Oh I see - (seconds since Jan 1, 1970) divided by 5. Great - would you like to leave it as an answer? – uhoh Jul 23 '16 at 04:12
  • @Rawing I work in multiple area - right now I mostly use [Julian Day](https://en.wikipedia.org/wiki/Julian_day), so January 1, 1970 was not *obvious to me*, though in the future it will be :) – uhoh Jul 23 '16 at 04:13
  • It's ok It's actually not a complete answer since the service seems to be protected and I haven't been able to call it. It always returns a 403 which is forbidden, so there must be some kind of header I'm not using – Aquiles Jul 23 '16 at 04:17
  • @Aquiles I had a hunch - thus the "*(time code? authorization? secret password?)*" part of my question. I don't want to do anything that's not allowed and welcome - NASA has enough challenges already trying to talk to a *fourty year old spacecraft 20 billion kilometers away*! – uhoh Jul 23 '16 at 04:20
  • maybe ask for an API, probably they have it – Aquiles Jul 23 '16 at 04:23
  • @Aquiles NASA is fantastic about putting information out there for the public - for example the DSCOVR satellite's EPIC camera pics, Mars rovers, etc. So far I haven't found any mention of an API offered for the *DSN Now* page. – uhoh Jul 23 '16 at 04:33

2 Answers2

2

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)

Loïc
  • 11,804
  • 1
  • 31
  • 49
  • I believe it's clean now :-) – Loïc Jul 23 '16 at 04:28
  • So far I keep getting 3 hour old data while monitoring `[float(sig['power']) for sig in dish['downSignal']]`, something that clearly fluctuates. This isn't working for me - may need to use a browser emulator as described by @alecxe in [this answer](http://stackoverflow.com/a/34459360/3904031). – uhoh Jul 23 '16 at 08:03
  • 1
    Bingo! Thank you for your persistence - incrementing a random number produces data that seems to track the web page in real time. Now watching Voyager 2, a signal that was sent 15 hours ago :) – uhoh Jul 23 '16 at 11:39
2

Regarding your updated question, why avoid sending the r query string parameter when it is very easy to generate it? Also, with the requests module, it's easy to send the parameter with the request too:

import time
import requests
import xml.etree.ElementTree as ET

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

r = int(time.time() / 5)
response = requests.get(url, params={'r': r})
root = ET.fromstring(response.content)
# etc....
mhawke
  • 84,695
  • 9
  • 117
  • 138
  • I was trying to work within the question/answer paradigm, working with the author of the only answer to get it right, and learning how to do all of this in the process (thus the script). It looks like you've posted this within seconds of me verifying that it was working with a random number and accepting the other answer. Thank you for your answer too! – uhoh Jul 23 '16 at 11:43
  • It seems to be working with the `?r=42` parameter within the url string itself, but you just taught me how to use a params dictionary - big bonus for me, thanks again! – uhoh Jul 23 '16 at 11:46