pax_global_header 0000666 0000000 0000000 00000000064 13436457030 0014517 g ustar 00root root 0000000 0000000 52 comment=3863a14eedf17551743a8bbccf0237874d7f4a16
woob-3863a14eedf17551743a8bbccf0237874d7f4a16-modules-edf-par/ 0000775 0000000 0000000 00000000000 13436457030 0022374 5 ustar 00root root 0000000 0000000 woob-3863a14eedf17551743a8bbccf0237874d7f4a16-modules-edf-par/modules/ 0000775 0000000 0000000 00000000000 13436457030 0024044 5 ustar 00root root 0000000 0000000 woob-3863a14eedf17551743a8bbccf0237874d7f4a16-modules-edf-par/modules/edf/ 0000775 0000000 0000000 00000000000 13436457030 0024602 5 ustar 00root root 0000000 0000000 woob-3863a14eedf17551743a8bbccf0237874d7f4a16-modules-edf-par/modules/edf/par/ 0000775 0000000 0000000 00000000000 13436457030 0025364 5 ustar 00root root 0000000 0000000 woob-3863a14eedf17551743a8bbccf0237874d7f4a16-modules-edf-par/modules/edf/par/__init__.py 0000664 0000000 0000000 00000000000 13436457030 0027463 0 ustar 00root root 0000000 0000000 woob-3863a14eedf17551743a8bbccf0237874d7f4a16-modules-edf-par/modules/edf/par/browser.py 0000664 0000000 0000000 00000014560 13436457030 0027427 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2016 Edouard Lambert
#
# 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 time import time
from weboob.browser import LoginBrowser, URL, need_login
from weboob.browser.exceptions import ClientError
from weboob.exceptions import BrowserIncorrectPassword, NocaptchaQuestion
from weboob.tools.decorators import retry
from weboob.tools.json import json
from .pages import (
HomePage, AuthenticatePage, AuthorizePage, CheckAuthenticatePage, ProfilPage,
DocumentsPage, WelcomePage, UnLoggedPage, ProfilePage, BillDownload,
)
class BrokenPageError(Exception):
pass
class EdfBrowser(LoginBrowser):
BASEURL = 'https://particulier.edf.fr'
home = URL('/fr/accueil/contrat-et-conso/mon-compte-edf.html', HomePage)
authenticate = URL(r'https://espace-client.edf.fr/sso/json/authenticate', AuthenticatePage)
authorize = URL(r'https://espace-client.edf.fr/sso/oauth2/INTERNET/authorize', AuthorizePage)
check_authenticate = URL('/services/rest/openid/checkAuthenticate', CheckAuthenticatePage)
not_connected = URL('/fr/accueil/connexion/mon-espace-client.html', UnLoggedPage)
connected = URL('/fr/accueil/espace-client/tableau-de-bord.html', WelcomePage)
profil = URL('/services/rest/authenticate/getListContracts', ProfilPage)
csrf_token = URL(r'/services/rest/init/initPage\?_=(?P.*)', ProfilPage)
documents = URL('/services/rest/edoc/getMyDocuments', DocumentsPage)
bills = URL('/services/rest/edoc/getBillsDocuments', DocumentsPage)
bill_informations = URL('/services/rest/document/dataUserDocumentGetX', DocumentsPage)
bill_download = URL(r'/services/rest/document/getDocumentGetXByData'
r'\?csrfToken=(?P.*)&dn=(?P.*)&pn=(?P.*)'
r'&di=(?P.*)&bn=(?P.*)&an=(?P.*)', BillDownload)
profile = URL('/services/rest/context/getCustomerContext', ProfilePage)
def __init__(self, config, *args, **kwargs):
self.config = config
self.authId = None
kwargs['username'] = self.config['login'].get()
kwargs['password'] = self.config['password'].get()
super(EdfBrowser, self).__init__(*args, **kwargs)
def do_login(self):
auth_params = {'realm': '/INTERNET'}
if self.config['captcha_response'].get() and self.authId:
self.authenticate.go(method='POST', params=auth_params)
data = self.page.get_data()
data['authId'] = self.authId
data['callbacks'][0]['input'][0]['value'] = self.username
data['callbacks'][1]['input'][0]['value'] = self.password
data['callbacks'][2]['input'][0]['value'] = self.config['captcha_response'].get()
data['callbacks'][3]['input'][0]['value'] = '0'
try:
self.authenticate.go(json=data, params=auth_params)
except ClientError as error:
resp = error.response
if resp.status_code == 401:
raise BrowserIncorrectPassword(resp.json()['message'])
raise
self.session.cookies['ivoiream'] = self.page.get_data()['tokenId']
# go to this url will auto submit a form which will finalize login
self.connected.go()
"""
call check_authenticate url before get subscription in profil, or we'll get an error 'invalid session'
we do nothing with this response (which contains false btw)
but edf website expect we call it before or will reject us
"""
self.check_authenticate.go()
else:
self.authenticate.go(method='POST', params=auth_params)
if self.page.has_captcha_request():
data = self.page.get_data()
website_key = data['callbacks'][4]['output'][0]['value']
website_url = "https://espace-client.edf.fr/sso/XUI/#login/&realm=%2FINTERNET"
self.authId = data['authId']
raise NocaptchaQuestion(website_key=website_key, website_url=website_url)
def get_csrf_token(self):
return self.csrf_token.go(timestamp=int(time())).get_token()
@need_login
def get_subscription_list(self):
return self.profil.stay_or_go().iter_subscriptions()
@need_login
def iter_documents(self, subscription):
self.documents.go() # go to docs before, else we get an error, thanks EDF
return self.bills.go().iter_bills(subid=subscription.id)
@retry(BrokenPageError, tries=2, delay=4)
@need_login
def download_document(self, document):
token = self.get_csrf_token()
bills_informations = self.bill_informations.go(headers={
'Content-Type': 'application/json;charset=UTF-8',
'Accept': 'application/json, text/plain, */*'},
data=json.dumps({
'bpNumber': document._bp,
'csrfToken': token,
'docId': document._doc_number,
'docName': 'FACTURE',
'numAcc': document._num_acc,
'parNumber': document._par_number
})).get_bills_informations()
self.bill_download.go(csrf_token=token, dn='FACTURE', pn=document._par_number,
di=document._doc_number, bn=bills_informations.get('bpNumber'),
an=bills_informations.get('numAcc'))
# sometimes we land to another page that tell us, this document doesn't exist, but just sometimes...
# make sure this page is the right one to avoid return a html page as document
if not self.bill_download.is_here():
raise BrokenPageError()
return self.page.content
@need_login
def get_profile(self):
self.profile.go()
return self.page.get_profile()
woob-3863a14eedf17551743a8bbccf0237874d7f4a16-modules-edf-par/modules/edf/par/pages.py 0000664 0000000 0000000 00000011042 13436457030 0027033 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2016 Edouard Lambert
#
# 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 datetime import datetime
from decimal import Decimal
from weboob.browser.filters.html import Attr
from weboob.browser.pages import LoggedPage, JsonPage, HTMLPage, RawPage
from weboob.browser.filters.standard import Env, Format, Date, Eval
from weboob.browser.elements import ItemElement, DictElement, method
from weboob.browser.filters.json import Dict
from weboob.capabilities.bill import DocumentTypes, Bill, Subscription
from weboob.capabilities.base import NotAvailable
from weboob.capabilities.profile import Profile
class HomePage(HTMLPage):
pass
class AuthenticatePage(JsonPage):
def has_captcha_request(self):
return self.doc['stage'] == "RecaptchaModuleS1"
def get_data(self):
return self.doc
class AuthorizePage(HTMLPage):
def on_load(self):
if Attr('//body', 'onload', default=NotAvailable)(self.doc):
self.get_form().submit()
class WelcomePage(LoggedPage, HTMLPage):
pass
class CheckAuthenticatePage(LoggedPage, RawPage):
pass
class UnLoggedPage(HTMLPage):
pass
class ProfilPage(LoggedPage, JsonPage):
@method
class iter_subscriptions(DictElement):
item_xpath = 'customerAccordContracts'
class item(ItemElement):
klass = Subscription
obj_subscriber = Format('%s %s', Dict('bp/identity/firstName'),
Dict('bp/identity/lastName'))
obj_id = Dict('number')
obj_label = obj_id
def get_token(self):
return Dict('data')(self.doc)
class DocumentsPage(LoggedPage, JsonPage):
@method
class iter_bills(DictElement):
def parse(self, el):
for i, sub_group in enumerate(self.el):
for j, sub in enumerate(Dict('listOfBillsByAccDTO')(sub_group)):
if Dict('accDTO/numAcc')(sub) in Env('subid')(self):
self.item_xpath = "%d/listOfBillsByAccDTO/%d/listOfbills" % (i, j)
self.env['bpNumber'] = Dict('%d/bpDto/bpNumber' % i)(self)
break
class item(ItemElement):
klass = Bill
obj_id = Format('%s_%s', Env('subid'), Dict('documentNumber'))
obj_date = Date(Eval(lambda t: datetime.fromtimestamp(int(t) / 1000) \
.strftime('%Y-%m-%d'), Dict('creationDate')))
obj_format = 'pdf'
obj_label = Format('Facture %s', Dict('documentNumber'))
obj_type = DocumentTypes.BILL
obj_price = Env('price')
obj_currency = 'EUR'
obj_vat = NotAvailable
obj__doc_number = Dict('documentNumber')
obj__par_number = Dict('parNumber')
obj__num_acc = Env('numAcc')
obj__bp = Env('bpNumber')
def parse(self, el):
self.env['price'] = Decimal(Dict('billAmount')(self))
self.env['numAcc'] = str(int(Env('subid')(self)))
def get_bills_informations(self):
return {
'bpNumber': Dict('bpNumber')(self.doc),
'docId': Dict('docId')(self.doc),
'docName': Dict('docName')(self.doc),
'numAcc': Dict('numAcc')(self.doc),
'parNumber': Dict('parNumber')(self.doc)
}
class ProfilePage(LoggedPage, JsonPage):
def get_profile(self):
data = self.doc['bp']
p = Profile()
p.address = '%s %s %s %s' % (data['streetNumber'], data['streetName'],
data['postCode'], data['city'])
p.name = '%s %s %s' % (data['civility'], data['lastName'], data['firstName'])
p.phone = data['mobilePhoneNumber'] or data['fixPhoneNumber']
p.email = data['mail']
return p
class BillDownload(LoggedPage, RawPage):
pass