-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_frames.py
More file actions
31 lines (25 loc) · 869 Bytes
/
export_frames.py
File metadata and controls
31 lines (25 loc) · 869 Bytes
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
#!/usr/bin/env python3
import csv
import os
import sys
from turnovertools import sourcedb
def main(inputfile, table, db, outputdir):
if isinstance(db, str):
db = sourcedb.SourceTable(
sourcedb.connect(database=db), table=table,
keyfield='PrimaryKey')
with open(inputfile, newline='') as csvfile:
reader = csv.reader(csvfile)
records = list(reader)
for i, key in enumerate(row[0] for row in records):
record = db[key]
if record is None:
print(f'No record found for {key}')
continue
reel = db[key]['reel']
image = db.get_blob(key, 'image', 'JPEG')
outname = f'{i:03}_{reel}.jpg'
with open(os.path.join(outputdir, outname), 'wb') as outfile:
outfile.write(image)
if __name__ == '__main__':
main(*sys.argv[1:])