-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 33_ISS_overhead_notifier.py
51 lines (35 loc) · 1.19 KB
/
Day 33_ISS_overhead_notifier.py
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
import requests
from datetime import datetime
import smtplib
import time
my_lat = 51.507351
my_long = -0.127758
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"])
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
email = example_email
password = password1234
while True:
time.sleep(60)
if my_lat - 5 <= iss_latitude <= my_lat + 5 and my_long - 5 <= iss_longitude <= my_long + 5 or sunset <= time_now <= sunrise:
connection = smtplib.SMTP("smtp.gmail.com")
connection.starttls()
connection.login(email, password)
connection.sendmail(
from_addr= email,
to_addr = email,
msg="Look up \\n The ISS is above you"
)