man01025

teacher_code

Jul 20th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | Source Code | 0 0
  1. import requests
  2. from datetime import datetime
  3. import smtplib
  4. import time
  5.  
  6. MY_EMAIL = "___YOUR_EMAIL_HERE____"
  7. MY_PASSWORD = "___YOUR_PASSWORD_HERE___"
  8. MY_LAT = 51.507351 # Your latitude
  9. MY_LONG = -0.127758 # Your longitude
  10.  
  11.  
  12. def is_iss_overhead():
  13. response = requests.get(url="http://api.open-notify.org/iss-now.json")
  14. response.raise_for_status()
  15. data = response.json()
  16.  
  17. iss_latitude = float(data["iss_position"]["latitude"])
  18. iss_longitude = float(data["iss_position"]["longitude"])
  19.  
  20. #Your position is within +5 or -5 degrees of the iss position.
  21. if MY_LAT-5 <= iss_latitude <= MY_LAT+5 and MY_LONG-5 <= iss_longitude <= MY_LONG+5:
  22. return True
  23.  
  24.  
  25. def is_night():
  26. parameters = {
  27. "lat": MY_LAT,
  28. "lng": MY_LONG,
  29. "formatted": 0,
  30. }
  31. response = requests.get("https://api.sunrise-sunset.org/json", params=parameters)
  32. response.raise_for_status()
  33. data = response.json()
  34. sunrise = int(data["results"]["sunrise"].split("T")[1].split(":")[0])
  35. sunset = int(data["results"]["sunset"].split("T")[1].split(":")[0])
  36.  
  37. time_now = datetime.now().hour
  38.  
  39. if time_now >= sunset or time_now <= sunrise:
  40. return True
  41.  
  42.  
  43. while True:
  44. time.sleep(60)
  45. if is_iss_overhead() and is_night():
  46. connection = smtplib.SMTP("__YOUR_SMTP_ADDRESS_HERE___")
  47. connection.starttls()
  48. connection.login(MY_EMAIL, MY_PASSWORD)
  49. connection.sendmail(
  50. from_addr=MY_EMAIL,
  51. to_addrs=MY_EMAIL,
  52. msg="Subject:Look Up👆\n\nThe ISS is above you in the sky."
  53. )
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment