pax_global_header 0000666 0000000 0000000 00000000064 14042356110 0014506 g ustar 00root root 0000000 0000000 52 comment=18d41565f955028f9fcd2f6cc437f5f1cb717401
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-lampiris/ 0000775 0000000 0000000 00000000000 14042356110 0022617 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-lampiris/modules/ 0000775 0000000 0000000 00000000000 14042356110 0024267 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-lampiris/modules/lampiris/ 0000775 0000000 0000000 00000000000 14042356110 0026107 5 ustar 00root root 0000000 0000000 woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-lampiris/modules/lampiris/__init__.py 0000664 0000000 0000000 00000001567 14042356110 0030231 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Phyks (Lucas Verney)
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from __future__ import unicode_literals
from .module import LampirisModule
__all__ = ['LampirisModule']
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-lampiris/modules/lampiris/browser.py 0000664 0000000 0000000 00000004074 14042356110 0030151 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Phyks (Lucas Verney)
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from __future__ import unicode_literals
from woob.browser import LoginBrowser, URL, need_login
from woob.browser.exceptions import ClientError
from woob.exceptions import BrowserIncorrectPassword
from .pages import LoginPage, BillsPage
class LampirisBrowser(LoginBrowser):
BASEURL = 'https://espaceclient.total-spring.fr/'
loginpage = URL('/user/login', LoginPage)
billspage = URL('/factures-et-paiements', BillsPage)
selectcus = URL('/set_selected_cus')
def __init__(self, *args, **kwargs):
self.logged = False
super(LampirisBrowser, self).__init__(*args, **kwargs)
def do_login(self):
if self.logged:
return
self.loginpage.stay_or_go().do_login(self.username, self.password)
try:
self.billspage.go()
self.logged = True
except ClientError:
raise BrowserIncorrectPassword()
@need_login
def get_subscriptions(self):
return self.billspage.go().get_subscriptions()
@need_login
def get_documents(self, subscription):
# Select subscription
self.selectcus.go(params={'cus': subscription.id})
# Then, fetch documents
for doc in self.billspage.go().get_documents():
doc.id = "{}#{}".format(subscription.id, doc.id)
yield doc
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-lampiris/modules/lampiris/module.py 0000664 0000000 0000000 00000006276 14042356110 0027761 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Phyks (Lucas Verney)
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from __future__ import unicode_literals
from woob.tools.backend import BackendConfig, Module
from woob.tools.value import Value, ValueBackendPassword
from woob.capabilities.base import find_object
from woob.capabilities.bill import Bill, CapDocument, DocumentNotFound, SubscriptionNotFound, Subscription
from .browser import LampirisBrowser
__all__ = ['LampirisModule']
class LampirisModule(Module, CapDocument):
NAME = 'lampiris'
DESCRIPTION = u'French electricity provider Lampiris.fr'
MAINTAINER = u'Phyks (Lucas Verney)'
EMAIL = 'phyks@phyks.me'
LICENSE = 'LGPLv3+'
VERSION = '3.1'
CONFIG = BackendConfig(
Value(
'email',
label='Email',
),
ValueBackendPassword(
'password',
label='Password'
)
)
BROWSER = LampirisBrowser
def create_default_browser(self):
return self.create_browser(
self.config['email'].get(),
self.config['password'].get()
)
def download_document(self, id):
"""
Download a document.
:param id: ID of document
:rtype: str
:raises: :class:`DocumentNotFound`
"""
if not isinstance(id, Bill):
doc = self.get_document(id)
else:
doc = id
if not doc.url:
return None
return self.browser.open(doc.url).content
def get_document(self, id):
"""
Get a document.
:param id: ID of document
:rtype: :class:`Document`
:raises: :class:`DocumentNotFound`
"""
return find_object(self.iter_documents(id.split("#")[0]),
id=id,
error=DocumentNotFound)
def iter_documents(self, subscription):
"""
Iter documents.
:param subscription: subscription to get documents
:type subscription: :class:`Subscription`
:rtype: iter[:class:`Document`]
"""
if not isinstance(subscription, Subscription):
subscription = find_object(self.iter_subscription(),
id=subscription,
error=SubscriptionNotFound)
return self.browser.get_documents(subscription)
def iter_subscription(self):
"""
Iter subscriptions.
:rtype: iter[:class:`Subscription`]
"""
return self.browser.get_subscriptions()
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-lampiris/modules/lampiris/pages.py 0000664 0000000 0000000 00000005615 14042356110 0027567 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Phyks (Lucas Verney)
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from __future__ import unicode_literals
from woob.browser.elements import ItemElement, ListElement, method
from woob.browser.filters.html import Attr, CleanHTML, Link, XPathNotFound
from woob.browser.filters.standard import CleanDecimal, CleanText, Date, Format
from woob.browser.pages import HTMLPage
from woob.capabilities.base import NotAvailable, Currency
from woob.capabilities.bill import Bill, Subscription
from woob.tools.compat import urljoin
class LoginPage(HTMLPage):
def do_login(self, email, password):
form = self.get_form(xpath='//form[@id="user-login"]')
form['name'] = email
form['pass'] = password
form.submit()
class BillsPage(HTMLPage):
@method
class get_subscriptions(ListElement):
item_xpath = '//div[@id="cusModal"]//div[has-class("cus-detail-wrapper")]'
class item(ItemElement):
klass = Subscription
# TODO: Handle energy type
obj_label = CleanText(CleanHTML('.'))
obj_id = Attr('./input', 'value')
@method
class get_documents(ListElement):
item_xpath = '//table[has-class("invoice-table-stickyheader")]/tbody/tr'
class item(ItemElement):
klass = Bill
def condition(self):
return len(self.el.xpath('./td')) > 3
obj_id = Attr('./td[3]/span', 'title')
obj_type = Format(
'%s - %s',
CleanText('./td[2]'),
Attr('./td[1]//img', 'title', default="")
)
obj_label = obj_type
obj_format = 'pdf'
obj_date = Date(CleanText('./td[4]'))
obj_price = CleanDecimal('./td[5]', replace_dots=(' ', ','))
def obj_currency(self):
return Currency.get_currency(CleanText('./td[5]')(self))
obj_duedate = Date(CleanText('./td[6]'))
def obj_url(self):
try:
return urljoin(
self.page.browser.BASEURL,
Link('./td[8]/a[1]')(self)
)
except XPathNotFound:
return NotAvailable
woob-18d41565f955028f9fcd2f6cc437f5f1cb717401-modules-lampiris/modules/lampiris/test.py 0000664 0000000 0000000 00000003326 14042356110 0027444 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Phyks (Lucas Verney)
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see .
from __future__ import unicode_literals
from woob.tools.test import BackendTest
class LampirisTest(BackendTest):
MODULE = 'lampiris'
def test_subscriptions(self):
"""
Test listing of subscriptions.
"""
subscriptions = list(self.backend.iter_subscription())
self.assertTrue(list(subscriptions), msg="Failed to list accounts.")
def test_documents(self):
"""
Test listing all available documents.
"""
for subscription in self.backend.iter_subscription():
documents = self.backend.iter_documents(subscription.id)
self.assertTrue(list(documents), msg="Failed to list documents.")
def test_download(self):
"""
Test downloading all documents.
"""
for subscription in self.backend.iter_subscription():
for bill in self.backend.iter_documents(subscription.id):
self.backend.download_document(bill.id)