pax_global_header 0000666 0000000 0000000 00000000064 13514067645 0014525 g ustar 00root root 0000000 0000000 52 comment=6d52c0c92f2617476fe0b131c1eebba68676b2fb
woob-6d52c0c92f2617476fe0b131c1eebba68676b2fb-modules-lucca/ 0000775 0000000 0000000 00000000000 13514067645 0022302 5 ustar 00root root 0000000 0000000 woob-6d52c0c92f2617476fe0b131c1eebba68676b2fb-modules-lucca/modules/ 0000775 0000000 0000000 00000000000 13514067645 0023752 5 ustar 00root root 0000000 0000000 woob-6d52c0c92f2617476fe0b131c1eebba68676b2fb-modules-lucca/modules/lucca/ 0000775 0000000 0000000 00000000000 13514067645 0025041 5 ustar 00root root 0000000 0000000 woob-6d52c0c92f2617476fe0b131c1eebba68676b2fb-modules-lucca/modules/lucca/__init__.py 0000664 0000000 0000000 00000001556 13514067645 0027161 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2018 Vincent A
#
# 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 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 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see .
from __future__ import unicode_literals
from .module import LuccaModule
__all__ = ['LuccaModule']
woob-6d52c0c92f2617476fe0b131c1eebba68676b2fb-modules-lucca/modules/lucca/browser.py 0000664 0000000 0000000 00000007633 13514067645 0027107 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2018 Vincent A
#
# 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 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 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see .
from __future__ import unicode_literals
from datetime import timedelta
from weboob.browser import LoginBrowser, need_login, URL
from weboob.browser.exceptions import ClientError
from weboob.exceptions import BrowserIncorrectPassword
from weboob.tools.date import new_datetime
from .pages import (
LoginPage, CalendarPage, HomePage, UsersPage,
DocumentsPage, SubscriptionPage,
)
class LuccaBrowser(LoginBrowser):
BASEURL = 'https://www.ilucca.net'
login = URL('/login', LoginPage)
home = URL('/home', HomePage)
calendar = URL('/api/leaveAMPMs', CalendarPage)
users = URL(r'/api/departments\?fields=id%2Cname%2Ctype%2Clevel%2Cusers.id%2Cusers.displayName%2Cusers.dtContractStart%2Cusers.dtContractEnd%2Cusers.manager.id%2Cusers.manager2.id%2Cusers.legalEntityID%2Cusers.calendar.id&date=since%2C1970-01-01', UsersPage)
subscriptions = URL(r'/api/v3/users/me\?fields=id,firstName,lastName,allowsElectronicPayslip,culture,login,mail,personalemail', SubscriptionPage)
payslips = URL(r'/api/v3/payslips\?fields=id,import\[name,endDate\]&orderby=import\.endDate,desc,import\.startDate,desc,import\.creationDate,desc&ownerID=(?P\d+)', DocumentsPage)
def __init__(self, subdomain, *args, **kwargs):
super(LuccaBrowser, self).__init__(*args, **kwargs)
self.BASEURL = 'https://%s.ilucca.net' % subdomain
def do_login(self):
try:
self.login.go(data={
'Login': self.username,
'Password': self.password,
})
except ClientError as exc:
if 'Incorrect credentials' in exc.response.text:
raise BrowserIncorrectPassword()
raise
if not self.home.is_here():
raise BrowserIncorrectPassword()
@need_login
def all_events(self, start, end):
self.users.go()
users = {u.id: u for u in self.page.iter_users()}
last = None
while True:
if end:
if end < start:
break
else:
if last and last + timedelta(days=300) < start:
self.logger.info('300 days without event, stopping')
break
window_end = start + timedelta(days=14)
params = {
'date': 'between,%s,%s' % (start.strftime('%Y-%m-%d'), window_end.strftime('%Y-%m-%d')),
'paging': '0,10000',
'owner.id': ','.join(str(u.id) for u in users.values()),
'fields': 'u,a,o,ls,mc,r,c,rw',
}
self.calendar.go(params=params)
events = self.page.iter_events(start, users=users)
for event in sorted(events, key=lambda ev: new_datetime(ev.start_date)):
if end and event.start_date >= end:
continue
yield event
last = new_datetime(event.start_date)
start = window_end
@need_login
def get_subscription(self):
self.subscriptions.go()
return self.page.get_subscription()
@need_login
def iter_documents(self, subid):
self.payslips.go(subid=subid)
return self.page.iter_documents(subid)
woob-6d52c0c92f2617476fe0b131c1eebba68676b2fb-modules-lucca/modules/lucca/module.py 0000664 0000000 0000000 00000006626 13514067645 0026712 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2018 Vincent A
#
# 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 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 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser 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.tools.value import Value, ValueBackendPassword
from weboob.capabilities.base import find_object
from weboob.capabilities.calendar import CapCalendarEvent
from weboob.capabilities.bill import (
CapDocument, DocumentTypes, SubscriptionNotFound, DocumentNotFound,
Subscription,
)
from .browser import LuccaBrowser
__all__ = ['LuccaModule']
class LuccaModule(Module, CapDocument, CapCalendarEvent):
NAME = 'lucca'
DESCRIPTION = 'Lucca RH'
MAINTAINER = 'Vincent A'
EMAIL = 'dev@indigo.re'
LICENSE = 'LGPLv3+'
VERSION = '1.6'
BROWSER = LuccaBrowser
CONFIG = BackendConfig(
Value('subdomain', label='Sub-domain', regexp=r'[\w-]+'),
Value('login', label='Identifiant'),
ValueBackendPassword('password', label='Mot de passe'),
)
accepted_document_types = (DocumentTypes.BILL,)
def create_default_browser(self):
return self.create_browser(
self.config['subdomain'].get(),
self.config['login'].get(),
self.config['password'].get()
)
def get_event(self, _id):
"""
Get an event from an ID.
:param _id: id of the event
:type _id: str
:rtype: :class:`BaseCalendarEvent` or None is fot found.
"""
raise NotImplementedError()
def list_events(self, date_from, date_to=None):
return self.browser.all_events(date_from, date_to)
def search_events(self, query):
for ev in self.browser.all_events(query.start_date, query.end_date):
if query.summary:
if query.summary.lower() not in ev.summary.lower():
continue
yield ev
# TODO merge contiguous events?
def iter_subscription(self):
return [self.browser.get_subscription()]
def get_subscription(self, id):
return find_object(self.iter_subscription(), id=id, error=SubscriptionNotFound)
def iter_documents(self, subscription):
if not isinstance(subscription, str):
subscription = subscription.id
return self.browser.iter_documents(subscription)
def get_document(self, id):
subid = id.split('_')[0]
return find_object(self.iter_documents(subid), id=id, error=DocumentNotFound)
def download_document(self, document):
return self.browser.open(document.url).content
def iter_resources(self, objs, split_path):
if Subscription in objs:
return CapDocument.iter_resources(self, objs, split_path)
return CapCalendarEvent.iter_resources(self, objs, split_path)
woob-6d52c0c92f2617476fe0b131c1eebba68676b2fb-modules-lucca/modules/lucca/pages.py 0000664 0000000 0000000 00000007371 13514067645 0026522 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
# Copyright(C) 2018 Vincent A
#
# 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 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 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see .
from __future__ import unicode_literals
from datetime import timedelta
from weboob.browser.pages import HTMLPage, LoggedPage, JsonPage
from weboob.capabilities.calendar import BaseCalendarEvent, STATUS
from weboob.capabilities.bill import (
Subscription, Document, DocumentTypes,
)
from weboob.tools.date import new_date, parse_date
from weboob.tools.compat import urljoin
class LoginPage(HTMLPage):
pass
class HomePage(LoggedPage, HTMLPage):
pass
class User(object):
id = None
name = None
start = None
end = None
class UsersPage(LoggedPage, JsonPage):
def iter_users(self):
for dpt in self.doc['data']:
for d in dpt['users']:
u = User()
u.id = d['id']
u.name = d['displayName']
v = d['dtContractStart']
if v:
u.start = parse_date(v)
v = d['dtContractEnd']
if v:
u.end = parse_date(v)
yield u
class CalendarPage(LoggedPage, JsonPage):
@staticmethod
def _offset(start_date, offset):
return start_date + timedelta(days=offset)
def iter_events(self, start_date, users):
start_date = start_date.replace(hour=0, minute=0, second=0, microsecond=0)
for d in self.doc['data']:
if not d['ls']: # seems to be validation state
continue
assert d['ls'] == 2
user = users[d['u']]
ev = BaseCalendarEvent()
ev.timezone = 'Europe/Paris'
ev.summary = user.name
ev.status = STATUS.CONFIRMED
ev.start_date = self._offset(start_date, d['o'])
if d['a'] == 2:
ev.end_date = ev.start_date + timedelta(days=1)
ev.start_date = ev.start_date.date()
ev.end_date = ev.end_date.date()
elif d['a'] == 1:
ev.start_date = ev.start_date + timedelta(hours=12)
ev.end_date = ev.start_date + timedelta(hours=12)
else:
assert d['a'] == 0
ev.end_date = ev.start_date + timedelta(hours=12)
if user.end and new_date(user.end) < new_date(ev.start_date):
continue
yield ev
class SubscriptionPage(LoggedPage, JsonPage):
def get_subscription(self):
sub = Subscription()
sub.id = str(self.doc['data']['id'])
sub.subscriber = sub.label = self.doc['header']['principal']
return sub
class DocumentsPage(LoggedPage, JsonPage):
def iter_documents(self, subid):
for d in self.doc['data']['items']:
doc = Document()
doc.id = '%s_%s' % (subid, d['id'])
doc._docid = d['id']
doc.label = d['import']['name']
doc.date = parse_date(d['import']['endDate'])
doc.url = urljoin(self.url, '/pagga/download/%s' % doc._docid)
doc.type = DocumentTypes.BILL
doc.format = 'pdf'
yield doc