-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_si_image_urls.py
executable file
·58 lines (33 loc) · 1.42 KB
/
add_si_image_urls.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
#!/usr/bin/env python
import csv
import sys
from etl.etl_si import get_image_urls
fieldnames = [ 'Resource Identifier', 'Title', 'Author/Artist', 'Description', 'Date', 'ResourceType', 'Digital Format', 'Dimensions', 'URL', 'Source', 'Language', 'Subjects (Historic Era)', 'Subjects (Topic/Keywords)', 'Subjects (Geographic)', 'Notes', 'Copyright Status', 'Collection Information', 'Credit Line', 'Images' ]
if __name__ == "__main__":
input_file = sys.argv[1]
first_row = int(sys.argv[2])
row_len = len(fieldnames)
row_num = 0
batch_size = 250
with open(input_file, 'r') as csvfile:
datareader = csv.reader(csvfile)
datawriter = csv.DictWriter(sys.stdout, fieldnames=fieldnames)
datawriter.writeheader()
first_row = True
for row in datareader:
if first_row:
first_row = False
continue
id_ = row[0]
if not id_:
pass
if row_num >= first_row and row_num < (first_row + batch_size):
urls = row[row_len - 1]
if not urls:
urls = get_image_urls(id_=id_)
if urls:
urls = '|'.join(urls)
row.append(urls)
row_data = { name : row[idx] for idx, name in enumerate(fieldnames) }
datawriter.writerow(row_data)
row_num += 1