Skip to content

Instantly share code, notes, and snippets.

@jgcasta
Last active June 10, 2016 19:31
Show Gist options
  • Save jgcasta/10599129 to your computer and use it in GitHub Desktop.
Save jgcasta/10599129 to your computer and use it in GitHub Desktop.
Get TLE orbital elements for a NORAD ID satellite and date
#!/usr/bin/env python
# -*- coding: utf-8
'''
GEt TLE orbital elements for a Satellite
@author Jose Gomez Castaño jgcasta@gmail.com
@version 1.0.0
@precondition username and password to login into www.space-track.org website is needed
'''
import urllib, urllib2, cookielib
import datetime
noradId = '25544'
fecha = '2014/04/01'
baseURL = 'https://www.space-track.org'
username = 'youruser'
password = 'yourpass'
d = datetime.datetime.strptime(fecha, "%Y/%m/%d")
d1 = d + datetime.timedelta(days=1)
dstr = d.strftime("%Y-%m-%d")
d1str = d1.strftime("%Y-%m-%d")
print "Connecting..."
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
parameters = urllib.urlencode({'identity': username ,'password': password})
opener.open(baseURL + '/ajaxauth/login', parameters)
queryString = baseURL +"/basicspacedata/query/class/tle/format/tle/NORAD_CAT_ID/"+noradId+"/EPOCH/"+dstr+"%2000:00:00--"+d1str+"%2000:00:00"
resp = opener.open(queryString)
TLE = resp.read()
print "---------------------------------TLE---------------------------------\n"
print TLE
opener.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment