Pep8 cleaning

This commit is contained in:
Florent 2014-04-08 10:55:42 +02:00
commit 3e9c168158
4 changed files with 58 additions and 29 deletions

View file

@ -33,8 +33,7 @@ class LaCentraleBrowser(BaseBrowser):
PROTOCOL = 'http' PROTOCOL = 'http'
DOMAIN = 'www.lacentrale.fr' DOMAIN = 'www.lacentrale.fr'
ENCODING = 'windows-1252' ENCODING = 'windows-1252'
PAGES = { PAGES = {'http://www.lacentrale.fr/': MainPage,
'http://www.lacentrale.fr/': MainPage,
'http://www.lacentrale.fr/listing_auto.php?.*': ListingAutoPage, 'http://www.lacentrale.fr/listing_auto.php?.*': ListingAutoPage,
'http://www.lacentrale.fr/auto-occasion-annonce-.*': AnnoncePage, 'http://www.lacentrale.fr/auto-occasion-annonce-.*': AnnoncePage,
} }

View file

@ -27,6 +27,7 @@ from weboob.capabilities.pricecomparison import Product, Price, Shop
__all__ = ['MainPage', 'ListingAutoPage', 'AnnoncePage'] __all__ = ['MainPage', 'ListingAutoPage', 'AnnoncePage']
# I manage main page, ie do nothing yet # I manage main page, ie do nothing yet
class MainPage(BasePage): class MainPage(BasePage):
def iter_products(self, criteria): def iter_products(self, criteria):
@ -37,14 +38,17 @@ class MainPage(BasePage):
product._criteria = criteria product._criteria = criteria
yield product yield product
def get_decimal(s): def get_decimal(s):
return re.findall(r'\d+', s.replace(' ', ''))[0] return re.findall(r'\d+', s.replace(' ', ''))[0]
def new_shop(id): def new_shop(id):
shop = Shop(id) shop = Shop(id)
shop.set_empty_fields(NotLoaded) shop.set_empty_fields(NotLoaded)
return shop return shop
def new_price(id, product, cost, title): def new_price(id, product, cost, title):
price = Price(id) price = Price(id)
price.product = product price.product = product
@ -55,6 +59,7 @@ def new_price(id, product, cost, title):
price.shop = new_shop(id) price.shop = new_shop(id)
return price return price
# I manage listing page and extract information # I manage listing page and extract information
class ListingAutoPage(BasePage): class ListingAutoPage(BasePage):
@ -67,10 +72,12 @@ class ListingAutoPage(BasePage):
def _extract_id(self, tr): def _extract_id(self, tr):
tdas = tr.cssselect('td.lcbrand a') tdas = tr.cssselect('td.lcbrand a')
if tdas is None or len(tdas)==0: return None if tdas is None or len(tdas) == 0:
return None
tda = tdas[0] tda = tdas[0]
m = re.search('annonce-(\d+)\.html', tda.get('href')) m = re.search('annonce-(\d+)\.html', tda.get('href'))
if not m: return None if not m:
return None
return m.group(1) return m.group(1)
def iter_prices(self, product, numpage): def iter_prices(self, product, numpage):
@ -100,6 +107,7 @@ class ListingAutoPage(BasePage):
return int(m.group(1)) return int(m.group(1))
return None return None
# I manage one car page (annonce) )and extract information # I manage one car page (annonce) )and extract information
class AnnoncePage(BasePage): class AnnoncePage(BasePage):
@ -115,7 +123,8 @@ class AnnoncePage(BasePage):
for td in e.cssselect('td.InfoLib'): for td in e.cssselect('td.InfoLib'):
if name in td.text_content(): if name in td.text_content():
ntd = td.getnext() ntd = td.getnext()
if ntd is None: continue if ntd is None:
continue
return ntd.text_content().strip() return ntd.text_content().strip()
return None return None
@ -124,7 +133,8 @@ class AnnoncePage(BasePage):
for span in e.cssselect('span.VendeurLib'): for span in e.cssselect('span.VendeurLib'):
if name in span.text_content(): if name in span.text_content():
li = span.getparent() li = span.getparent()
if li is None: continue if li is None:
continue
# get all text # get all text
s = li.text_content() s = li.text_content()
# get text without header # get text without header

View file

@ -1,8 +1,28 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright(C) 2014 Vicnet
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.test import BackendTest from weboob.tools.test import BackendTest
__all__ = ['LaCentraleTest'] __all__ = ['LaCentraleTest']
class LaCentraleTest(BackendTest): class LaCentraleTest(BackendTest):
BACKEND = 'lacentrale' BACKEND = 'lacentrale'