Skip to content
pages.py 3.52 KiB
Newer Older
Bezleputh's avatar
Bezleputh committed
# -*- coding: utf-8 -*-

# Copyright(C) 2013      Bezleputh
#
# This file is part of a weboob module.
Bezleputh's avatar
Bezleputh committed
#
# This weboob module is free software: you can redistribute it and/or modify
Bezleputh's avatar
Bezleputh committed
# 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,
Bezleputh's avatar
Bezleputh committed
# 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 <http://www.gnu.org/licenses/>.
Bezleputh's avatar
Bezleputh committed

Bezleputh's avatar
Bezleputh committed
from datetime import timedelta, datetime
Bezleputh's avatar
Bezleputh committed
import re
from weboob.browser.pages import HTMLPage, pagination
from weboob.browser.elements import ListElement, ItemElement, method
from weboob.browser.filters.standard import Filter, CleanText, Regexp, Format, Env
from weboob.browser.filters.html import CleanHTML, Attr
Bezleputh's avatar
Bezleputh committed
from weboob.capabilities.job import BaseJobAdvert
Bezleputh's avatar
Bezleputh committed


Bezleputh's avatar
Bezleputh committed
class IndeedDate(Filter):
    def filter(self, date):
        now = datetime.now()
        number = re.search("\d+", date)
        if number:
            if 'heures' in date:
                return now - timedelta(hours=int(number.group(0)))
            elif 'jour' in date:
                return now - timedelta(days=int(number.group(0)))
        return now
Bezleputh's avatar
Bezleputh committed


Bezleputh's avatar
Bezleputh committed
class SearchPage(HTMLPage):
    @pagination
    @method
    class iter_job_adverts(ListElement):
        item_xpath = '//div[@data-tn-component="organicJob"]'
Bezleputh's avatar
Bezleputh committed

Bezleputh's avatar
Bezleputh committed
        def next_page(self):
            for a in self.page.doc.xpath('//a'):
                if a.xpath('span[@class="pn"]/span[@class="np"]') and \
                   "Suivant" in a.xpath('span[@class="pn"]/span[@class="np"]')[0].text:
                    return a.attrib['href'].replace('jobs?', 'emplois?')
Bezleputh's avatar
Bezleputh committed

Bezleputh's avatar
Bezleputh committed
        class Item(ItemElement):
            klass = BaseJobAdvert
Bezleputh's avatar
Bezleputh committed

Bezleputh's avatar
Bezleputh committed
            obj_id = CleanText(Format('%s#%s#%s',
                                      Regexp(Attr('.', 'id'), '^..(.*)'),
                                      Attr('div[@class="title"]/a', 'title'),
Bezleputh's avatar
Bezleputh committed
                                      CleanText('span[@class="company"]')),
                               replace=[(" ", "-"), ("/", "-")])
            obj_title = Attr('div[@class="title"]/a', 'title')
Bezleputh's avatar
Bezleputh committed
            obj_society_name = CleanText('span[@class="company"]')
            obj_place = CleanText('span/span[@class="location"]')
            obj_publication_date = IndeedDate(CleanText('table/tr/td/span[@class="date"]'))
Bezleputh's avatar
Bezleputh committed


Bezleputh's avatar
Bezleputh committed
class AdvertPage(HTMLPage):
Bezleputh's avatar
Bezleputh committed

Bezleputh's avatar
Bezleputh committed
    @method
    class get_job_advert(ItemElement):
        klass = BaseJobAdvert

        def parse(self, el):
            self.env['url'] = self.page.url
            self.env['num_id'] = self.page.url.split('-')[-1]
Bezleputh's avatar
Bezleputh committed

Bezleputh's avatar
Bezleputh committed
        obj_id = Format('%s#%s#%s',
                        Env('num_id'),
                        CleanText('//div[@id="job_header"]/b[@class="jobtitle"]'),
                        CleanText('//div[@id="job_header"]/span[@class="company"]'),
                        )
        obj_title = CleanText('//div[@id="job_header"]/b[@class="jobtitle"]')
        obj_place = CleanText('//div[@id="job_header"]/span[@class="location"]')
        obj_description = CleanHTML('//span[@class="summary"]')
        obj_job_name = CleanText('//div[@id="job_header"]/b[@class="jobtitle"]')
        obj_url = Env('url')
        obj_publication_date = IndeedDate(CleanText('//span[@class="date"]'))