Commit 76a37820 authored by Juliana - Le Filament's avatar Juliana - Le Filament

Modif appel API

parent f63a7bf5
# -*- coding: utf-8 -*-
# © 2017 Le Filament (<http://www.le-filament.com>)
# © 2020 Le Filament (<http://www.le-filament.com>)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from . import models
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2018 Le Filament (<https://www.le-filament.com>)
<!-- Copyright 2020 Le Filament (<https://www.le-filament.com>)
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). -->
<odoo>
<data noupdate="1">
......
......@@ -2,35 +2,32 @@
# © 2020 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
import json
import urllib.request
import time
import requests
import logging
from odoo import api, fields, models, tools, _
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)
def geo_find(addr):
if not addr:
return None
url = 'https://nominatim.openstreetmap.org/search.php/'
url += urllib.request.quote(addr.encode('utf8'))
url += '?format=json'
url = 'https://nominatim.openstreetmap.org/search'
try:
result = json.load(urllib.request.urlopen(url))
headers = {'User-Agent': 'Odoo (http://www.odoo.com/contactus)'}
response = requests.get(url, headers=headers, params={'format': 'json', 'q': addr})
_logger.info('openstreetmap nominatim service called')
if response.status_code != 200:
_logger.error('Request to openstreetmap failed.\nCode: %s\nContent: %s' % (response.status_code, response.content))
result = response.json()
except Exception as e:
raise UserError(_('Cannot contact geolocation servers. Please make \
sure that your Internet connection is up and \
running (%s).') % e)
raise UserError(_('Cannot contact geolocation servers. Please make sure that your Internet connection is up and running (%s).') % e)
try:
if result:
geo = result[0]
return [float(geo['lat']), float(geo['lon'])]
return None
except (KeyError, ValueError):
return None
geo = result[0]
return float(geo['lat']), float(geo['lon'])
def geo_query_address(street=None, zip=None, city=None,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment