mirror of
https://github.com/smittix/intercept.git
synced 2026-07-07 17:18:11 -07:00
Swap ISS position API priority to avoid timeout delays
Open Notify API (api.open-notify.org) is frequently unreliable, causing 5-second timeout delays on every ISS position request. Promote wheretheiss.at as the primary API in both satellite.py and sstv.py, demoting Open Notify to fallback. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+14
-14
@@ -42,30 +42,30 @@ def _fetch_iss_realtime(observer_lat: Optional[float] = None, observer_lon: Opti
|
|||||||
iss_alt = 420 # Default altitude in km
|
iss_alt = 420 # Default altitude in km
|
||||||
source = None
|
source = None
|
||||||
|
|
||||||
# Try primary API: Open Notify
|
# Try primary API: Where The ISS At
|
||||||
try:
|
try:
|
||||||
response = requests.get('http://api.open-notify.org/iss-now.json', timeout=5)
|
response = requests.get('https://api.wheretheiss.at/v1/satellites/25544', timeout=5)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if data.get('message') == 'success':
|
iss_lat = float(data['latitude'])
|
||||||
iss_lat = float(data['iss_position']['latitude'])
|
iss_lon = float(data['longitude'])
|
||||||
iss_lon = float(data['iss_position']['longitude'])
|
iss_alt = float(data.get('altitude', 420))
|
||||||
source = 'open-notify'
|
source = 'wheretheiss'
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Open Notify API failed: {e}")
|
logger.debug(f"Where The ISS At API failed: {e}")
|
||||||
|
|
||||||
# Try fallback API: Where The ISS At
|
# Try fallback API: Open Notify
|
||||||
if iss_lat is None:
|
if iss_lat is None:
|
||||||
try:
|
try:
|
||||||
response = requests.get('https://api.wheretheiss.at/v1/satellites/25544', timeout=5)
|
response = requests.get('http://api.open-notify.org/iss-now.json', timeout=5)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
iss_lat = float(data['latitude'])
|
if data.get('message') == 'success':
|
||||||
iss_lon = float(data['longitude'])
|
iss_lat = float(data['iss_position']['latitude'])
|
||||||
iss_alt = float(data.get('altitude', 420))
|
iss_lon = float(data['iss_position']['longitude'])
|
||||||
source = 'wheretheiss'
|
source = 'open-notify'
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Where The ISS At API failed: {e}")
|
logger.debug(f"Open Notify API failed: {e}")
|
||||||
|
|
||||||
if iss_lat is None:
|
if iss_lat is None:
|
||||||
return None
|
return None
|
||||||
|
|||||||
+26
-26
@@ -467,7 +467,32 @@ def iss_position():
|
|||||||
observer_lat = request.args.get('latitude', type=float)
|
observer_lat = request.args.get('latitude', type=float)
|
||||||
observer_lon = request.args.get('longitude', type=float)
|
observer_lon = request.args.get('longitude', type=float)
|
||||||
|
|
||||||
# Try primary API: Open Notify
|
# Try primary API: Where The ISS At
|
||||||
|
try:
|
||||||
|
response = requests.get('https://api.wheretheiss.at/v1/satellites/25544', timeout=5)
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
iss_lat = float(data['latitude'])
|
||||||
|
iss_lon = float(data['longitude'])
|
||||||
|
|
||||||
|
result = {
|
||||||
|
'status': 'ok',
|
||||||
|
'lat': iss_lat,
|
||||||
|
'lon': iss_lon,
|
||||||
|
'altitude': float(data.get('altitude', 420)),
|
||||||
|
'timestamp': datetime.utcnow().isoformat(),
|
||||||
|
'source': 'wheretheiss'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Calculate observer-relative data if location provided
|
||||||
|
if observer_lat is not None and observer_lon is not None:
|
||||||
|
result.update(_calculate_observer_data(iss_lat, iss_lon, observer_lat, observer_lon))
|
||||||
|
|
||||||
|
return jsonify(result)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Where The ISS At API failed: {e}")
|
||||||
|
|
||||||
|
# Try fallback API: Open Notify
|
||||||
try:
|
try:
|
||||||
response = requests.get('http://api.open-notify.org/iss-now.json', timeout=5)
|
response = requests.get('http://api.open-notify.org/iss-now.json', timeout=5)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@@ -493,31 +518,6 @@ def iss_position():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Open Notify API failed: {e}")
|
logger.warning(f"Open Notify API failed: {e}")
|
||||||
|
|
||||||
# Try fallback API: Where The ISS At
|
|
||||||
try:
|
|
||||||
response = requests.get('https://api.wheretheiss.at/v1/satellites/25544', timeout=5)
|
|
||||||
if response.status_code == 200:
|
|
||||||
data = response.json()
|
|
||||||
iss_lat = float(data['latitude'])
|
|
||||||
iss_lon = float(data['longitude'])
|
|
||||||
|
|
||||||
result = {
|
|
||||||
'status': 'ok',
|
|
||||||
'lat': iss_lat,
|
|
||||||
'lon': iss_lon,
|
|
||||||
'altitude': float(data.get('altitude', 420)),
|
|
||||||
'timestamp': datetime.utcnow().isoformat(),
|
|
||||||
'source': 'wheretheiss'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Calculate observer-relative data if location provided
|
|
||||||
if observer_lat is not None and observer_lon is not None:
|
|
||||||
result.update(_calculate_observer_data(iss_lat, iss_lon, observer_lat, observer_lon))
|
|
||||||
|
|
||||||
return jsonify(result)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"Where The ISS At API failed: {e}")
|
|
||||||
|
|
||||||
# Both APIs failed
|
# Both APIs failed
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'status': 'error',
|
'status': 'error',
|
||||||
|
|||||||
Reference in New Issue
Block a user