-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotation_download.py
More file actions
37 lines (25 loc) · 1.08 KB
/
annotation_download.py
File metadata and controls
37 lines (25 loc) · 1.08 KB
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
'''
The following file:
- opens a csv file
- loops over a specific column
- uses the values to download remote files and place them in a folder
python3 annotation_download.py -source_file "data/Groundwater map urls.csv" -column_name Annotation -output_folder "annotations"
#note be sure to add an 'local_annotation' column to the spreadsheet and use the following formula for the value =CONCATENATE("annotations/",RIGHT(J2, 16),".json")
'''
import argparse
import csv
import urllib.request
parser = argparse.ArgumentParser()
parser.add_argument("-source_file", help="")
parser.add_argument("-column_name", help="")
parser.add_argument("-output_folder", help="")
args = parser.parse_args()
# create file with heading - Alias,CDM_page_id,CDM_field,Value
#Input
input_file=open( args.source_file, 'r' )
csv_reader = csv.DictReader(input_file)
#output
for row in csv_reader:
# get values from row and download the file
urllib.request.urlretrieve(row[args.column_name], args.output_folder+"/"+row[args.column_name][row[args.column_name].rfind('/')+1:]+".json")
input_file.close()