-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanorama_download.py
37 lines (30 loc) · 1.13 KB
/
panorama_download.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
"""
This script downloads a panorama by ID, with optional
arguments of zoom and file save path.
"""
import argparse
from streetview_download.panorama import get_pil_panorama, PanoramaSettings
parser = argparse.ArgumentParser(description="Downloads a panorama by ID.")
parser.add_argument("panorama_id", help="Panorama ID (22 characters).")
parser.add_argument("-z", "--zoom", type=int, help="Level of zoom [0, 5]")
parser.add_argument("-o", "--output", help="Output file path.")
def main() -> None:
args = parser.parse_args()
# Gather arguments.
panorama_id = args.panorama_id
zoom = args.zoom if args.zoom is not None else 0
output_file = args.output
# Downloads panorama.
pil_panorama = get_pil_panorama(panorama_id, PanoramaSettings(zoom))
if output_file is not None:
# Save to given output file.
pil_panorama.save(output_file, format="jpeg")
print(f"Successfully saved panorama.")
else:
# Display the image instead, if no file is provided.
pil_panorama.show()
if __name__ == "__main__":
try:
main()
except Exception as e:
print(f"Error: {e}")