pages.py 4.99 KB
Newer Older
1 2 3 4
# -*- coding: utf-8 -*-

# Copyright(C) 2013      Bezleputh
#
5
# This file is part of a weboob module.
6
#
7
# This weboob module is free software: you can redistribute it and/or modify
8 9 10 11
# 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.
#
12
# This weboob module is distributed in the hope that it will be useful,
13 14 15 16 17
# 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
18
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
19

20 21 22
import requests
from weboob.browser.pages import HTMLPage, pagination, JsonPage
from weboob.browser.elements import ItemElement, method, DictElement
23

24
from .compat.weboob_browser_filters_standard import CleanText, Regexp, Date
25
from weboob.browser.filters.html import CleanHTML
26
from weboob.browser.filters.json import Dict
27

28
from weboob.browser.filters.javascript import JSVar
29
from weboob.capabilities.job import BaseJobAdvert
30
from weboob.capabilities.base import empty
31 32 33


class SearchPage(HTMLPage):
34
    def get_post_params(self):
35
        return {'facetSettingId': JSVar(CleanText('//script'), var='_FacetName')(self.doc),
36 37 38 39 40 41 42
                'currentLanguage': JSVar(CleanText('//script'), var='_CurrentLanguage')(self.doc),
                'clientId': JSVar(CleanText('//script'), var='_ClientId')(self.doc),
                'branchId': JSVar(CleanText('//script'), var='_BranchId')(self.doc),
                'clientName':  JSVar(CleanText('//script'), var='_ClientName')(self.doc)}


class AdvertsJsonPage(JsonPage):
43 44
    @pagination
    @method
45 46
    class iter_job_adverts(DictElement):
        item_xpath = 'Items'
47 48

        def next_page(self):
49 50 51 52 53
            if len(self.page.doc['Pagination']) >= 2:
                if self.page.doc['Pagination'][-2]['keyName'] == u'Suivant':
                    url = self.page.doc['Pagination'][-2]['valueName']
                    self.env['data']['filterUrl'] = u'http://www.adecco.fr%s' % url
                    return requests.Request("POST", self.page.url, data=self.env['data'])
54 55 56 57

        class item(ItemElement):
            klass = BaseJobAdvert

58 59 60 61 62 63
            def validate(self, advert):
                if empty(advert.publication_date) or not self.env['date_min']:
                    return advert

                if advert.publication_date >= self.env['date_min']:
                    return advert
64

65 66 67 68
            obj_id = Dict('JobId')
            obj_title = Dict('JobTitle')
            obj_place = Dict('JobLocation')
            obj_publication_date = Date(Dict('PostedDate'))
69 70 71 72 73 74 75


class AdvertPage(HTMLPage):
    @method
    class get_job_advert(ItemElement):
        klass = BaseJobAdvert

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        def obj_id(self):
            _id = Regexp(CleanText('//meta[@property="og:url"]/@content'),
                         '.*\?ID=(.*)',
                         default=None)(self)
            if _id is None:
                _id = JSVar(CleanText('//script'), var='_JobDetailsId')(self)
            return _id

        def obj_title(self):
            title = CleanText('//meta[@property="og:title"]/@content',
                              default=None)(self)
            if title is None:
                title = JSVar(CleanText('//script'), var='_JobTitle')(self)
            return title

        def obj_place(self):
            place = CleanText('//span[@itemprop="jobLocation"]', default=None)(self)
93 94 95
            if not place:
                place = CleanText('//li[@class="job--meta_location"]')(self)

96 97
            if not place:
                place = Regexp(CleanText('//meta[@property="og:title"]/@content'),
98
                               u'.*\ à (.*)')(self)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
            return place

        def obj_publication_date(self):
            date = Date(CleanText('//time[@itemprop="startDate"]'), default=None)(self)
            if date is None:
                date = Date(CleanText('//span[@id="posted-date"]'))(self)
            return date

        obj_contract_type = CleanText('//li[@class="job--meta_employment-type"]/div/div/span[@class="job-details-value"]')

        # obj_pay = CleanText('//div[@class="jobGreyContain"]/div/div[4]/span[@class="value"]')

        def obj_job_name(self):
            job_name = Regexp(CleanText('//meta[@property="og:title"]/@content'),
                              '(.*)\|.*', default=None)(self)
            if job_name is None:
                job_name = JSVar(CleanText('//script'), var='_JobTitle')(self)
            return job_name

        obj_description = CleanHTML('//div[@class="VacancyDescription"]')

        def obj_url(self):
            url = CleanText('//meta[@property="og:url"]/@content', default=None)(self)
            if url is None:
                url = JSVar(CleanText('//script'), var='_JobUrl')(self)

            if not url.startswith('http'):
                url = 'www.adecco.fr%s' % url

            return url