geolocip deleted ; geolocip2->geolocip ; geolocip corrected

This commit is contained in:
Julien Veyssier 2010-11-27 14:17:09 +01:00
commit a25cf6b6f3
5 changed files with 31 additions and 139 deletions

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 # 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 # it under the terms of the GNU General Public License as published by
@ -18,10 +18,8 @@
from __future__ import with_statement from __future__ import with_statement
from weboob.capabilities.geolocip import ICapGeolocIp, IpLocation from weboob.capabilities.geolocip import ICapGeolocIp, IpLocation
from weboob.capabilities.base import NotAvailable
from weboob.tools.backend import BaseBackend from weboob.tools.backend import BaseBackend
from weboob.tools.browser import BaseBrowser from weboob.tools.browser import BaseBrowser
from weboob.tools.value import ValuesDict, Value
__all__ = ['GeolocIpBackend'] __all__ = ['GeolocIpBackend']
@ -29,58 +27,45 @@ __all__ = ['GeolocIpBackend']
class GeolocIpBackend(BaseBackend, ICapGeolocIp): class GeolocIpBackend(BaseBackend, ICapGeolocIp):
NAME = 'geolocip' NAME = 'geolocip'
MAINTAINER = 'Romain Bignon' MAINTAINER = 'Julien Veyssier'
EMAIL = 'romain@weboob.org' EMAIL = 'julien.veyssier@aiur.fr'
VERSION = '0.4' VERSION = '0.4'
LICENSE = 'GPLv3' LICENSE = 'GPLv3'
DESCRIPTION = u"IP Adresses geolocalisation with the API of the site www.geolocalise-ip.com " DESCRIPTION = u"IP Adresses geolocalisation with the site www.geolocip.com"
CONFIG = ValuesDict(Value('email', label='Username'),
Value('password',label='Password', masked=True))
BROWSER = BaseBrowser BROWSER = BaseBrowser
def create_default_browser(self): def create_default_browser(self):
return self.create_browser(self.config['email'], self.config['password']) return self.create_browser()
def get_location(self, ipaddr): def get_location(self, ipaddr):
with self.browser: 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('&'): content = self.browser.readurl('http://www.geolocip.com/?s[ip]=%s&commit=locate+IP!' % str(ipaddr))
if not '=' in line:
continue tab = {}
key, value = line.split('=', 1) last_line = ''
line = ''
for line in content.split('\n'):
if len(line.split('<dd>')) > 1:
key = last_line.split('<dt>')[1].split('</dt>')[0][0:-2]
value = line.split('<dd>')[1].split('</dd>')[0]
tab[key] = value tab[key] = value
last_line = line
if 'erreur' in tab and tab['erreur'][0] == '1':
raise Exception(tab['erreur'][1:].replace('<p>', '').replace('</p>', '').replace('<br />', '\n')\
.strip().decode('iso-8859-1'))
iploc = IpLocation(ipaddr) iploc = IpLocation(ipaddr)
iploc.city = tab['City']
if tab['ville'] != NotAvailable: iploc.region = tab['Region']
iploc.city = tab['ville'].decode('iso-8859-15') iploc.zipcode = tab['Postal code']
iploc.region = tab['region'] iploc.country = tab['Country name']
iploc.zipcode = tab['cp'] if tab['Latitude'] != '':
iploc.country = tab['pays'] iploc.lt = float(tab['Latitude'])
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']
else: 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 return iploc

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 # 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 # it under the terms of the GNU General Public License as published by

View file

@ -1,3 +0,0 @@
from .backend import GeolocIp2Backend
__all__ = ['GeolocIp2Backend']

View file

@ -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('<dd>')) > 1:
key = last_line.split('<dt>')[1].split('</dt>')[0][0:-2]
value = line.split('<dd>')[1].split('</dd>')[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

View file

@ -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')