Replace Insert2 by InsertX
And remove the encoding of login/password And move BrowserBanned exception in page
This commit is contained in:
parent
5cdefd8966
commit
39ea87fa61
2 changed files with 28 additions and 23 deletions
|
|
@ -17,9 +17,8 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
from weboob.tools.browser2 import LoginBrowser, URL, need_login
|
from weboob.tools.browser2 import LoginBrowser, URL, need_login
|
||||||
from weboob.tools.browser import BrowserBanned, BrowserIncorrectPassword
|
from weboob.tools.browser import BrowserIncorrectPassword
|
||||||
from .pages import HomePage, LoginPage, HistoryPage, BillsPage, ErrorPage
|
from .pages import HomePage, LoginPage, HistoryPage, BillsPage, ErrorPage
|
||||||
|
|
||||||
__all__ = ['PoivyBrowser']
|
__all__ = ['PoivyBrowser']
|
||||||
|
|
@ -40,8 +39,7 @@ class PoivyBrowser(LoginBrowser):
|
||||||
|
|
||||||
self.login.stay_or_go()
|
self.login.stay_or_go()
|
||||||
|
|
||||||
if not self.page.login(self.username, self.password):
|
self.page.login(self.username, self.password)
|
||||||
raise BrowserBanned('Too many connections from you IP address: captcha enabled')
|
|
||||||
|
|
||||||
if self.login.is_here() or self.warning.is_here():
|
if self.login.is_here() or self.warning.is_here():
|
||||||
raise BrowserIncorrectPassword()
|
raise BrowserIncorrectPassword()
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from weboob.tools.browser import BrowserBanned
|
||||||
from weboob.tools.browser2.page import HTMLPage, LoggedPage, method, ListElement, ItemElement
|
from weboob.tools.browser2.page import HTMLPage, LoggedPage, method, ListElement, ItemElement
|
||||||
from weboob.tools.browser2.filters import Env, CleanText, CleanDecimal, Field, Attr, Filter, Time, Date, Link
|
from weboob.tools.browser2.filters import Env, CleanText, CleanDecimal, Field, Attr, Filter, Time, Date, Link
|
||||||
from weboob.capabilities.bill import Subscription, Detail
|
from weboob.capabilities.bill import Subscription, Detail
|
||||||
|
|
@ -35,36 +36,43 @@ class LoginPage(HTMLPage):
|
||||||
def login(self, login, password):
|
def login(self, login, password):
|
||||||
captcha = self.doc.xpath('//label[@class="label_captcha_input"]')
|
captcha = self.doc.xpath('//label[@class="label_captcha_input"]')
|
||||||
if len(captcha) > 0:
|
if len(captcha) > 0:
|
||||||
return False
|
raise BrowserBanned('Too many connections from you IP address: captcha enabled')
|
||||||
|
|
||||||
xpath_hidden = '//form[@id="newsletter_form"]/input[@type="hidden"]'
|
xpath_hidden = '//form[@id="newsletter_form"]/input[@type="hidden"]'
|
||||||
hidden_id = Attr(xpath_hidden, "value")(self.doc)
|
hidden_id = Attr(xpath_hidden, "value")(self.doc)
|
||||||
hidden_name = Attr(xpath_hidden, "name")(self.doc)
|
hidden_name = Attr(xpath_hidden, "name")(self.doc)
|
||||||
|
|
||||||
form = self.get_form(xpath="//form[@class='form-detail']")
|
form = self.get_form(xpath="//form[@class='form-detail']")
|
||||||
form['login[username]'] = login.encode('iso-8859-1')
|
form['login[username]'] = login
|
||||||
form['login[password]'] = password.encode('iso-8859-1')
|
form['login[password]'] = password
|
||||||
form[hidden_name] = hidden_id
|
form[hidden_name] = hidden_id
|
||||||
form.submit()
|
form.submit()
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class Insert2(Filter):
|
class InsertX(Filter):
|
||||||
"""
|
"""
|
||||||
Insert two Filters inside a string
|
Insert a list of Filters inside a string
|
||||||
"""
|
"""
|
||||||
def __init__(self, selector, selector2, string):
|
def __init__(self, selectors, string):
|
||||||
super(Insert2, self).__init__(selector)
|
|
||||||
self.string = string
|
self.string = string
|
||||||
self.selector2 = selector2
|
self.selectors = selectors
|
||||||
|
|
||||||
|
|
||||||
|
def map_filter(self, selector, item):
|
||||||
|
if isinstance(selector, basestring):
|
||||||
|
value = item.xpath(selector)
|
||||||
|
elif callable(selector):
|
||||||
|
value = selector(item)
|
||||||
|
else:
|
||||||
|
value = selector
|
||||||
|
return value
|
||||||
|
|
||||||
def __call__(self, item):
|
def __call__(self, item):
|
||||||
value = self.selector(item)
|
myliste = [self.map_filter(selector, item) for selector in self.selectors]
|
||||||
value2 = self.selector2(item)
|
return self.filter(tuple(myliste))
|
||||||
return self.filter(value, value2)
|
|
||||||
|
|
||||||
def filter(self, txt, txt2):
|
def filter(self, mytupple):
|
||||||
return self.string % (txt, txt2)
|
return self.string % mytupple
|
||||||
|
|
||||||
|
|
||||||
class HomePage(LoggedPage, HTMLPage):
|
class HomePage(LoggedPage, HTMLPage):
|
||||||
|
|
@ -78,7 +86,7 @@ class HomePage(LoggedPage, HTMLPage):
|
||||||
|
|
||||||
obj_id = CleanText('//span[@class="welcome-text"]/b')
|
obj_id = CleanText('//span[@class="welcome-text"]/b')
|
||||||
obj__balance = CleanDecimal(CleanText('//span[@class="balance"]'), replace_dots=False)
|
obj__balance = CleanDecimal(CleanText('//span[@class="balance"]'), replace_dots=False)
|
||||||
obj_label = Insert2(Field('id'), Field('_balance'), u"Poivy - %s - %s €")
|
obj_label = InsertX([Field('id'), Field('_balance')], u"Poivy - %s - %s €")
|
||||||
|
|
||||||
|
|
||||||
class HistoryPage(LoggedPage, HTMLPage):
|
class HistoryPage(LoggedPage, HTMLPage):
|
||||||
|
|
@ -102,16 +110,15 @@ class HistoryPage(LoggedPage, HTMLPage):
|
||||||
obj_datetime = Env('datetime')
|
obj_datetime = Env('datetime')
|
||||||
obj_price = CleanDecimal('td[7]', replace_dots=False, default=0)
|
obj_price = CleanDecimal('td[7]', replace_dots=False, default=0)
|
||||||
obj_currency = u'EUR'
|
obj_currency = u'EUR'
|
||||||
obj_label = Env('label')
|
obj_label = InsertX([CleanText('td[3]'), CleanText('td[4]'),
|
||||||
|
CleanText('td[5]'), CleanText('td[6]')],
|
||||||
|
u"%s from %s to %s - %s")
|
||||||
|
|
||||||
def parse(self, el):
|
def parse(self, el):
|
||||||
tds = el.xpath('td')
|
|
||||||
|
|
||||||
mydate = Date(CleanText('td[1]'))(el)
|
mydate = Date(CleanText('td[1]'))(el)
|
||||||
mytime = Time(CleanText('td[2]'))(el)
|
mytime = Time(CleanText('td[2]'))(el)
|
||||||
|
|
||||||
self.env['datetime'] = datetime.combine(mydate, mytime)
|
self.env['datetime'] = datetime.combine(mydate, mytime)
|
||||||
self.env['label'] = u"%s from %s to %s - %s" % (tds[2].text, tds[3].text, tds[4].text, tds[5].text)
|
|
||||||
|
|
||||||
|
|
||||||
#TODO
|
#TODO
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue