improve ls command in handjoob

This commit is contained in:
Bezleputh 2013-08-20 18:03:14 +02:00
commit b4c93587b4
10 changed files with 54 additions and 71 deletions

View file

@ -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:

View file

@ -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))

View file

@ -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:

View file

@ -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))

View file

@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
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:

View file

@ -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))

View file

@ -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:

View file

@ -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))

View file

@ -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:

View file

@ -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.