コード例 #1
0
ファイル: status.py プロジェクト: changpingc/Nominatim
def compute_database_date(conn):
    """ Determine the date of the database from the newest object in the
        data base.
    """
    # First, find the node with the highest ID in the database
    with conn.cursor() as cur:
        osmid = cur.scalar("SELECT max(osm_id) FROM place WHERE osm_type='N'")

        if osmid is None:
            LOG.fatal("No data found in the database.")
            raise UsageError("No data found in the database.")

    LOG.info("Using node id %d for timestamp lookup", osmid)
    # Get the node from the API to find the timestamp when it was created.
    node_url = 'https://www.openstreetmap.org/api/0.6/node/{}/1'.format(osmid)
    data = get_url(node_url)

    match = re.search(
        r'timestamp="((\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}))Z"',
        data)

    if match is None:
        LOG.fatal(
            "The node data downloaded from the API does not contain valid data.\n"
            "URL used: %s", node_url)
        raise UsageError("Bad API data.")

    LOG.debug("Found timestamp %s", match[1])

    return dt.datetime.fromisoformat(match[1]).replace(tzinfo=dt.timezone.utc)
コード例 #2
0
 def _get_wiki_content(lang):
     """
         Request and return the wiki page's content
         corresponding to special phrases for a given lang.
         Requested URL Example :
             https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/EN
     """
     url = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/' + lang.upper() # pylint: disable=line-too-long
     return get_url(url)
コード例 #3
0
def add_osm_object(osm_type, osm_id, use_main_api, options):
    """ Add or update a single OSM object from the latest version of the
        API.
    """
    if use_main_api:
        base_url = f'https://www.openstreetmap.org/api/0.6/{osm_type}/{osm_id}'
        if osm_type in ('way', 'relation'):
            base_url += '/full'
    else:
        # use Overpass API
        if osm_type == 'node':
            data = f'node({osm_id});out meta;'
        elif osm_type == 'way':
            data = f'(way({osm_id});>;);out meta;'
        else:
            data = f'(rel(id:{osm_id});>;);out meta;'
        base_url = 'https://overpass-api.de/api/interpreter?' \
                   + urllib.parse.urlencode({'data': data})

    options['append'] = True
    options['import_data'] = get_url(base_url).encode('utf-8')

    run_osm2pgsql(options)