From ad48efdea5f59b6fd59f5edaf27f6b71329206e5 Mon Sep 17 00:00:00 2001 From: Roshan Khausiya Date: Mon, 3 Oct 2022 12:36:12 +0545 Subject: [PATCH] isstracker.py Track international space station through API --- Python/isstracker.py | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Python/isstracker.py diff --git a/Python/isstracker.py b/Python/isstracker.py new file mode 100644 index 0000000..e96f5c0 --- /dev/null +++ b/Python/isstracker.py @@ -0,0 +1,55 @@ +import requests +from datetime import datetime +import smtplib +import time + +MY_EMAIL = "mail" +MY_PASSWORD = "password" +MY_LAT = 51.507351 # latitude +MY_LONG = -0.127758 # longitude + + +def is_iss_overhead(): + response = requests.get(url="http://api.open-notify.org/iss-now.json") + response.raise_for_status() + data = response.json() + + iss_latitude = float(data["iss_position"]["latitude"]) + iss_longitude = float(data["iss_position"]["longitude"]) + + #isis positions + if MY_LAT-5 <= iss_latitude <= MY_LAT+5 and MY_LONG-5 <= iss_longitude <= MY_LONG+5: + return True + + +def is_night(): + parameters = { + "lat": MY_LAT, + "lng": MY_LONG, + "formatted": 0, + } + response = requests.get("https://api.sunrise-sunset.org/json", params=parameters) + response.raise_for_status() + data = response.json() + sunrise = int(data["results"]["sunrise"].split("T")[1].split(":")[0]) + sunset = int(data["results"]["sunset"].split("T")[1].split(":")[0]) + + time_now = datetime.now().hour + + if time_now >= sunset or time_now <= sunrise: + return True + + +while True: + time.sleep(60) + if is_iss_overhead() and is_night(): + connection = smtplib.SMTP("__YOUR_SMTP_ADDRESS_HERE___") + connection.starttls() + connection.login(MY_EMAIL, MY_PASSWORD) + connection.sendmail( + from_addr=MY_EMAIL, + to_addrs=MY_EMAIL, + msg="Subject:Look Up👆\n\nISS has appeared now" + ) + +