-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 33 - ISS Overhead Notifier
55 lines (44 loc) · 1.62 KB
/
Day 33 - ISS Overhead Notifier
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#Day 33: Build a program that will send you an email notification if the ISS is overhead your current/ selected location.
import requests
from datetime import datetime
import smtplib
import time
MY_LAT = -74.277496
MY_LONG = 40.606010
my_email = "testing123@gmail.com"
password = "Abcd1234()"
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"])
if MY_LAT-5 <= iss_latitude <= MY_LAT+5 and MY_LONG-5 <= iss_longitude <= MY_LONG+5:
return True
else:
return False
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()
if time_now.hour >= sunset or time_now.hour <= sunrise:
return True
while True:
time.sleep(60)
if iss_overhead() and is_night():
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(user=my_email, password=password)
connection.sendmail(
from_addr=my_email,
to_addrs=my_email,
msg=f"Subject:Look Up!\n\nThe ISS is passing through your area now."
)