Skip to content

Instantly share code, notes, and snippets.

@wgaylord
Created October 24, 2018 20:25
Show Gist options
  • Save wgaylord/4099f1622afe27ca4801e41b83b191e6 to your computer and use it in GitHub Desktop.
Save wgaylord/4099f1622afe27ca4801e41b83b191e6 to your computer and use it in GitHub Desktop.
from datetime import datetime , timedelta
import requests
import json
class Pass:
id = 0
start = None
end = None
ground_station = None
satellite = None
transmitter = None
def __repr__(self):
return "\n<ID>: {}\n<Start>: {}\n<End>: {}\n<Ground Station>: {}\n<Satellite> {}\n<Transmitter>: {}".format(self.id,self.start.strftime('%Y-%m-%dT%H:%M:%S%z'),self.end.strftime('%Y-%m-%dT%H:%M:%S%z'),self.ground_station,json.dumps(self.satellite,indent = 1),json.dumps(self.transmitter,indent=1))
def getActive():
start = (datetime.utcnow() - timedelta(0,0,0,0,20)).strftime('%Y-%m-%dT%H:%M:%S%z')
end = (datetime.utcnow() + timedelta(0,0,0,0,30)).strftime('%Y-%m-%dT%H:%M:%S%z')
passesR = requests.get("https://network.satnogs.org/api/observations/?end="+end+"&format=json&start="+start)
passes = passesR.json()
if passesR.links.has_key("next"):
while passesR.links.has_key("next"):
passesR = requests.get(passesR.links["next"]["url"])
passes += passesR.json()
ground_stations = {}
for x in passes:
if datetime.strptime(x["start"],'%Y-%m-%dT%H:%M:%Sz') > datetime.utcnow() or datetime.strptime(x["end"],'%Y-%m-%dT%H:%M:%Sz') < datetime.utcnow():
passes.remove(x)
else:
if ground_stations.has_key(x["ground_station"]):
ground_stations[x["ground_station"]].append(x)
else:
ground_stations[x["ground_station"]] = []
ground_stations[x["ground_station"]].append(x)
passes = []
for x in ground_stations:
start = datetime.utcnow()
current = {"start":datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S%z')+"z"}
for y in ground_stations[x]:
if datetime.strptime(y["start"],'%Y-%m-%dT%H:%M:%Sz') < datetime.strptime(current["start"],'%Y-%m-%dT%H:%M:%Sz'):
current = y
passes.append(current)
Passes =[]
for x in passes:
temp = Pass()
temp.id = x["id"]
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.satellite = requests.get("https://db.satnogs.org/api/satellites/"+str(x["norad_cat_id"])) .json()
temp.transmitter = requests.get("https://db.satnogs.org/api/transmitters/"+x["transmitter"]).json()
Passes.append(temp)
return Passes
def GetGroundStations():
stationsR = requests.get("https://network.satnogs.org/api/stations/")
stations = stationsR.json()
while stationsR.links.has_key("next"):
stationsR = requests.get(stationsR.links["next"]["url"])
stations += stationsR.json()
for x in stations:
if x["last_seen"] == None:
stations.remove(x)
continue
if datetime.strptime(x["last_seen"],'%Y-%m-%dT%H:%M:%Sz') < (datetime.utcnow()- timedelta(10,0,0,0)):
stations.remove(x)
for x in stations:
if x["last_seen"] == None:
stations.remove(x)
continue
if datetime.strptime(x["last_seen"],'%Y-%m-%dT%H:%M:%Sz') < (datetime.utcnow()- timedelta(10,0,0,0)):
stations.remove(x)
return stations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment