-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
28 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,49 @@ | ||
import requests | ||
from datetime import datetime | ||
|
||
MY_LAT = 51.507351 # Your latitude | ||
MY_LONG = -0.127758 # Your longitude | ||
|
||
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"]) | ||
|
||
#Your position is within +5 or -5 degrees of the ISS position. | ||
|
||
|
||
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() | ||
import time | ||
import smtplib | ||
|
||
MY_LAT = 51.507351 # Your latitude | ||
MY_LONG = -0.127758 # Your longitude | ||
|
||
|
||
def is_iss_here(): | ||
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"]) | ||
|
||
# Your position is within +5 or -5 degrees of the ISS position. | ||
if MY_LONG - 5 <= iss_longitude <= MY_LONG + 5 and MY_LAT - 5 <= iss_latitude <= MY_LAT + 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() | ||
print(data) | ||
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 | ||
|
||
#If the ISS is close to my current position | ||
# and it is currently dark | ||
# Then send me an email to tell me to look up. | ||
# Then print message to tell me to look up. | ||
# BONUS: run the code every 60 seconds. | ||
|
||
|
||
while True: | ||
time.sleep(60) | ||
if is_iss_here() and is_night(): | ||
print("Look up! ISS is here") | ||
|