pax_global_header 0000666 0000000 0000000 00000000064 13400741301 0014503 g ustar 00root root 0000000 0000000 52 comment=309ae667efa3c8f7192ef6b744c295fbb8a2d101
woob-309ae667efa3c8f7192ef6b744c295fbb8a2d101-modules-ensap/ 0000775 0000000 0000000 00000000000 13400741301 0022314 5 ustar 00root root 0000000 0000000 woob-309ae667efa3c8f7192ef6b744c295fbb8a2d101-modules-ensap/modules/ 0000775 0000000 0000000 00000000000 13400741301 0023764 5 ustar 00root root 0000000 0000000 woob-309ae667efa3c8f7192ef6b744c295fbb8a2d101-modules-ensap/modules/ensap/ 0000775 0000000 0000000 00000000000 13400741301 0025072 5 ustar 00root root 0000000 0000000 woob-309ae667efa3c8f7192ef6b744c295fbb8a2d101-modules-ensap/modules/ensap/__init__.py 0000664 0000000 0000000 00000001510 13400741301 0027200 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Juliette Fourcot
#
# 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 .
from __future__ import unicode_literals
from .module import EnsapModule
__all__ = ['EnsapModule']
woob-309ae667efa3c8f7192ef6b744c295fbb8a2d101-modules-ensap/modules/ensap/browser.py 0000664 0000000 0000000 00000005330 13400741301 0027130 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Juliette Fourcot
#
# 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 .
from __future__ import unicode_literals
from weboob.browser import LoginBrowser, need_login, URL
from weboob.browser.profiles import Firefox
from weboob.exceptions import BrowserIncorrectPassword
from weboob.capabilities.base import find_object
from weboob.capabilities.bill import DocumentNotFound
from .pages import LoginPage, DocumentsPage, HomePage, LoginControlPage,\
LoginValidityPage
class EnsapBrowser(LoginBrowser):
BASEURL = 'https://ensap.gouv.fr'
PROFILE = Firefox()
loginp = URL('/web/views/contenus/accueilnonconnecte.html', LoginPage)
loginvalidity = URL('/authentification', LoginValidityPage)
authp = URL('/prive/initialiserhabilitation/v1', LoginControlPage)
homep = URL('/prive/accueilconnecte/v1', HomePage)
documents = URL('/prive/remuneration/v1', DocumentsPage)
logged = False
token = None
def do_login(self):
self.logger.debug('call Browser.do_login')
if self.logged:
return True
self.loginp.stay_or_go()
self.loginvalidity.go(data={"identifiant": self.username,
"secret": self.password})
if not self.page.check_logged():
raise BrowserIncorrectPassword()
self.authp.go(data={"": ""})
self.token = self.page.get_xsrf()
self.logged = True
@need_login
def iter_documents(self, subscription):
self.documents.stay_or_go(headers={"X-XSRF-TOKEN": self.token})
self.token = self.session.cookies.get("XSRF-TOKEN")
# return self.bills.go().iter_bills(subid=subscription.id)
return self.page.iter_documents()
@need_login
def iter_subscription(self):
self.homep.stay_or_go(headers={"X-XSRF-TOKEN": self.token})
self.token = self.session.cookies.get("XSRF-TOKEN")
return self.page.iter_subscription()
@need_login
def get_document(self, id):
return find_object(self.iter_documents(None), id=id,
error=DocumentNotFound())
woob-309ae667efa3c8f7192ef6b744c295fbb8a2d101-modules-ensap/modules/ensap/module.py 0000664 0000000 0000000 00000004745 13400741301 0026743 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Juliette Fourcot
#
# 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 .
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, SubscriptionNotFound,\
Document, DocumentNotFound
from weboob.tools.value import Value, ValueBackendPassword
from .browser import EnsapBrowser
__all__ = ['EnsapModule']
class EnsapModule(Module, CapDocument):
NAME = 'ensap'
DESCRIPTION = u'ensap website'
MAINTAINER = u'Juliette Fourcot'
EMAIL = 'juliette@fourcot.fr'
LICENSE = 'AGPLv3+'
VERSION = '1.4'
BROWSER = EnsapBrowser
CONFIG = BackendConfig(Value('login', label='User ID',
regexp='[0-9]{15}', required=True),
ValueBackendPassword('password', label='Password'))
def create_default_browser(self):
return self.create_browser(self.config['login'].get(),
self.config['password'].get())
def get_document(self, _id):
return find_object(self.iter_documents(None), id=_id,
error=DocumentNotFound)
def get_subscription(self, _id):
return find_object(self.browser.iter_subscription(), id=_id,
error=SubscriptionNotFound)
def iter_documents(self, subscription):
if isinstance(subscription, basestring):
subscription = self.get_subscription(subscription)
return self.browser.iter_documents(subscription)
def iter_subscription(self):
return self.browser.iter_subscription()
def download_document(self, doc):
if not isinstance(doc, Document):
doc = self.get_document(doc)
return self.browser.open(doc.url).content
woob-309ae667efa3c8f7192ef6b744c295fbb8a2d101-modules-ensap/modules/ensap/pages.py 0000664 0000000 0000000 00000004450 13400741301 0026546 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Juliette Fourcot
#
# 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 .
from __future__ import unicode_literals
from weboob.browser.pages import HTMLPage, JsonPage
from weboob.browser.elements import ItemElement, DictElement, method
from weboob.browser.filters.json import Dict
from weboob.capabilities.bill import Subscription, Document
from weboob.browser.filters.standard import Date, CleanText, Format, Regexp
class LoginPage(HTMLPage):
pass
class LoginValidityPage(JsonPage):
def check_logged(self):
if self.get("code") == 60:
return True
return False
class HomePage(JsonPage):
def iter_subscription(self):
obj = Subscription()
obj.subscriber = self.get("donnee.identification.identite")
obj.label = "Account of %s" % obj.subscriber
obj.id = CleanText(replace=[(' ', '.')]).filter(obj.subscriber)
return [obj]
class DocumentsPage(JsonPage):
@method
class iter_documents(DictElement):
item_xpath = 'donnee/listeDocument'
ignore_duplicate = True
class item(ItemElement):
klass = Document
obj_date = Date(Dict('date'))
obj_format = "pdf"
obj_label = Format("%s : %s", Dict('libelle1'), Dict('libelle3'))
obj_type = CleanText(Dict('libelleIcone'),
replace=[('IcĂ´ne ', '')])
obj_id = Regexp(Dict('libelle2'), r"(\S+)\.", nth=0)
obj_url = Format("/prive/telechargerdocument/v1?documentUuid=%s",
Dict('documentUuid'))
class LoginControlPage(JsonPage):
def get_xsrf(self):
return self.get("xcrf")