diff --git a/modules/adecco/backend.py b/modules/adecco/backend.py index a1176d04..f23e7011 100644 --- a/modules/adecco/backend.py +++ b/modules/adecco/backend.py @@ -19,7 +19,6 @@ from weboob.tools.backend import BaseBackend, BackendConfig -from weboob.capabilities.collection import ICapCollection, CollectionNotFound from weboob.tools.ordereddict import OrderedDict from weboob.tools.value import Value from weboob.capabilities.job import ICapJob @@ -29,7 +28,7 @@ from .job import AdeccoJobAdvert __all__ = ['AdeccoBackend'] -class AdeccoBackend(BaseBackend, ICapJob, ICapCollection): +class AdeccoBackend(BaseBackend, ICapJob): NAME = 'adecco' DESCRIPTION = u'adecco website' MAINTAINER = u'Bezleputh' @@ -284,22 +283,14 @@ class AdeccoBackend(BaseBackend, ICapJob, ICapCollection): for advert in self.browser.search_job(pattern): yield advert - def iter_resources(self, objs, split_path): - with self.browser: - collection = self.get_collection(objs, split_path) - if collection.path_level == 0: - for advert in self.browser.advanced_search_job(publication_date=int(self.config['publication_date'].get()), - conty=int(self.config['conty'].get()), - region=int(self.config['region'].get()), - job_category=int(self.config['job_category'].get()), - activity_domain=int(self.config['activity_domain'].get()) - ): - yield advert - - def validate_collection(self, objs, collection): - if collection.path_level == 0: - return - raise CollectionNotFound(collection.split_path) + def advanced_search_job(self): + for advert in self.browser.advanced_search_job(publication_date=int(self.config['publication_date'].get()), + conty=int(self.config['conty'].get()), + region=int(self.config['region'].get()), + job_category=int(self.config['job_category'].get()), + activity_domain=int(self.config['activity_domain'].get()) + ): + yield advert def get_job_advert(self, _id, advert=None): with self.browser: diff --git a/modules/adecco/test.py b/modules/adecco/test.py index 6f721b5f..9a4a7efe 100644 --- a/modules/adecco/test.py +++ b/modules/adecco/test.py @@ -31,7 +31,7 @@ class AdeccoTest(BackendTest): self.assertTrue(advert.url, 'URL for announce "%s" not found: %s' % (advert.id, advert.url)) def test_adecco_advanced_search(self): - l = list(self.backend.iter_resources([], [])) + l = list(self.backend.advanced_search_job()) 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)) diff --git a/modules/apec/backend.py b/modules/apec/backend.py index c07943e5..7c728b8b 100644 --- a/modules/apec/backend.py +++ b/modules/apec/backend.py @@ -19,7 +19,6 @@ from weboob.tools.backend import BaseBackend, BackendConfig -from weboob.capabilities.collection import ICapCollection, CollectionNotFound from weboob.capabilities.job import ICapJob from weboob.tools.ordereddict import OrderedDict from weboob.tools.value import Value @@ -29,7 +28,7 @@ from .job import ApecJobAdvert __all__ = ['ApecBackend'] -class ApecBackend(BaseBackend, ICapJob, ICapCollection): +class ApecBackend(BaseBackend, ICapJob): NAME = 'apec' DESCRIPTION = u'apec website' MAINTAINER = u'Bezleputh' @@ -233,23 +232,15 @@ class ApecBackend(BaseBackend, ICapJob, ICapCollection): for job_advert in self.browser.search_job(pattern=pattern): yield job_advert - def iter_resources(self, objs, split_path): - with self.browser: - collection = self.get_collection(objs, split_path) - if collection.path_level == 0: - for job_advert in self.browser.advanced_search_job(region=self.config['place'].get(), - fonction=self.config['fonction'].get(), - secteur=self.config['secteur'].get(), - salaire=self.config['salaire'].get(), - contrat=self.config['contrat'].get(), - limit_date=self.config['limit_date'].get(), - level=self.config['level'].get()): - yield job_advert - - def validate_collection(self, objs, collection): - if collection.path_level == 0: - return - raise CollectionNotFound(collection.split_path) + def advanced_search_job(self): + for job_advert in self.browser.advanced_search_job(region=self.config['place'].get(), + fonction=self.config['fonction'].get(), + secteur=self.config['secteur'].get(), + salaire=self.config['salaire'].get(), + contrat=self.config['contrat'].get(), + limit_date=self.config['limit_date'].get(), + level=self.config['level'].get()): + yield job_advert def get_job_advert(self, _id, advert=None): with self.browser: diff --git a/modules/apec/test.py b/modules/apec/test.py index 6a66c338..7bc5a59d 100644 --- a/modules/apec/test.py +++ b/modules/apec/test.py @@ -31,7 +31,7 @@ class ApecTest(BackendTest): 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.iter_resources([], [])) + l = list(self.backend.advanced_search_job()) 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)) diff --git a/modules/lolix/backend.py b/modules/lolix/backend.py index b14ec3e5..a5c6d2b3 100644 --- a/modules/lolix/backend.py +++ b/modules/lolix/backend.py @@ -18,7 +18,6 @@ # along with weboob. If not, see . from weboob.tools.backend import BaseBackend, BackendConfig -from weboob.capabilities.collection import ICapCollection, CollectionNotFound from weboob.tools.ordereddict import OrderedDict from weboob.tools.value import Value from weboob.capabilities.job import ICapJob @@ -29,7 +28,7 @@ from .job import LolixJobAdvert __all__ = ['LolixBackend'] -class LolixBackend(BaseBackend, ICapJob, ICapCollection): +class LolixBackend(BaseBackend, ICapJob): NAME = 'lolix' DESCRIPTION = u'Lolix French free software employment website' MAINTAINER = u'Bezleputh' @@ -138,20 +137,12 @@ class LolixBackend(BaseBackend, ICapJob, ICapCollection): Value('contrat', label=u'Contrat', choices=contrat_choices), Value('limit_date', label=u'Date limite', choices=limit_date_choices)) - def iter_resources(self, objs, split_path): - with self.browser: - collection = self.get_collection(objs, split_path) - if collection.path_level == 0: - for advert in self.browser.advanced_search_job(region=self.config['region'].get(), - poste=self.config['poste'].get(), - contrat=int(self.config['contrat'].get()), - limit_date=self.config['limit_date'].get()): - yield advert - - def validate_collection(self, objs, collection): - if collection.path_level == 0: - return - raise CollectionNotFound(collection.split_path) + def advanced_search_job(self): + for advert in self.browser.advanced_search_job(region=self.config['region'].get(), + poste=self.config['poste'].get(), + contrat=int(self.config['contrat'].get()), + limit_date=self.config['limit_date'].get()): + yield advert def get_job_advert(self, _id, advert=None): with self.browser: diff --git a/modules/lolix/test.py b/modules/lolix/test.py index d866b11c..ff75d0ab 100644 --- a/modules/lolix/test.py +++ b/modules/lolix/test.py @@ -25,7 +25,7 @@ class LolixTest(BackendTest): BACKEND = 'lolix' def test_lolix_advanced_search(self): - l = list(self.backend.iter_resources([], [])) + l = list(self.backend.advanced_search_job()) assert len(l) advert = self.backend.get_job_advert(l[0].id, l[0]) self.assertTrue(advert.url, 'URL for announce "%s" not found: %s' % (advert.id, advert.url)) diff --git a/modules/popolemploi/backend.py b/modules/popolemploi/backend.py index 87b590f4..57349790 100644 --- a/modules/popolemploi/backend.py +++ b/modules/popolemploi/backend.py @@ -19,7 +19,6 @@ from weboob.tools.backend import BaseBackend, BackendConfig -from weboob.capabilities.collection import ICapCollection, CollectionNotFound from weboob.capabilities.job import ICapJob from weboob.tools.value import Value from weboob.tools.ordereddict import OrderedDict @@ -30,7 +29,7 @@ from .job import PopolemploiJobAdvert __all__ = ['PopolemploiBackend'] -class PopolemploiBackend(BaseBackend, ICapJob, ICapCollection): +class PopolemploiBackend(BaseBackend, ICapJob): NAME = 'popolemploi' DESCRIPTION = u'Pole Emploi website' MAINTAINER = u'Bezleputh' @@ -205,18 +204,10 @@ class PopolemploiBackend(BaseBackend, ICapJob, ICapCollection): with self.browser: return self.browser.search_job(pattern=pattern) - def iter_resources(self, objs, split_path): - with self.browser: - collection = self.get_collection(objs, split_path) - if collection.path_level == 0: - return self.browser.advanced_search_job(metier=self.config['metier'].get(), - place=self.config['place'].get(), - contrat=self.config['contrat'].get()) - - def validate_collection(self, objs, collection): - if collection.path_level == 0: - return - raise CollectionNotFound(collection.split_path) + def advanced_search_job(self): + return self.browser.advanced_search_job(metier=self.config['metier'].get(), + place=self.config['place'].get(), + contrat=self.config['contrat'].get()) def get_job_advert(self, _id, advert=None): with self.browser: diff --git a/modules/popolemploi/test.py b/modules/popolemploi/test.py index 7d1b62c3..4c16a778 100644 --- a/modules/popolemploi/test.py +++ b/modules/popolemploi/test.py @@ -31,7 +31,7 @@ class PopolemploiTest(BackendTest): self.assertTrue(advert.url, 'URL for announce "%s" not found: %s' % (advert.id, advert.url)) def test_popolemploi_advanced_search(self): - l = list(self.backend.iter_resources([], [])) + l = list(self.backend.advanced_search_job()) assert len(l) advert = self.backend.get_job_advert(l[0].id, l[0]) self.assertTrue(advert.url, 'URL for announce "%s" not found: %s' % (advert.id, advert.url)) diff --git a/weboob/applications/handjoob/handjoob.py b/weboob/applications/handjoob/handjoob.py index 5008d1f9..e5f25261 100644 --- a/weboob/applications/handjoob/handjoob.py +++ b/weboob/applications/handjoob/handjoob.py @@ -84,6 +84,7 @@ class Handjoob(ReplApplication): 'job_advert': JobAdvertFormatter, } COMMANDS_FORMATTERS = {'search': 'job_advert_list', + 'ls': 'job_advert_list', 'info': 'job_advert', } @@ -99,6 +100,17 @@ class Handjoob(ReplApplication): for backend, job_advert in self.do('search_job', pattern): self.cached_format(job_advert) + @defaultcount(10) + def do_ls(self, line): + """ + advanced search + + Search for an advert matching to advanced filters. + """ + self.change_path([u'advanced']) + for backend, job_advert in self.do('advanced_search_job'): + self.cached_format(job_advert) + def complete_info(self, text, line, *ignored): args = line.split(' ') if len(args) == 2: diff --git a/weboob/capabilities/job.py b/weboob/capabilities/job.py index 53e5de78..9ae85458 100644 --- a/weboob/capabilities/job.py +++ b/weboob/capabilities/job.py @@ -81,6 +81,13 @@ class ICapJob(IBaseCap): """ raise NotImplementedError() + def advanced_search_job(self): + """ + Iter results of an advanced search + + :rtype: iter[:class:`BaseJobAdvert`] + """ + def get_job_advert(self, _id, advert=None): """ Get an announce from an ID.