#http://open-notify.org/Open-Notify-API/ISS-Location-Now/
#http://api.open-notify.org/iss-now.json
#https://www.latlong.net/
import requests
from datetime import datetime as dt
import time
def is_iss_overhead():
response=requests.get(url="http://api.open-notify.org/iss-now.json")
response.raise_for_status()
response_data=response.json()
iss_lat=float(response_data["iss_position"]["latitude"])
iss_longitude=float(response_data["iss_position"]["longitude"])
#Your position is within +5 or -5 degrees of the ISS position
if parameters["lat"]-5<=iss_lat<=parameters["lat"]+5 and parameters["lng"]-5<=iss_longitude<=parameters["lng"]+5:
return True
def is_night():
parameters={
"lat":12.971599,
"lng":77.594566,
"formatted":0
}
response=requests.get("https://api.sunrise-sunset.org/json",params=parameters)
response.raise_for_status()
response_data=response.json()
sunrise=response_data["results"]["sunrise"].split("T")[1].split(":")[0]
sunset=response_data["results"]["sunset"].split("T")[1].split(":")[0]
time_now=dt.now().hour()
if time_now>=sunset or time_now<=sunrise:
return True
while True:
time.sleep(60)
if is_iss_overhead() and is_night():
#TODO: send email function
pass