diff --git a/weboob/backends/geolocip/backend.py b/weboob/backends/geolocip/backend.py index 70324523..15cd8dc8 100644 --- a/weboob/backends/geolocip/backend.py +++ b/weboob/backends/geolocip/backend.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010 Romain Bignon +# Copyright(C) 2010 Julien Veyssier # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,10 +18,8 @@ from __future__ import with_statement from weboob.capabilities.geolocip import ICapGeolocIp, IpLocation -from weboob.capabilities.base import NotAvailable from weboob.tools.backend import BaseBackend from weboob.tools.browser import BaseBrowser -from weboob.tools.value import ValuesDict, Value __all__ = ['GeolocIpBackend'] @@ -29,58 +27,45 @@ __all__ = ['GeolocIpBackend'] class GeolocIpBackend(BaseBackend, ICapGeolocIp): NAME = 'geolocip' - MAINTAINER = 'Romain Bignon' - EMAIL = 'romain@weboob.org' + MAINTAINER = 'Julien Veyssier' + EMAIL = 'julien.veyssier@aiur.fr' VERSION = '0.4' LICENSE = 'GPLv3' - DESCRIPTION = u"IP Adresses geolocalisation with the API of the site www.geolocalise-ip.com " - CONFIG = ValuesDict(Value('email', label='Username'), - Value('password',label='Password', masked=True)) + DESCRIPTION = u"IP Adresses geolocalisation with the site www.geolocip.com" BROWSER = BaseBrowser def create_default_browser(self): - return self.create_browser(self.config['email'], self.config['password']) + return self.create_browser() def get_location(self, ipaddr): with self.browser: - args = {'email': self.config['email'], - 'pass': self.config['password'], - 'ip': str(ipaddr) - } - content = self.browser.readurl(self.browser.buildurl('http://www.geolocalise-ip.com/api.php', **args)) - tab = {'ville' : NotAvailable ,\ - 'region' : NotAvailable ,\ - 'cp' : NotAvailable ,\ - 'pays' : NotAvailable ,\ - 'lt' : NotAvailable ,\ - 'lg' : NotAvailable ,\ - 'host' : NotAvailable ,\ - 'tld' : NotAvailable ,\ - 'fai' : NotAvailable} - for line in content.split('&'): - if not '=' in line: - continue - key, value = line.split('=', 1) - tab[key] = value - - if 'erreur' in tab and tab['erreur'][0] == '1': - raise Exception(tab['erreur'][1:].replace('

', '').replace('

', '').replace('
', '\n')\ - .strip().decode('iso-8859-1')) + content = self.browser.readurl('http://www.geolocip.com/?s[ip]=%s&commit=locate+IP!' % str(ipaddr)) + tab = {} + last_line = '' + line = '' + for line in content.split('\n'): + if len(line.split('
')) > 1: + key = last_line.split('
')[1].split('
')[0][0:-2] + value = line.split('
')[1].split('
')[0] + tab[key] = value + last_line = line iploc = IpLocation(ipaddr) - - if tab['ville'] != NotAvailable: - iploc.city = tab['ville'].decode('iso-8859-15') - iploc.region = tab['region'] - iploc.zipcode = tab['cp'] - iploc.country = tab['pays'] - iploc.lt = float(tab['lt']) - iploc.lg = float(tab['lg']) - iploc.host = tab['host'] - iploc.tld = tab['tld'] - if 'fai' in tab: - iploc.isp = tab['fai'] + iploc.city = tab['City'] + iploc.region = tab['Region'] + iploc.zipcode = tab['Postal code'] + iploc.country = tab['Country name'] + if tab['Latitude'] != '': + iploc.lt = float(tab['Latitude']) else: - iploc.isp = NotAvailable + iploc.lt = 0.0 + if tab['Longitude'] != '': + iploc.lg = float(tab['Longitude']) + else: + iploc.lg = 0.0 + #iploc.host = 'NA' + #iploc.tld = 'NA' + #iploc.isp = 'NA' + return iploc diff --git a/weboob/backends/geolocip/test.py b/weboob/backends/geolocip/test.py index ff94003e..0b881b48 100644 --- a/weboob/backends/geolocip/test.py +++ b/weboob/backends/geolocip/test.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright(C) 2010 Romain Bignon +# Copyright(C) 2010 Julien Veyssier # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/weboob/backends/geolocip2/__init__.py b/weboob/backends/geolocip2/__init__.py deleted file mode 100644 index 833bcb91..00000000 --- a/weboob/backends/geolocip2/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .backend import GeolocIp2Backend - -__all__ = ['GeolocIp2Backend'] diff --git a/weboob/backends/geolocip2/backend.py b/weboob/backends/geolocip2/backend.py deleted file mode 100644 index c547b547..00000000 --- a/weboob/backends/geolocip2/backend.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2010 Julien Veyssier -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 3 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -from __future__ import with_statement - -from weboob.capabilities.geolocip import ICapGeolocIp, IpLocation -from weboob.tools.backend import BaseBackend -from weboob.tools.browser import BaseBrowser - - -__all__ = ['GeolocIp2Backend'] - - -class GeolocIp2Backend(BaseBackend, ICapGeolocIp): - NAME = 'geolocip2' - MAINTAINER = 'Julien Veyssier' - EMAIL = 'julien.veyssier@aiur.fr' - VERSION = '0.4' - LICENSE = 'GPLv3' - DESCRIPTION = u"IP Adresses geolocalisation with the site www.geolocip.com" - BROWSER = BaseBrowser - - def create_default_browser(self): - return self.create_browser() - - def get_location(self, ipaddr): - with self.browser: - - content = self.browser.readurl('http://www.geolocip.com/?s[ip]=%s&commit=locate+IP!' % str(ipaddr)) - - tab = {} - last_line = '' - line = '' - for line in content.split('\n'): - if len(line.split('
')) > 1: - key = last_line.split('
')[1].split('
')[0][0:-2] - value = line.split('
')[1].split('
')[0] - tab[key] = value - last_line = line - iploc = IpLocation(ipaddr) - iploc.city = tab['City'] - iploc.region = tab['Region'] - iploc.zipcode = tab['Postal code'] - iploc.country = tab['Country name'] - iploc.lt = float(tab['Latitude']) - iploc.lg = float(tab['Longitude']) - #iploc.host = 'NA' - #iploc.tld = 'NA' - #iploc.isp = 'NA' - - return iploc diff --git a/weboob/backends/geolocip2/test.py b/weboob/backends/geolocip2/test.py deleted file mode 100644 index 406f4859..00000000 --- a/weboob/backends/geolocip2/test.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2010 Julien Veyssier -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, version 3 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -from weboob.tools.test import BackendTest - -class GeolocIP2Test(BackendTest): - BACKEND = 'geolocip2' - - def test_geolocip2(self): - self.backend.get_location('88.198.11.130')