summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xscripts/osm/sequence_number.sh22
-rw-r--r--utils/osm15
2 files changed, 30 insertions, 7 deletions
diff --git a/scripts/osm/sequence_number.sh b/scripts/osm/sequence_number.sh
new file mode 100755
index 0000000..eb365d0
--- /dev/null
+++ b/scripts/osm/sequence_number.sh
@@ -0,0 +1,22 @@
1#!/bin/bash
2
3# $1 as --hour or --minute, $2 as timestamp
4# return the latest sequence number
5
6case $1 in
7 # hour difference with Tue Jun 4 03:00:00 UTC 2019
8 # sequence number=58940
9 --hour)
10 echo $[($2 - 1559617200)/3600 + 58940]
11 ;;
12
13 # minute difference with latest planet state file
14 --minute)
15 benchmark=benchmark
16 curl https://planet.openstreetmap.org/replication/minute/state > $benchmark
17 timeString=$(tail -1 $benchmark | tr -d 'timestamp=\\')
18 timestamp=$(date -d "$timeString" +%s)
19 seq=$(sed -n 2p $benchmark | tr -d "sequenceNumber=")
20 rm $benchmark
21 echo $[$seq - ($timestamp - $2)/60 - 1 ]
22esac
diff --git a/utils/osm b/utils/osm
index 7ef8cdf..cdc4eb7 100644
--- a/utils/osm
+++ b/utils/osm
@@ -44,9 +44,9 @@ osm.goto() {
44 xdg-open https://www.openstreetmap.org/$1/$2 44 xdg-open https://www.openstreetmap.org/$1/$2
45} 45}
46 46
47#SERVER=https://master.apis.dev.openstreetmap.org 47#OSM_SERVER=https://master.apis.dev.openstreetmap.org
48SERVER=https://api.openstreetmap.org 48OSM_SERVER=https://api.openstreetmap.org
49OSM_API=$SERVER/api/0.6 49OSM_API=$OSM_SERVER/api/0.6
50OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm) 50OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm)
51 51
52# get .osm format data 52# get .osm format data
@@ -200,7 +200,7 @@ osm.api.changeset.create() {
200 tail -1 | read changeset_id 200 tail -1 | read changeset_id
201 201
202 echo " copied into clipboard" 202 echo " copied into clipboard"
203 echo "changeset created, check $SERVER/changeset/$changeset_id" 203 echo "changeset created, check $OSM_SERVER/changeset/$changeset_id"
204 echo $changeset_id | xsel -ib 204 echo $changeset_id | xsel -ib
205} 205}
206# add a new element into changeset 206# add a new element into changeset
@@ -234,7 +234,7 @@ osm.api.changeset.close() {
234# update an .osm.pbf file 234# update an .osm.pbf file
235osm.pbf.update() { 235osm.pbf.update() {
236 PBF_FILE=$1 236 PBF_FILE=$1
237 SERVER=http://download.geofabrik.de/asia/taiwan-updates 237 GEOFABRICK_SERVER=http://download.geofabrik.de/asia/taiwan-updates
238 238
239 # get next sequence number and store it into NEW_SEQ 239 # get next sequence number and store it into NEW_SEQ
240 osmium fileinfo $PBF_FILE | \ 240 osmium fileinfo $PBF_FILE | \
@@ -247,11 +247,12 @@ osm.pbf.update() {
247 # get it and do file update 247 # get it and do file update
248 while 248 while
249 SEQ_PATH=$(echo $NEW_SEQ | sed -r 's/(.{1})(.{3})/00\1\/\2/') 249 SEQ_PATH=$(echo $NEW_SEQ | sed -r 's/(.{1})(.{3})/00\1\/\2/')
250 STATE_URL=$SERVER/000/$SEQ_PATH.state.txt 250 STATE_URL=$GEOFABRICK_SERVER/000/$SEQ_PATH.state.txt
251 echo $STATE_URL
251 [ $(curl.code $STATE_URL) != "404" ] 252 [ $(curl.code $STATE_URL) != "404" ]
252 do 253 do
253 mkdir -p changes 254 mkdir -p changes
254 CHANGE_URL=$SERVER/000/$SEQ_PATH.osc.gz 255 CHANGE_URL=$GEOFABRICK_SERVER/000/$SEQ_PATH.osc.gz
255 echo $CHANGE_URL 256 echo $CHANGE_URL
256 curl -o changes/$NEW_SEQ.osc.gz $CHANGE_URL && \ 257 curl -o changes/$NEW_SEQ.osc.gz $CHANGE_URL && \
257 osmium apply-changes $PBF_FILE changes/$NEW_SEQ.osc.gz \ 258 osmium apply-changes $PBF_FILE changes/$NEW_SEQ.osc.gz \