-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (41 loc) · 1.45 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
49
import requests
from datetime import datetime, timezone
import smtplib
import time
LAT = 16.544893
LNG = 81.521240
EMAIL = "[email protected]"
PASS = "9samplegmail"
def iss_in_local_position():
response = requests.get(url="http://api.open-notify.org/iss-now.json")
response.raise_for_status()
data = response.json()
iss_lat = float(data["iss_position"]["latitude"])
iss_lng = float(data["iss_position"]["longitude"])
if LAT-5 <= iss_lat <= LAT+5 and LNG-5 <= iss_lng <= LNG+5:
return True
def mid_night():
parameters = {
"lat": LAT,
"lng": LNG,
"formatted": 0
}
res = requests.get(url="https://api.sunrise-sunset.org/json", params=parameters,)
res.raise_for_status()
data = res.json()
sunrise = int(data["results"]["sunrise"].split("T")[1].split(":")[0])
sunset = int(data["results"]["sunset"].split("T")[1].split(":")[0])
current_time = datetime.now(timezone.utc).hour
if current_time >= sunset or current_time <= sunrise:
return True
while True:
time.sleep(1800) # 30 mins
if iss_in_local_position() and mid_night():
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(user=EMAIL, password=PASS)
connection.sendmail(
from_addr=EMAIL,
to_addrs=EMAIL,
msg="Subject: Look up \n\nISS is right above you look for it!! "
)