Skip to content

Instantly share code, notes, and snippets.

@celoyd
Last active August 12, 2024 17:59
Show Gist options
  • Save celoyd/118aff647e9ec041748a14dffe76c2b1 to your computer and use it in GitHub Desktop.
Save celoyd/118aff647e9ec041748a14dffe76c2b1 to your computer and use it in GitHub Desktop.
Download Nikon raw images from https://eol.jsc.nasa.gov/
# python neffer.py 55 111879
# mission ^^ ^^^^^^ frame
# will write to iss055e111878.nef.
# This code is public domain; please improve & adapt it.
import requests
from sys import argv, exit
from random import uniform
from time import sleep
mission = f"{int(argv[1]):03}"
frame = f"{int(argv[2]):06}" # what happens at 7 digits?
ask_url = f"https://eol.jsc.nasa.gov/SearchPhotos/RequestOriginalImage.pl?mission=ISS{mission}&roll=E&frame={frame}&file=iss{mission}e{frame}.NEF"
print(f"Knocking on: {ask_url}")
dst_path = f"iss{mission}e{frame}.nef"
req = requests.get(ask_url)
rsc = req.status_code
if rsc != 200:
exit(f"Gave up on {mission} {frame}: HTTP {rsc}.")
waited = 0
def fetch_nef(mission, frame, waited):
nef_url = f"https://eol.jsc.nasa.gov/OriginalImagery/iss{mission}e{frame}.NEF"
print(f"Trying to download {nef_url}")
nef_req = requests.get(nef_url)
if nef_req.status_code != 200:
return False
with open(dst_path, "wb") as dst:
dst.write(nef_req.content)
print(f"Wrote to {dst_path} after {waited} s.")
return True
another = ''
for try_ in range(5):
# wait 1 minute, then 2 (total of 3), then 3 (total of 6) ...
delay = 60*(try_+1) # uniform(30, (10 * 60))
print(f"Waiting{another} {delay} s.")
another = ' another'
sleep(delay)
waited += delay
fetched = fetch_nef(mission, frame, waited)
if fetched:
exit()
print(f"Failed to fetch {mission}e{frame} over {try_+1} tries in {waited} s.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment