pax_global_header 0000666 0000000 0000000 00000000064 13434601454 0014516 g ustar 00root root 0000000 0000000 52 comment=d0a72914b1b13c7766ca764ce93a9d23b473bfe7
woob-d0a72914b1b13c7766ca764ce93a9d23b473bfe7-modules-ensap/ 0000775 0000000 0000000 00000000000 13434601454 0022241 5 ustar 00root root 0000000 0000000 woob-d0a72914b1b13c7766ca764ce93a9d23b473bfe7-modules-ensap/modules/ 0000775 0000000 0000000 00000000000 13434601454 0023711 5 ustar 00root root 0000000 0000000 woob-d0a72914b1b13c7766ca764ce93a9d23b473bfe7-modules-ensap/modules/ensap/ 0000775 0000000 0000000 00000000000 13434601454 0025017 5 ustar 00root root 0000000 0000000 woob-d0a72914b1b13c7766ca764ce93a9d23b473bfe7-modules-ensap/modules/ensap/__init__.py 0000664 0000000 0000000 00000001565 13434601454 0027137 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Juliette Fourcot
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. If not, see .
from __future__ import unicode_literals
from .module import EnsapModule
__all__ = ['EnsapModule']
woob-d0a72914b1b13c7766ca764ce93a9d23b473bfe7-modules-ensap/modules/ensap/browser.py 0000664 0000000 0000000 00000006042 13434601454 0027056 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Juliette Fourcot
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. 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, ListYear
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/(?P\d+)', DocumentsPage)
listyears = URL('/prive/listeanneeremuneration/v1', ListYear)
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="{}", headers={'Content-Type': 'application/json'})
self.token = self.page.get_xsrf()
self.logged = True
@need_login
def iter_documents(self, subscription):
self.listyears.go()
years = self.page.get_years()
# use reverse order of list to get recent documents first
for year in years[::-1]:
self.documents.stay_or_go(year=year, headers={"X-XSRF-TOKEN": self.token})
self.token = self.session.cookies.get("XSRF-TOKEN")
for doc in self.page.iter_documents():
yield doc
@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-d0a72914b1b13c7766ca764ce93a9d23b473bfe7-modules-ensap/modules/ensap/module.py 0000664 0000000 0000000 00000005022 13434601454 0026655 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Juliette Fourcot
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. 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.5'
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-d0a72914b1b13c7766ca764ce93a9d23b473bfe7-modules-ensap/modules/ensap/pages.py 0000664 0000000 0000000 00000004662 13434601454 0026500 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2017 Juliette Fourcot
#
# This file is part of a weboob module.
#
# This weboob module 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.
#
# This weboob 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this weboob module. 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'
ignore_duplicate = True
class item(ItemElement):
klass = Document
obj_date = Date(Dict('dateDocument'))
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/telechargerdocumentremuneration/v1?documentUuid=%s",
Dict('documentUuid'))
class LoginControlPage(JsonPage):
def get_xsrf(self):
return self.get("xcrf")
class ListYear(JsonPage):
def get_years(self):
return self.get("donnee")