Last active
February 21, 2022 03:10
-
-
Save Jithender5913/08a12d2ed27850febe423bc15ea31d20 to your computer and use it in GitHub Desktop.
ISS Overhead notifier project using Python SMTP Library, API and Datetime module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from datetime import datetime | |
import smtplib | |
import time | |
MY_LAT = 51.507351 # Your latitude | |
MY_LONG = -0.127758 # Your longitude | |
MY_EMAIL = "sXXX@yahoo.com" | |
MY_PASSWORD = "xxx" | |
def 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"]) | |
print(iss_latitude) | |
print(iss_longitude) | |
# Your position is within +5 or -5 degrees of the ISS position. | |
if iss_latitude - MY_LAT <= 5 and 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: # this is a 24-hour format | |
return True | |
# If the ISS is close to my current position | |
# and if it is currently dark | |
# Then email me to tell me to look up. | |
# run the code every 60 seconds. | |
while True: | |
time.sleep(60) | |
if iss_overhead() and is_night(): | |
with smtplib.SMTP("smtp.mail.yahoo.com") as connection: | |
connection.starttls() | |
connection.login(MY_EMAIL, MY_PASSWORD) | |
connection.sendmail(from_addr=MY_EMAIL, to_addrs=MY_EMAIL, | |
msg="LOOK UP\n\nLOOK UP. There is the ISS") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment