-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
load_photo_metadata.py
38 lines (32 loc) · 984 Bytes
/
load_photo_metadata.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
import json
import pathlib
import sqlite_utils
def load_image_metadata():
root = pathlib.Path("photos-metadata")
to_insert = []
for path in root.glob("*.json"):
with open(path) as fp:
data = json.load(fp)
data["filename"] = path.name.replace(".json", "")
to_insert.append(data)
db = sqlite_utils.Database("browse.db")
db["raw_photos"].insert_all(to_insert, pk="filename", alter=True, replace=True)
db.create_view(
"photos",
"""
select
'https://niche-museums.imgix.net/' || filename as url,
case
when Orientation in (6, 8) then PixelHeight
else PixelWidth
end as width,
case
when Orientation in (6, 8) then PixelWidth
else PixelHeight
end as height
from raw_photos
""",
replace=True,
)
if __name__ == "__main__":
load_image_metadata()