From 8fd414dc9f957f0e22bea11646b24bec13747838 Mon Sep 17 00:00:00 2001 From: wgaylord Date: Wed, 24 Oct 2018 16:37:05 -0500 Subject: [PATCH] Color the lines and make the case of no TLE work better. --- satnogs.py | 6 +++--- templates/map.html | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/satnogs.py b/satnogs.py index c3cc992..0113182 100644 --- a/satnogs.py +++ b/satnogs.py @@ -4,7 +4,7 @@ from flask import Flask , render_template,redirect,url_for import json from apscheduler.schedulers.background import BackgroundScheduler import ephem -from satnogs_api_client import fetch_satellites, DB_BASE_URL +from satnogs_api_client import fetch_satellites, DB_BASE_URL,fetch_tle_of_observation from satellite_tle import fetch_tles scheduler = BackgroundScheduler() @@ -177,8 +177,8 @@ def api_occuring_sats(): obs = {} for x in Passes: if x.satellite['norad_cat_id'] not in TLEs.keys(): - q = requests.get("https://db.satnogs.org/satellite_position/"+str( x.satellite['norad_cat_id'])).json() - TLEs[ x.satellite['norad_cat_id'] ] = [str(q["name"]),str(q["tle1"]),str(q["tle2"])] + q = fetch_tle_of_observation(x.id) + TLEs[ x.satellite['norad_cat_id'] ] = [str(x.satellite["name"]),str(q[0]),str(q[1])] satellite = ephem.readtle(TLEs[x.satellite['norad_cat_id']][0],TLEs[x.satellite['norad_cat_id']][1],TLEs[x.satellite['norad_cat_id']][2]) now = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') satellite.compute(now) diff --git a/templates/map.html b/templates/map.html index 600b95d..4bf2784 100644 --- a/templates/map.html +++ b/templates/map.html @@ -68,6 +68,8 @@ stationList = {} {%endfor%} + + var sats = {} var links = {} @@ -85,7 +87,7 @@ var links = {} $.get("/api/satstationpairs", function(data, status){ data = JSON.parse(data) data.forEach(function(entry){ - firstpolyline = new L.Polyline([[stationList[entry[0]]._latlng.lat,stationList[entry[0]]._latlng.lng],[sats[entry[1]]._latlng.lat,sats[entry[1]]._latlng.lng]], {color: 'red',weight: 3,opacity: 1,smoothFactor: 1}); + firstpolyline = new L.Polyline([[stationList[entry[0]]._latlng.lat,stationList[entry[0]]._latlng.lng],[sats[entry[1]]._latlng.lat,sats[entry[1]]._latlng.lng]], {color: '#'+entry[1].toString(16).repeat(2).substr(0,6),weight: 3,opacity: 1,smoothFactor: 1}); firstpolyline.addTo(mymap) firstpolyline.bringToFront() links[entry[0]] = firstpolyline @@ -133,7 +135,7 @@ setInterval(function(){ }) data.forEach(function(entry){ - firstpolyline = new L.Polyline([[stationList[entry[0]]._latlng.lat,stationList[entry[0]]._latlng.lng],[sats[entry[1]]._latlng.lat,sats[entry[1]]._latlng.lng]], {color: 'red',weight:3,opacity:1,smoothFactor: 1}); + firstpolyline = new L.Polyline([[stationList[entry[0]]._latlng.lat,stationList[entry[0]]._latlng.lng],[sats[entry[1]]._latlng.lat,sats[entry[1]]._latlng.lng]], {color: '#'+entry[1].toString(16).repeat(2).substr(0,6),weight:3,opacity:1,smoothFactor: 1}); firstpolyline.addTo(mymap) links[entry[0]] = firstpolyline stationList[entry[0]].setIcon(active_station)