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

# Copyright(C) 2013      Bezleputh
#
Roger Philibert's avatar
Roger Philibert committed
# This file is part of a woob module.
Bezleputh's avatar
Bezleputh committed
#
Roger Philibert's avatar
Roger Philibert committed
# This woob 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.
#
Roger Philibert's avatar
Roger Philibert committed
# This woob 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
Roger Philibert's avatar
Roger Philibert committed
# along with this woob 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 woob.browser.pages import HTMLPage, pagination
from woob.browser.elements import ListElement, ItemElement, method
from woob.browser.filters.standard import Filter, CleanText, Regexp, Format, Env
from woob.browser.filters.html import CleanHTML, Attr
from woob.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"]'))