diff --git a/satnogs.py b/satnogs.py index d128593..a35d1b0 100644 --- a/satnogs.py +++ b/satnogs.py @@ -2,6 +2,7 @@ from datetime import datetime , timedelta import requests from flask import Flask , render_template,redirect,url_for import json +import random from apscheduler.schedulers.background import BackgroundScheduler from satnogs_api_client import fetch_satellites, DB_BASE_URL,fetch_tle_of_observation from satellite_tle import fetch_tles @@ -14,6 +15,7 @@ Passes = [] Occuring_sats = {} Stations = [] TLEs = {} +Transmitters = {} class Pass: id = 0 @@ -61,6 +63,7 @@ def getActive(): temp.start = datetime.strptime(x["start"],'%Y-%m-%dT%H:%M:%Sz') temp.end = datetime.strptime(x["end"],'%Y-%m-%dT%H:%M:%Sz') temp.ground_station = x["ground_station"] + temp.transmitter = x["transmitter"] temp.norad = str(x["norad_cat_id"]) try: temp.satellite = requests.get("https://db.satnogs.org/api/satellites/"+str(x["norad_cat_id"])).json() @@ -98,6 +101,18 @@ def GetGroundStations(): return stations +@scheduler.scheduled_job('interval',days=5) +def updateTransmitters(): + global Transmitters + print "Updating Transmitters" + temp = requests.get("https://db.satnogs.org/api/transmitters/").json() + for x in temp: + if str(x["norad_cat_id"]) in Transmitters.keys(): + Transmitters[str(x["norad_cat_id"])][x["uuid"]] = [x["description"],"#"+str("%06x" % random.randint(0, 0xFFFFFF))] + else: + Transmitters[str(x["norad_cat_id"])]={} + Transmitters[str(x["norad_cat_id"])][x["uuid"]] = [x["description"],"#"+str("%06x" % random.randint(0, 0xFFFFFF))] + #print Transmitters @scheduler.scheduled_job('interval',minutes=3) def updatePasses(): @@ -153,11 +168,18 @@ def api_active_stations(): @app.route('/stations_from_sat/') def api_occuring_observations(norad): obs = [] + trans = [] for x in Passes: if x.norad == norad: - obs.append(x.ground_station) - - return json.dumps(obs) + obs.append([x.ground_station,Transmitters[norad][x.transmitter][1]]) + trans.append(x.transmitter) + #print Transmitters[norad].values() + + transList = [] + for x in set(trans): + transList.append(Transmitters[norad][x]) + #print transList,norad + return json.dumps([obs,transList]) @app.route('/occuring_sats') def api_occuring_sats(): @@ -170,5 +192,6 @@ def api_occuring_sats(): updatePasses() updateStations() updateTLE() +updateTransmitters() scheduler.start() app.run(use_reloader=False,host = "0.0.0.0",port=5001) \ No newline at end of file diff --git a/satnogs_api_client.pyc b/satnogs_api_client.pyc new file mode 100644 index 0000000..91a2e0b Binary files /dev/null and b/satnogs_api_client.pyc differ diff --git a/static/Worker.js b/static/Worker.js index e02410c..72c91e0 100644 --- a/static/Worker.js +++ b/static/Worker.js @@ -23,7 +23,11 @@ setInterval(function(){ var longitude = positionGd.longitude var latitude = positionGd.latitude - postMessage([norad,TLE[0],[degress(latitude),degress(longitude)],groundStations]) + if (groundStations[1] == undefined){ + groundStations.push([]) + } + + postMessage([norad,TLE[0],[degress(latitude),degress(longitude)],groundStations[0],groundStations[1]]) }, 500); diff --git a/templates/map.html b/templates/map.html index df6d341..dc32f03 100644 --- a/templates/map.html +++ b/templates/map.html @@ -91,25 +91,42 @@ function UpdateMap(e) { var name = e.data[1] var satPos = e.data[2] if (norad in Sats){ - Sats[norad]._latlng = {"lat":satPos[0],"lng":satPos[1]} + Sats[norad]._latlng = {"lat":satPos[0],"lng":satPos[1]} Sats[norad].update() }else{ Sats[norad] = L.marker(satPos,{icon: dark_sat,zIndexOffset:1000}).addTo(mymap); - Sats[norad].bindPopup("Name: "+name+"
Norad: "+norad+""); Lines[norad] = {} - e.data[3].forEach(function(x){ - Lines[norad][x] = new L.Polyline([[Stations[x]._latlng.lat,Stations[x]._latlng.lng],[satPos[0],satPos[1]]], {color: '#'+norad.toString(16).repeat(2).substr(0,6),weight: 3,opacity: 1,smoothFactor: 1}); - Lines[norad][x].addTo(mymap) - }); + + + } + + popupText = "Name: "+name+"
Norad: "+norad+"
Station Count: "+e.data[3].length+"
" - Object.keys(Lines[norad]).forEach(function(x){ - if (e.data[3].includes(Number(x))){ - Lines[norad][x]._latlngs[1]= {"lat":satPos[0],"lng":satPos[1]} + e.data[4].forEach(function(x){ + //console.log(x + " "+norad) + popupText = popupText + '
'+x[0]+"

" + }) + Sats[norad].bindPopup(popupText) + Sats[norad]._popup.setContent(popupText) + + temp = [] + e.data[3].forEach(function(x){ + temp.push(x[0]) + }) + + e.data[3].forEach(function(x){ + if (Object.keys(Lines[norad]).includes(Number(x[0]))){ + Object.keys(Lines[norad]).forEach(function(y){ + if (temp.includes(Number(y))){ + Lines[norad][y]._latlngs[1]= {"lat":satPos[0],"lng":satPos[1]} }else{ - Lines[norad][x].removeFrom(mymap) - delete Lines[norad][x] + Lines[norad][x[0]].removeFrom(mymap) + delete Lines[norad][x[0]] } + + })}else{Lines[norad][x[0]] = new L.Polyline([[Stations[x[0]]._latlng.lat,Stations[x[0]]._latlng.lng],[satPos[0],satPos[1]]], {color: x[1],weight: 3,opacity: 1,smoothFactor: 1}); + Lines[norad][x[0]].addTo(mymap)}; })