ocssw
V2022
|
spacetrack_tles.py
Go to the documentation of this file.
14 norad = {
34 description='This script retrieves Two-Line Elements from www.space-track.org for a given satellite name or NORAD catalog ID')
36 parser.add_argument('satellite',nargs='?', help='Satellite TLE to retrieve. "ALL" will return TLEs for all in the list above.', type=str,
54 parser.add_argument('--ofile','-o', type=str, default=None, help="Name of file to store retreived TLE")
55 parser.add_argument('--catID', '-c', type=int, default=None, help='NORAD Catalog ID of satellite to retrieve; ingored if a satellite name is provided.')
58 parser.add_argument('--copyTCE', default=False, action='store_true', help="Copy TLE to latest '<satellite>.tce' file")
59 parser.add_argument('--directory','-d', type=str, default=os.getcwd(), help="Direcotry to write TLEs; default is the current working directory")
60 parser.add_argument('--norad_catIDs', '-n', type=str, default=os.path.join(os.environ['OCDATAROOT'],'common','norad_catalog.json'), help="JSON file in the form {'satellite':<catID>}")
63 args = parser.parse_args()
66 logging.basicConfig(level=logging.DEBUG)
68 identity = args.username
69 password = args.password
76 parts = line.split()
83 sys.exit("Authentication credentials required! Check your $HOME/.netrc or pass in via --username/--password")
85 baseTLEdir = args.directory
95 elif args.norad_catIDs == os.path.join(os.environ['OCDATAROOT'],'common','norad_catalog.json') and not os.path.isfile(args.norad_catIDs):
117 tleurl = '/'.join([baseurl,"basicspacedata","query","class","tle_latest","ORDINAL","1","NORAD_CAT_ID",tleIDs,"format","tle"])
120 stConn = requests.Session()
123 tlehash = {}
126 req = stConn.post(loginurl, data=credentials)
128 sys.exit("Received response: %d from space-track.org...unable to log in...exiting..." % req.status_code)
138 tlereq = stConn.get(tleurl)
165 tle = tlehash[tleID]
169 tleDate = tle[0].split()[3]
171 doy = tleDate[2:5]
188 tceFile, ext = os.path.splitext(tleFile)