-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrover.py
41 lines (33 loc) · 1.24 KB
/
rover.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
# Constants for Russian LEO navigation satellites
import os
import requests
import urllib
def fetch_rover_photos(rover_name, sol, camera, api_key):
url = f"https://api.nasa.gov/mars-photos/api/v1/rovers/{rover_name}/photos"
params = {
'sol': sol,
'camera': camera,
'api_key': api_key
}
try:
response = requests.get(url, params=params)
response.raise_for_status() # Raise an exception for bad responses (4xx or 5xx)
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error fetching rover photos: {e}")
return None
def save_rover_images(photo_data, save_folder):
try:
photos = photo_data.get('photos', [])
if not photos:
print("No photos found.")
return
for photo in photos:
img_src = photo['img_src']
img_name = os.path.basename(img_src)
img_path = os.path.join(save_folder, img_name)
# Download the image
urllib.request.urlretrieve(img_src, img_path)
print(f"Image saved: {img_name}")
except KeyError as e:
print(f"Error accessing photo data: {e}")