Skip to content

Commit

Permalink
Day 33
Browse files Browse the repository at this point in the history
  • Loading branch information
neubrom committed Jan 19, 2022
1 parent a69d0cb commit d36f910
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions 33/issoverhead-start/main.py
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")

0 comments on commit d36f910

Please sign in to comment.