-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (64 loc) · 2.04 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
if __name__ == "__main__":
import json
try:
import core
except TypeError:
import core_legacy as core
from PIL import Image
import os
print("# NEA Viewer - Imagemapper")
print()
id = None
while id is None:
id = input("Enter ID: ")
try:
id = int(id)
print(f"Fetching info for {id}...")
print()
features = core.get_features(id)
if features["data"]["images"]["features"] is None:
print("Wrong Image ID; Not Found")
id = None
else:
break
except ValueError:
print("Wrong format.")
id = None
#with open("features.json", "w") as f:
# json.dump(features, f, indent=2)
feature = features["data"]["images"]["features"][0]
print(f">> Image name: {feature['properties']['imagepath']}")
print(f">> Image date: {feature['properties']['bildflugdatum']}")
print()
zoom = None
while zoom is None:
zoom = input(f"Enter Zoom-Level ({feature['properties']['image_minzoom']}-{feature['properties']['image_maxzoom']}): ")
try:
zoom = int(zoom)
break
except ValueError:
print("Wrong zoom-level.")
zoom = None
(image_width, image_height), tile_list = core.construct_all_meta(feature, zoom)
print()
print(f">> Final image size: {image_width}x{image_height}")
print(f">> Tilecount: {len(tile_list)}")
print()
try:
input("Press Enter to download or Ctrl+C to exit now or anytime during download.")
except KeyboardInterrupt:
print()
print("Exited.")
exit()
print()
img = core.download_all(((image_width, image_height), tile_list))
path_n = f'output_{id}_{zoom}'
path = path_n
i = 2
while os.path.exists(path + ".jpg"):
path = f"{path_n} ({i})"
i += 1
path += ".jpg"
img.convert('RGB').save(path, quality=95)
print(f"Saved to {path}")
print("\nDone")