Example #1
0
def build_areas(areas):
    for sa in areas:
        if not sa['enable_matching']:
            continue

        osmfilename = settings.DATAFILE_TEMPLATE.format(**sa)
        basepath, ext = os.path.splitext(osmfilename)
        osrmfilename = basepath + '.osrm'

        if util.file_age(osrmfilename) > util.file_age(osmfilename):
            print u"extracting pk={pk} {name}".format(**sa).encode('utf-8')
            extract_call = [
                settings.OSRM_EXTRACT_PATH,
                os.path.abspath(osmfilename)]
            retval = subprocess.call(extract_call, cwd=settings.OSRM_CWD_PATH)

            if retval != 0:
                print u"extract failed; skipping pk={pk} {name}".format(**sa).encode('utf-8')
                continue
        else:
            print u"Skipping extract for {name}".format(**sa).encode('utf-8')

        if util.file_age(osrmfilename + '.hsgr') > util.file_age(osrmfilename):
            print u"preparing pk={pk} {name}".format(**sa).encode('utf-8')
            prepare_call = [
                settings.OSRM_PREPARE_PATH,
                os.path.abspath(osrmfilename)]
            retval = subprocess.call(prepare_call, cwd=settings.OSRM_CWD_PATH)
            print "prepared: {}".format(retval)

            if retval != 0:
                print u"prepare (contract) failed; skipping pk={pk} {name}".format(**sa).encode('utf-8')
                continue
        else:
            print u"Skipping prepare for pk={pk} {name}".format(**sa).encode('utf-8')
Example #2
0
def download_areas(areas):
    for sa in areas:
        outfile = settings.DATAFILE_TEMPLATE.format(**sa)
        if sa['enable_matching'] and util.file_age(outfile) > settings.MAX_DOWNLOAD_AGE:
            print u"Downloading pk={pk} '{name}'".format(**sa).encode('utf-8')
            util.overpass_api_download(sa['boundary'], outfile)
            time.sleep(2)
        else:
            print u"Skipping pk={pk} '{name}'".format(**sa).encode('utf-8')