Add missing dep
parent
6f91791bf1
commit
79054d0ece
|
@ -0,0 +1,2 @@
|
|||
from .fetch_tle import * # noqa
|
||||
from .fetch_tles import * # noqa
|
Binary file not shown.
|
@ -0,0 +1,64 @@
|
|||
import csv
|
||||
from lxml import html
|
||||
import requests
|
||||
import pkg_resources
|
||||
|
||||
SOURCES_LIST = pkg_resources.resource_filename('satellite_tle', 'sources.csv')
|
||||
|
||||
|
||||
def get_tle_sources():
|
||||
'''
|
||||
Returns a list of (source, url)-tuples for well-known TLE sources.
|
||||
'''
|
||||
|
||||
sources = []
|
||||
|
||||
with open(SOURCES_LIST) as csvfile:
|
||||
csv_reader = csv.reader(csvfile,
|
||||
delimiter=',',
|
||||
quotechar='\'',
|
||||
quoting=csv.QUOTE_NONNUMERIC)
|
||||
for row in csv_reader:
|
||||
source, url = row
|
||||
sources.append((source, url))
|
||||
|
||||
return sources
|
||||
|
||||
|
||||
def fetch_tle_from_celestrak(norad_cat_id):
|
||||
'''
|
||||
Returns the TLE for a given norad_cat_id as currently available from CelesTrak.
|
||||
Raises IndexError if no data is available for the given norad_cat_id.
|
||||
'''
|
||||
|
||||
r = requests.get('https://www.celestrak.com/satcat/tle.php?CATNR={}'.format(norad_cat_id))
|
||||
page = html.fromstring(r.text)
|
||||
|
||||
tle = page.xpath('//pre/text()')[0].split('\n')
|
||||
if tle[1].strip() == 'No TLE found':
|
||||
raise LookupError
|
||||
|
||||
return tle[1].strip(), tle[2].strip(), tle[3].strip()
|
||||
|
||||
|
||||
def fetch_tles_from_url(url):
|
||||
'''
|
||||
Downloads the TLE set from the given url.
|
||||
Returns a dictionary of the form {norad_id1: tle1, norad_id2: tle2} for all TLEs found.
|
||||
tleN is returned as list of three strings: [satellite_name, line1, line2].
|
||||
'''
|
||||
|
||||
r = requests.get(url)
|
||||
|
||||
tles = dict()
|
||||
l0 = ''
|
||||
l1 = ''
|
||||
lines = r.text.splitlines()
|
||||
for l in lines[:-1]:
|
||||
if l[0] == '2':
|
||||
norad_cat_id = int(l1[2:7].encode('ascii'))
|
||||
tles[norad_cat_id] = (l0.strip(), l1, l)
|
||||
l0 = l1
|
||||
l1 = l
|
||||
|
||||
return tles
|
Binary file not shown.
|
@ -0,0 +1,66 @@
|
|||
from __future__ import print_function
|
||||
|
||||
from sgp4.earth_gravity import wgs72
|
||||
from sgp4.io import twoline2rv
|
||||
|
||||
from . import get_tle_sources, fetch_tles_from_url, fetch_tle_from_celestrak
|
||||
|
||||
|
||||
def fetch_tles(requested_norad_ids):
|
||||
'''
|
||||
Returns the most recent TLEs found for the requested satellites
|
||||
available via Celestrak, CalPoly and AMSAT.
|
||||
'''
|
||||
|
||||
# List of 2-tuples of the form (source, tle)
|
||||
# source is a human-readable string
|
||||
# tle is a 3-tuple of strings
|
||||
tles = dict()
|
||||
|
||||
def update_tles(source, tle):
|
||||
if norad_id not in requested_norad_ids:
|
||||
# Satellite not requested,
|
||||
# skip.
|
||||
return
|
||||
|
||||
if norad_id not in tles.keys():
|
||||
# Satellite requested and first occurence in the downloaded data,
|
||||
# store new TLE.
|
||||
#print('Found {}'.format(norad_id))
|
||||
tles[norad_id] = source, tle
|
||||
return
|
||||
|
||||
# There are multiple TLEs for this satellite available.
|
||||
# Parse and compare epoch of both TLEs and choose the most recent one.
|
||||
current_sat = twoline2rv(tles[norad_id][1][1], tles[norad_id][1][2], wgs72)
|
||||
new_sat = twoline2rv(tle[1], tle[2], wgs72)
|
||||
if new_sat.epoch > current_sat.epoch:
|
||||
# Found a more recent TLE than the current one,
|
||||
# store the new TLE.
|
||||
|
||||
tles[norad_id] = source, tle
|
||||
|
||||
# Fetch TLE sets from well-known TLE sources
|
||||
sources = get_tle_sources()
|
||||
|
||||
for source, url in sources:
|
||||
#print('Fetch from {}'.format(url))
|
||||
new_tles = fetch_tles_from_url(url=url)
|
||||
|
||||
for norad_id, tle in new_tles.items():
|
||||
update_tles(source, tle)
|
||||
|
||||
# Try fetching missing sats from another Celestrak endoint
|
||||
missing_norad_ids = set(requested_norad_ids) - set(tles.keys())
|
||||
|
||||
for norad_id in missing_norad_ids:
|
||||
try:
|
||||
#print('Fetching {} from Celestrak (satcat):'.format(norad_id), end='')
|
||||
tle = fetch_tle_from_celestrak(norad_id)
|
||||
#print(' ok, ', end='')
|
||||
update_tles('Celestrak (satcat)', tle)
|
||||
except LookupError:
|
||||
#print(' failed.')
|
||||
continue
|
||||
|
||||
return tles
|
Binary file not shown.
|
@ -0,0 +1,46 @@
|
|||
'CalPoly','http://mstl.atl.calpoly.edu/~ops/keps/kepler.txt'
|
||||
'AMSAT','https://www.amsat.org/amsat/ftp/keps/current/nasabare.txt'
|
||||
'Celestrak (tle-new)','https://www.celestrak.com/NORAD/elements/tle-new.txt'
|
||||
'Celestrak (stations)','https://www.celestrak.com/NORAD/elements/stations.txt'
|
||||
'Celestrak (visual)','https://www.celestrak.com/NORAD/elements/visual.txt'
|
||||
'Celestrak (1999-025)','https://www.celestrak.com/NORAD/elements/1999-025.txt'
|
||||
'Celestrak (iridium-33-debris)','https://www.celestrak.com/NORAD/elements/iridium-33-debris.txt'
|
||||
'Celestrak (cosmos-2251-debris)','https://www.celestrak.com/NORAD/elements/cosmos-2251-debris.txt'
|
||||
'Celestrak (2012-044)','https://www.celestrak.com/NORAD/elements/2012-044.txt'
|
||||
'Celestrak (weather)','https://www.celestrak.com/NORAD/elements/weather.txt'
|
||||
'Celestrak (noaa)','https://www.celestrak.com/NORAD/elements/noaa.txt'
|
||||
'Celestrak (goes)','https://www.celestrak.com/NORAD/elements/goes.txt'
|
||||
'Celestrak (resource)','https://www.celestrak.com/NORAD/elements/resource.txt'
|
||||
'Celestrak (sarsat)','https://www.celestrak.com/NORAD/elements/sarsat.txt'
|
||||
'Celestrak (dmc)','https://www.celestrak.com/NORAD/elements/dmc.txt'
|
||||
'Celestrak (tdrss)','https://www.celestrak.com/NORAD/elements/tdrss.txt'
|
||||
'Celestrak (argos)','https://www.celestrak.com/NORAD/elements/argos.txt'
|
||||
'Celestrak (planet)','https://www.celestrak.com/NORAD/elements/planet.txt'
|
||||
'Celestrak (spire)','https://www.celestrak.com/NORAD/elements/spire.txt'
|
||||
'Celestrak (geo)','https://www.celestrak.com/NORAD/elements/geo.txt'
|
||||
'Celestrak (intelsat)','https://www.celestrak.com/NORAD/elements/intelsat.txt'
|
||||
'Celestrak (ses)','https://www.celestrak.com/NORAD/elements/ses.txt'
|
||||
'Celestrak (iridium)','https://www.celestrak.com/NORAD/elements/iridium.txt'
|
||||
'Celestrak (iridium-NEXT)','https://www.celestrak.com/NORAD/elements/iridium-NEXT.txt'
|
||||
'Celestrak (orbcomm)','https://www.celestrak.com/NORAD/elements/orbcomm.txt'
|
||||
'Celestrak (globalstar)','https://www.celestrak.com/NORAD/elements/globalstar.txt'
|
||||
'Celestrak (amateur)','https://www.celestrak.com/NORAD/elements/amateur.txt'
|
||||
'Celestrak (other-comm)','https://www.celestrak.com/NORAD/elements/other-comm.txt'
|
||||
'Celestrak (gorizont)','https://www.celestrak.com/NORAD/elements/gorizont.txt'
|
||||
'Celestrak (raduga)','https://www.celestrak.com/NORAD/elements/raduga.txt'
|
||||
'Celestrak (molniya)','https://www.celestrak.com/NORAD/elements/molniya.txt'
|
||||
'Celestrak (gps-ops)','https://www.celestrak.com/NORAD/elements/gps-ops.txt'
|
||||
'Celestrak (glo-ops)','https://www.celestrak.com/NORAD/elements/glo-ops.txt'
|
||||
'Celestrak (galileo)','https://www.celestrak.com/NORAD/elements/galileo.txt'
|
||||
'Celestrak (beidou)','https://www.celestrak.com/NORAD/elements/beidou.txt'
|
||||
'Celestrak (sbas)','https://www.celestrak.com/NORAD/elements/sbas.txt'
|
||||
'Celestrak (nnss)','https://www.celestrak.com/NORAD/elements/nnss.txt'
|
||||
'Celestrak (musson)','https://www.celestrak.com/NORAD/elements/musson.txt'
|
||||
'Celestrak (science)','https://www.celestrak.com/NORAD/elements/science.txt'
|
||||
'Celestrak (geodetic)','https://www.celestrak.com/NORAD/elements/geodetic.txt'
|
||||
'Celestrak (engineering)','https://www.celestrak.com/NORAD/elements/engineering.txt'
|
||||
'Celestrak (education)','https://www.celestrak.com/NORAD/elements/education.txt'
|
||||
'Celestrak (military)','https://www.celestrak.com/NORAD/elements/military.txt'
|
||||
'Celestrak (radar)','https://www.celestrak.com/NORAD/elements/radar.txt'
|
||||
'Celestrak (cubesat)','https://www.celestrak.com/NORAD/elements/cubesat.txt'
|
||||
'Celestrak (other)','https://www.celestrak.com/NORAD/elements/other.txt'
|
|
Loading…
Reference in New Issue