# Path: www/maposmatic/gisdb.py
# _DB = None
#         _DB = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s' port='%s'" %
#                                 (www.settings.GIS_DATABASE_NAME,
#                                  www.settings.GIS_DATABASE_USER,
#                                  www.settings.GIS_DATABASE_HOST,
#                                  www.settings.GIS_DATABASE_PASSWORD,
#                                  www.settings.GIS_DATABASE_PORT))
#         _DB = None
# def get():


from django.utils.translation import ugettext
from urllib import urlencode
from xml.etree.ElementTree import parse as XMLTree
from www.maposmatic import gisdb
import logging
import psycopg2
import urllib2
import ocitysmap
import www.settings
    import pprint, sys
# Nominatim parsing + json export
# Note: we query nominatim in XML format because otherwise we cannot
# access the osm_id tag. Then we format it as json back to the
# javascript routines


"""
Simple API to query http://nominatim.openstreetmap.org

Most of the credits should go to gthe Nominatim team.
"""



NOMINATIM_BASE_URL = 'http://nominatim.openstreetmap.org'
NOMINATIM_MAX_RESULTS_PER_RESPONSE = 10

NOMINATIM_USER_AGENT = 'MapOSMatic'
if www.settings.ADMINS:
    NOMINATIM_USER_AGENT = '%s (%s)' % (NOMINATIM_USER_AGENT,
                                        www.settings.ADMINS[0][1])

l = logging.getLogger('maposmatic')

def reverse_geo(lat, lon):
    """Query the nominatim service for the given lat/long coordinates and
    returns the reverse geocoded informations."""

    request = urllib2.Request('%s/reverse?%s' %
        (NOMINATIM_BASE_URL, urlencode({'lat': lat, 'lon': lon})))

# Path: www/maposmatic/gisdb.py
# _DB = None
#         _DB = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s' port='%s'" %
#                                 (www.settings.GIS_DATABASE_NAME,
#                                  www.settings.GIS_DATABASE_USER,
#                                  www.settings.GIS_DATABASE_HOST,
#                                  www.settings.GIS_DATABASE_PASSWORD,
#                                  www.settings.GIS_DATABASE_PORT))
#         _DB = None
# def get():


# Path: www/maposmatic/nominatim.py
from django.utils.translation import ugettext
from urllib import urlencode
from xml.etree.ElementTree import parse as XMLTree
from www.maposmatic import gisdb
import logging
import psycopg2
import urllib2
import ocitysmap
import www.settings
    import pprint, sys

# Nominatim parsing + json export
# Note: we query nominatim in XML format because otherwise we cannot
# access the osm_id tag. Then we format it as json back to the
# javascript routines


"""
Simple API to query http://nominatim.openstreetmap.org

Most of the credits should go to gthe Nominatim team.
"""



NOMINATIM_BASE_URL = 'http://nominatim.openstreetmap.org'
NOMINATIM_MAX_RESULTS_PER_RESPONSE = 10

NOMINATIM_USER_AGENT = 'MapOSMatic'
if www.settings.ADMINS:
    NOMINATIM_USER_AGENT = '%s (%s)' % (NOMINATIM_USER_AGENT,
                                        www.settings.ADMINS[0][1])

l = logging.getLogger('maposmatic')

def reverse_geo(lat, lon):
    """Query the nominatim service for the given lat/long coordinates and
    returns the reverse geocoded informations."""

    request = urllib2.Request('%s/reverse?%s' %
        (NOMINATIM_BASE_URL, urlencode({'lat': lat, 'lon': lon})))

    request.add_header('User-Agent', NOMINATIM_USER_AGENT)