-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (38 loc) · 1.5 KB
/
main.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
import requests
from datetime import datetime
import smtplib
import time
MY_LAT= 36.778259
MY_LONG= -119.417931
def is_iss_close_to_me():
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 and MY_LAT + 5 >= iss_latitude):
if (MY_LONG - 5 <= iss_longitude and MY_LONG + 5 >= iss_longitude):
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_close_to_me() and is_night():
with smtplib.SMTP("smtp.gmail.com", port=587) as connection:
connection.starttls()
connection.login(user="[email protected]", password="gdwaoiwzpupscepw")
connection.sendmail(from_addr="[email protected]", to_addrs="[email protected]",
msg=f"Subject:Look Up\n\nThe ISS is above you in the sky")
is_iss_close_to_me()