-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeocode_ca.sh
executable file
·66 lines (61 loc) · 1.66 KB
/
geocode_ca.sh
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
#!/bin/bash
COUNT=0
FOLDER="json"
FIELDS="2-"
IDFIELDS="1"
BBOX_MTL="45.402161,-73.999939|45.704788,-73.476097"
D=`date +%s`
if [ $# -lt 1 ]
then
echo "Missing file"
exit
fi
if [ $# -gt 1 ]
then
FOLDER=$2
fi
if [ $# -gt 2 ]
then
FIELDS=$3
fi
if [ $# -gt 3 ]
then
IDFIELDS=$4
fi
while read line
do
#echo ${line}
id=`echo "${line}" | cut -d, -f${IDFIELDS}`
#| sed 's/ \+//g'`
address=`echo "${line}" | cut -d, -f${FIELDS}`
address_url=`echo ${address} | sed 's/ /+/g' `
echo $address
FO="${FOLDER}/${id}.json"
if [ -s "${FO}" ]
then
echo "Already OK: ${FO}"
continue
fi
#URL="http://maps.googleapis.com/maps/api/geocode/json?sensor=false&language=fr®ion=ca&address=${address_url}&bounds=${BBOX_MTL}&components=country:CA"
URL="http://maps.googleapis.com/maps/api/geocode/json?sensor=false&language=fr®ion=ca&address=${address_url}&components=country:CA"
#URL="http://maps.googleapis.com/maps/api/geocode/json?sensor=false&language=fr®ion=ca&address=${address_url}&components=administrative_area:Montreal|administrative_area:QC|country:CA"
echo "${URL}"
curl -s "${URL}" -o "${FO}"
echo "${FO}"
let COUNT=${COUNT}+1
if [ ${COUNT} -gt 2450 ] || [ `grep OVER_QUERY_LIMIT "${FO}" 2> /dev/null | wc -l` -eq 1 ]
then
echo "MARK SET -- ${COUNT}: `date`"
#NEXTMIDNIGHT=`date -d"tomorrow" +%Y-%m-%d `
#DNEXT=`date -d${NEXTMIDNIGHT} +%s`
DNEXT=`date -d"tomorrow" +%s`
DNOW=`date +%s`
let SLEEPTIME=${DNEXT}-${DNOW}
SLEEPTIME=86400
echo "SLEEPING ${SLEEPTIME} SECONDS -- until `date -d"+1 day"`"
sleep ${SLEEPTIME}
curl -s "${URL}" -o "${FO}"
COUNT=0
fi
sleep 0.75
done < $1