Beispiel #1
0
 def put(self):
     latitude = self.request.params.get('lat')
     longitude = self.request.params.get('lon')
     nominatim = ConfigurationWrapper.instance('api').get('nominatim')
     request = Request.blank(
         nominatim + '/reverse?format=json&lat=%s&lon=%s&addressdetails=1' %
         (latitude, longitude))
     request.user_agent = 'CoolMap/1.0.0'
     response = request.get_response()
     if response.status_code != HTTPStatus.OK.value:
         return HTTPBadResponse(
             FailResultSimple('FailGeodecoding', 'Fail to geodecoding'))
     data = response.json_body
     osm_type = data.get('osm_type')[0].upper()
     osm_id = data.get('osm_id')
     title = data.get('display_name')
     address = json.dumps(data.get('address'))
     place = self._add_or_update(osm_id, osm_type, address, title)
     return HTTPOk(place)
Beispiel #2
0
import uuid

from core.configuration import ConfigurationWrapper
from core.entities import *
from sqlalchemy import create_engine, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.session import Session

Base = declarative_base()
Engine = create_engine(ConfigurationWrapper.instance('api').get('database'))


class SessionWrapper(Session):
    def __init__(self, **kwargs):
        super(SessionWrapper, self).__init__(**kwargs)

    def __enter__(self) -> 'SessionWrapper':
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if exc_type is None:
            self.commit()
        else:
            self.rollback()
        self.close()


def create_transaction() -> SessionWrapper:
    return SessionWrapper(bind=Engine)