diff --git a/modules/apec/browser.py b/modules/apec/browser.py index f9852793..cf4a9c4b 100644 --- a/modules/apec/browser.py +++ b/modules/apec/browser.py @@ -39,7 +39,9 @@ class ApecBrowser(PagesBrowser): json_ids = URL('/cms/webservices/rechercheOffre/ids', IdsPage) json_offre = URL('/cms/webservices/offre/public\?numeroOffre=(?P<_id>.*)', OffrePage) - def create_parameters(self, pattern='', fonctions='[]', lieux='[]', secteursActivite='[]', typesContrat='[]', typesConvention='[]', niveauxExperience='[]', salaire_min='', salaire_max='', date_publication='', start=0, range=20): + def create_parameters(self, pattern='', fonctions='[]', lieux='[]', secteursActivite='[]', typesContrat='[]', + typesConvention='[]', niveauxExperience='[]', salaire_min='', salaire_max='', + date_publication='', start=0, range=20): if date_publication: date_publication = ',"anciennetePublication":%s' % (date_publication) @@ -54,19 +56,23 @@ class ApecBrowser(PagesBrowser): def search_job(self, pattern=None): data = self.create_parameters(pattern=pattern) + return self.get_job_adverts(data, pattern=pattern) + + def get_job_adverts(self, data, pattern='', lieux='', fonctions='', secteursActivite='', salaire_min='', + salaire_max='', typesContrat='', date_publication='', niveauxExperience='', typesConvention=''): count = self.json_count.go(data=data).get_adverts_number() self.start = 0 if count: ids = self.json_ids.go(data=data).iter_job_adverts(pattern=pattern, - fonctions='[]', - lieux='[]', - secteursActivite='[]', - typesContrat='[]', - typesConvention='[]', - niveauxExperience='[]', - salaire_min='', - salaire_max='', - date_publication='', + fonctions='[%s]' % fonctions, + lieux='[%s]' % lieux, + secteursActivite='[%s]' % secteursActivite, + typesContrat='[%s]' % typesContrat, + niveauxExperience='[%s]' % niveauxExperience, + typesConvention='[%s]' % typesConvention, + salaire_min=salaire_min, + salaire_max=salaire_max, + date_publication=date_publication, start=self.start, count=count, range=20) @@ -94,20 +100,12 @@ class ApecBrowser(PagesBrowser): salaire_max=salaire_max, date_publication=limit_date) - count = self.json_count.go(data=data).get_adverts_number() - self.start - if count: - ids = self.json_ids.go(data=data).iter_job_adverts(pattern='', - fonctions='[%s]' % fonction, - lieux='[%s]' % region, - secteursActivite='[%s]' % secteur, - typesContrat='[%s]' % contrat, - niveauxExperience='[%s]' % level, - salaire_min=salaire_min, - salaire_max=salaire_max, - date_publication=limit_date, - start=self.start, - count=count, - range=20) - for _id in ids: - yield self.json_offre.go(_id=_id).get_job_advert() + return self.get_job_adverts(data, + fonctions=fonction, + lieux=region, + secteursActivite=secteur, + typesContrat=contrat, + niveauxExperience=level, + salaire_min=salaire_min, + salaire_max=salaire_max, + date_publication=limit_date) diff --git a/modules/apec/job.py b/modules/apec/job.py deleted file mode 100644 index 999d3986..00000000 --- a/modules/apec/job.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright(C) 2013 Bezleputh -# -# This file is part of weboob. -# -# weboob 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. -# -# weboob 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 weboob. If not, see . - -from weboob.capabilities.job import BaseJobAdvert - - -class ApecJobAdvert(BaseJobAdvert): - @classmethod - def id2url(cls, _id): - splitted_id = _id.split('/') - return 'http://cadres.apec.fr/offres-emploi-cadres/offres-emploi-cadres/0_0_0_%s________%s.html' % (splitted_id[0], splitted_id[1]) diff --git a/modules/apec/test.py b/modules/apec/test.py index 87e94b7a..835d3c35 100644 --- a/modules/apec/test.py +++ b/modules/apec/test.py @@ -19,19 +19,20 @@ from weboob.tools.test import BackendTest +import itertools class ApecTest(BackendTest): MODULE = 'apec' def test_apec_search(self): - l = list(self.backend.search_job(u'informaticien')) + l = list(itertools.islice(self.backend.search_job(u'informaticien'), 0, 50)) assert len(l) advert = self.backend.get_job_advert(l[0].id, None) self.assertTrue(advert.url, 'URL for announce "%s" not found: %s' % (advert.id, advert.url)) def test_apec_advanced_search(self): - l = list(self.backend.advanced_search_job()) + l = list(itertools.islice(self.backend.advanced_search_job(), 0, 50)) assert len(l) advert = self.backend.get_job_advert(l[0].id, None) self.assertTrue(advert.url, 'URL for announce "%s" not found: %s' % (advert.id, advert.url))