Commit 8cdcb9d1 authored by Thibault Douge's avatar Thibault Douge Committed by Vincent A

[myfoncia] get new documents, management report

parent c5a037f9
......@@ -23,7 +23,7 @@ from __future__ import unicode_literals
from weboob.browser import LoginBrowser, need_login, URL
from weboob.exceptions import BrowserIncorrectPassword
from .pages import LoginPage, MonBienPage, MesChargesPage
from .pages import LoginPage, MonBienPage, MesChargesPage, DocumentsPage
class MyFonciaBrowser(LoginBrowser):
......@@ -32,6 +32,7 @@ class MyFonciaBrowser(LoginBrowser):
login = URL(r'/login', LoginPage)
monBien = URL(r'/espace-client/espace-de-gestion/mon-bien', MonBienPage)
mesCharges = URL(r'/espace-client/espace-de-gestion/mes-charges/(?P<subscription>.+)', MesChargesPage)
documents = URL(r'/espace-client/espace-de-gestion/mes-documents/(?P<subscription>.+)/(?P<letter>[A-Z])', DocumentsPage)
def do_login(self):
self.login.stay_or_go().do_login(self.username, self.password)
......@@ -45,5 +46,14 @@ class MyFonciaBrowser(LoginBrowser):
return self.monBien.stay_or_go().get_subscriptions()
@need_login
def get_documents(self, subscription):
return self.mesCharges.stay_or_go(subscription=subscription).get_documents()
def get_documents(self, subscription_id):
# the last char of subscription_id is a letter, we need this to put this at the end of the url
if not subscription_id[-1:].isupper():
self.logger.debug('The last char of subscription id is not an uppercase')
self.documents.go(subscription=subscription_id, letter=subscription_id[-1:])
for doc in self.page.iter_documents():
yield doc
self.mesCharges.go(subscription=subscription_id)
for bill in self.page.get_documents():
yield bill
......@@ -22,9 +22,11 @@ from __future__ import unicode_literals
from weboob.tools.backend import Module, BackendConfig
from weboob.capabilities.base import find_object
from weboob.capabilities.bill import (CapDocument, Bill, DocumentNotFound,
Subscription)
from weboob.tools.value import Value, ValueBackendPassword
from weboob.capabilities.bill import (
CapDocument, DocumentNotFound,
Subscription, DocumentTypes, Document,
)
from weboob.tools.value import ValueBackendPassword
from .browser import MyFonciaBrowser
......@@ -40,20 +42,18 @@ class MyFonciaModule(Module, CapDocument):
LICENSE = 'LGPLv3+'
VERSION = '2.1'
CONFIG = BackendConfig(
Value(
'login',
label='Email address or Foncia ID'
),
ValueBackendPassword(
'password',
label='Password'
)
ValueBackendPassword('login', label='Email address or Foncia ID'),
ValueBackendPassword('password', label='Password'),
)
BROWSER = MyFonciaBrowser
accepted_document_types = (DocumentTypes.BILL, DocumentTypes.REPORT,)
def create_default_browser(self):
return self.create_browser(self.config['login'].get(),
self.config['password'].get())
return self.create_browser(
self.config['login'].get(),
self.config['password'].get()
)
def iter_subscription(self):
return self.browser.get_subscriptions()
......@@ -65,18 +65,17 @@ class MyFonciaModule(Module, CapDocument):
subscription_id = subscription
return self.browser.get_documents(subscription_id)
def get_document(self, bill):
return find_object(
self.iter_documents(bill.split("#")[0]),
id=bill,
error=DocumentNotFound
)
def get_document(self, _id):
subid = _id.rsplit('_', 1)[0]
subscription = self.get_subscription(subid)
return find_object(self.iter_documents(subscription), id=_id, error=DocumentNotFound)
def download_document(self, bill):
if not isinstance(bill, Bill):
bill = self.get_document(bill)
def download_document(self, document):
if not isinstance(document, Document):
document = self.get_document(document)
if not bill.url:
if not document.url:
return None
return self.browser.open(bill.url).content
return self.browser.open(document.url).content
......@@ -21,10 +21,10 @@ from __future__ import unicode_literals
from weboob.browser.pages import HTMLPage, LoggedPage
from weboob.browser.filters.standard import CleanDecimal, CleanText, Date, Env, Format
from weboob.browser.filters.html import Attr, Link, XPathNotFound
from weboob.browser.filters.html import Attr, Link, XPathNotFound, AbsoluteLink
from weboob.browser.elements import ItemElement, ListElement, method
from weboob.capabilities.base import NotAvailable
from weboob.capabilities.bill import Bill, Subscription
from weboob.capabilities.bill import Bill, Subscription, Document, DocumentTypes
from weboob.tools.compat import urljoin
......@@ -72,7 +72,7 @@ class MesChargesPage(LoggedPage, HTMLPage):
klass = Bill
obj_id = Format(
'%s#%s',
'%s_%s',
Env('subscription'),
Attr('.', 'id')
)
......@@ -100,3 +100,22 @@ class MesChargesPage(LoggedPage, HTMLPage):
)
except XPathNotFound:
return NotAvailable
class DocumentsPage(LoggedPage, HTMLPage):
@method
class iter_documents(ListElement):
item_xpath = '//main[@role="main"]//article'
class item(ItemElement):
klass = Document
def condition(self):
return CleanText('.//p[@data-behat="descOfUtilityRecord"]')(self) == 'CRG'
obj_id = Format('%s_%s', Attr('.', 'id'), Env('subscription'))
obj_date = Date(CleanText('.//p[@data-behat="dateOfUtilityRecord"]'), dayfirst=True)
obj_label = CleanText('.//p[@data-behat="descOfUtilityRecord"]')
obj_url = AbsoluteLink('.//a[@class="Download"]')
obj_format = 'pdf'
obj_type = DocumentTypes.REPORT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment