最新の変更セットを含む YAML ファイルがあります。最新のダウンロードを記録して、urlretrieve
その範囲で使用してください。
import os, urllib, yaml
os_url = "http://planet.openstreetmap.org/replication/"
base_dir = "./"
try:
with open('download.log', 'r') as f:
last_set = int(f.readlines()[-1].strip())
except:
last_set = int(raw_input("Enter latest set:"))
stream = urllib.urlopen(os_url+"changesets/state.yaml")
latest_set = yaml.load(stream)['sequence']
for seq in range(last_set+1,latest_set+1):
changeset_dir = "changesets/000/%03d/"%(seq/1000)
changeset_file = "%03d.osm.gz"%(seq%1000)
remote_file = os_url + changeset_dir + changeset_file
local_dir = base_dir + changeset_dir
local_file = local_dir + changeset_file
if not os.path.exists(local_dir):
os.makedirs(local_dir)
try:
with open(local_file) as f: pass
print "Already downloaded",seq
except:
urllib.urlretrieve(remote_file, local_file)
print "Downloaded changeset",seq
print "Up-to-date"
with open('download.log', 'a') as f:
f.write('%s\n'%latest_set)