-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk_api-upload.sh
More file actions
executable file
·69 lines (50 loc) · 1.29 KB
/
bulk_api-upload.sh
File metadata and controls
executable file
·69 lines (50 loc) · 1.29 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
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
#!/bin/bash
# written by Michael Maier (s.8472@aon.at)
#
# 30.03.2016 - intial release
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
###
### Standard help text
###
if [ ! "$1" ] || [ "$1" = "-h" ] || [ "$1" = " -help" ] || [ "$1" = "--help" ]
then
cat <<EOH
Usage: $0 file.geojson [OPTIONS]
$0 is a program to take a geojson Feature-Collection and bulk upload data to
the TransforMap API
OPTIONS:
-h -help --help this help text
EOH
fi
###
### variables
###
infile="$1"
workdir="single"
endpoint="https://data.transformap.co/place/"
resultfile="ids.csv"
###
### working part
###
mkdir -p "$workdir"
if [ ! -f "$resultfile" ]; then
echo "name, id, uri" > "$resultfile"
fi
counter=0
while true; do
result=`cat "$infile"|jq ".features[$counter]"`
if [ "$result" = "null" ]; then
echo "finished after $counter items."
exit
fi
fname=$workdir/$counter.geojson
echo "$result" > $fname
name=`echo "$result" | jq ".properties.name"`
id=`curl -s $endpoint "-d@$fname" -H 'content-type: application/json' | jq ".id"|sed 's/"//g'`
echo "name: '$name', id: $id"
echo "$name, $id, $endpoint$id" >> $resultfile
let counter=$counter+1
done