diff options
| -rwxr-xr-x | scripts/osm/sequence_number.sh | 22 | ||||
| -rw-r--r-- | utils/osm | 15 |
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 | |||
| 6 | case $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 ] | ||
| 22 | esac | ||
| @@ -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 |
| 48 | SERVER=https://api.openstreetmap.org | 48 | OSM_SERVER=https://api.openstreetmap.org |
| 49 | OSM_API=$SERVER/api/0.6 | 49 | OSM_API=$OSM_SERVER/api/0.6 |
| 50 | OSM_USER_PASSWD=$(cat $SETTING_DIR/tokens/osm) | 50 | OSM_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 |
| 235 | osm.pbf.update() { | 235 | osm.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 \ |