From 48f0054e91a70e6709e6a4b8df86bb191b9e8a03 Mon Sep 17 00:00:00 2001 From: Bezleputh Date: Wed, 3 Jul 2013 13:14:28 +0200 Subject: [PATCH] creation de l'appli console handjoob --- scripts/handjoob | 26 +++++ weboob/applications/handjoob/__init__.py | 3 + weboob/applications/handjoob/handjoob.py | 143 +++++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100755 scripts/handjoob create mode 100644 weboob/applications/handjoob/__init__.py create mode 100644 weboob/applications/handjoob/handjoob.py diff --git a/scripts/handjoob b/scripts/handjoob new file mode 100755 index 0000000000..ed40b3d7da --- /dev/null +++ b/scripts/handjoob @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright(C) 2012 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.applications.handjoob import Handjoob + + +if __name__ == '__main__': + Handjoob.run() diff --git a/weboob/applications/handjoob/__init__.py b/weboob/applications/handjoob/__init__.py new file mode 100644 index 0000000000..b225e6db34 --- /dev/null +++ b/weboob/applications/handjoob/__init__.py @@ -0,0 +1,3 @@ +from .handjoob import Handjoob + +__all__ = ['Handjoob'] diff --git a/weboob/applications/handjoob/handjoob.py b/weboob/applications/handjoob/handjoob.py new file mode 100644 index 0000000000..c279d7591f --- /dev/null +++ b/weboob/applications/handjoob/handjoob.py @@ -0,0 +1,143 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2012 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 . + +import sys + +from weboob.capabilities.job import ICapJob +from weboob.tools.application.repl import ReplApplication +from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter + +__all__ = ['Handjoob'] + + +class JobAdvertFormatter(IFormatter): + + MANDATORY_FIELDS = ('id', 'url', 'publication_date', 'title') + + def format_obj(self, obj, alias): + result = u'%s%s%s\n' % (self.BOLD, obj.title, self.NC) + result += 'url: %s\n' % obj.url + if hasattr(obj, 'publication_date') and obj.publication_date: + result += 'Publication date : %s\n' % obj.publication_date.strftime('%Y-%m-%d') + if hasattr(obj, 'place') and obj.place: + result += 'Location: %s\n' % obj.place + if hasattr(obj, 'society_name') and obj.society_name: + result += 'Society : %s\n' % obj.society_name + if hasattr(obj, 'job_name') and obj.job_name: + result += 'Job name : %s\n' % obj.job_name + if hasattr(obj, 'contract_type') and obj.contract_type: + result += 'Contract : %s\n' % obj.contract_type + if hasattr(obj, 'pay') and obj.pay: + result += 'Pay : %s\n' % obj.pay + if hasattr(obj, 'formation') and obj.formation: + result += 'Formation : %s\n' % obj.formation + if hasattr(obj, 'experience') and obj.experience: + result += 'Experience : %s\n' % obj.experience + if hasattr(obj, 'description') and obj.description: + result += 'Description : %s\n' % obj.description + return result + + +class JobAdvertListFormatter(PrettyFormatter): + MANDATORY_FIELDS = ('id', 'title') + """ + def format_obj(self, obj, alias): + title = self.get_title(obj) + desc = self.get_description(obj) + + if desc is None: + title = '%s%s%s' % (self.NC, title, self.BOLD) + + result = u'%s* (%s)\n %s%s' % (self.BOLD, obj.fullid, title, self.NC) + + if desc is not None: + result += u'\n\t%s' % desc + + return result + """ + def get_title(self, obj): + return '%s' % (obj.title) + + def get_description(self, obj): + result = u'' + if hasattr(obj, 'publication_date') and obj.publication_date: + result += 'Publication date : %s\n' % obj.publication_date.strftime('%Y-%m-%d') + if hasattr(obj, 'place') and obj.place: + result += '\tLocation: %s\n' % obj.place + if hasattr(obj, 'society_name') and obj.society_name: + result += '\tSociety : %s\n' % obj.society_name + if hasattr(obj, 'contract_type') and obj.contract_type: + result += '\tContract : %s\n' + return result + + +class Handjoob(ReplApplication): + APPNAME = 'handjoob' + VERSION = '0.g' + COPYRIGHT = 'Copyright(C) 2012 Bezleputh' + DESCRIPTION = "Console application to search for a job." + SHORT_DESCRIPTION = "search for a job" + CAPS = ICapJob + EXTRA_FORMATTERS = {'job_advert_list': JobAdvertListFormatter, + 'job_advert': JobAdvertFormatter, + } + COMMANDS_FORMATTERS = {'search': 'job_advert_list', + 'info': 'job_advert', + } + + def main(self, argv): + self.load_config() + return ReplApplication.main(self, argv) + + def do_search(self, pattern): + """ + search PATTERN + + Search for an advert matching a PATTERN. + """ + self.change_path([u'search']) + self.start_format(pattern=pattern) + for backend, job_advert in self.do('search_job', pattern): + self.cached_format(job_advert) + self.flush() + + def complete_info(self, text, line, *ignored): + args = line.split(' ') + if len(args) == 2: + return self._complete_object() + + def do_info(self, _id): + """ + info ID + + Get information about an advert. + """ + if not _id: + print >>sys.stderr, 'This command takes an argument: %s' % self.get_command_help('info', short=True) + return 2 + + job_advert = self.get_object(_id, 'get_job_advert') + + if not job_advert: + print >>sys.stderr, 'Job advert not found: %s' % _id + return 3 + + self.start_format() + self.format(job_advert) + self.flush() -- GitLab