Exemplo n.º 1
0
    def _push_job_offers_to_twitter(self, num_tweets_to_push):
        # Do not push every job offer at once. The Twitter API won't allow it.
        # We thus push them num_offers_to_push at a time.
        if num_tweets_to_push > self.MAX_TWEETS_TO_PUSH:
            err_msg = 'Cannot push %s tweets at once, pushing %s tweets ' \
                      'instead.' % (num_tweets_to_push, self.MAX_TWEETS_TO_PUSH)
            self._logging(logging.WARNING, err_msg)

            num_tweets_to_push = self.MAX_TWEETS_TO_PUSH

        self._logging(logging.INFO, 'Acquiring unpublished job offers.')
        to_push = JobAlchemy.get_not_pushed_on_twitter(num_tweets_to_push)

        for job_offer in to_push:
            tweet = self._format_tweet(job_offer.id, job_offer.title)

            try:
                self._logging(logging.INFO, 'Publishing to Twitter.')
                self._twitter_api.PostUpdate(tweet)
            except twitter.TwitterError as exc:
                err_msg = '[Job offer id: %s] The following error: %s, ' \
                          'occurred while pushing the following tweet: %s.' \
                          % (job_offer.id, exc.message, tweet)
                self._logging(logging.WARNING, err_msg)
            except Exception as exc:
                err_msg = '[Job offer id: %s] An unhandled error: %s, ' \
                          'occurred while pushing the following tweet: %s.' \
                          % (job_offer.id, exc, tweet)
                self._logging(logging.ERROR, err_msg)
            else:
                # The tweet has been pushed successfully. Mark the job offer as
                # pushed on Twitter in the Postgresql database, so we don't push
                # it again on Twitter later on.
                self._logging(logging.INFO, 'Marking as published on Twitter.')
                JobAlchemy.set_pushed_on_twitter(job_offer.id, True)
Exemplo n.º 2
0
    def _push_job_offers_to_twitter(self, num_tweets_to_push):
        # Do not push every job offer at once. The Twitter API won't allow it.
        # We thus push them num_offers_to_push at a time.
        if num_tweets_to_push > self.MAX_TWEETS_TO_PUSH:
            err_msg = 'Cannot push %s tweets at once, pushing %s tweets ' \
                      'instead.' % (num_tweets_to_push, self.MAX_TWEETS_TO_PUSH)
            self._logging(logging.WARNING, err_msg)

            num_tweets_to_push = self.MAX_TWEETS_TO_PUSH

        self._logging(logging.INFO, 'Acquiring unpublished job offers.')
        to_push = JobAlchemy.get_not_pushed_on_twitter(num_tweets_to_push)

        for job_offer in to_push:
            tweet = self._format_tweet(job_offer.id, job_offer.title)

            try:
                self._logging(logging.INFO, 'Publishing to Twitter.')
                self._twitter_api.PostUpdate(tweet)
            except twitter.TwitterError as exc:
                err_msg = '[Job offer id: %s] The following error: %s, ' \
                          'occurred while pushing the following tweet: %s.' \
                          % (job_offer.id, exc.message, tweet)
                self._logging(logging.WARNING, err_msg)
            except Exception as exc:
                err_msg = '[Job offer id: %s] An unhandled error: %s, ' \
                          'occurred while pushing the following tweet: %s.' \
                          % (job_offer.id, exc, tweet)
                self._logging(logging.ERROR, err_msg)
            else:
                # The tweet has been pushed successfully. Mark the job offer as
                # pushed on Twitter in the Postgresql database, so we don't push
                # it again on Twitter later on.
                self._logging(logging.INFO, 'Marking as published on Twitter.')
                JobAlchemy.set_pushed_on_twitter(job_offer.id, True)
Exemplo n.º 3
0
    def index(self, *args, **kwargs):
        try:
            job_offers = JobAlchemy.get_all_job_offers()
        except NoResultFound:
            job_offers = None

        return dict(sources=SOURCES, jobs=job_offers,
                    job_offer_search_form=JobsResearchForm)
Exemplo n.º 4
0
    def index(self, *args, **kwargs):
        try:
            job_offers = JobAlchemy.get_all_job_offers()
        except NoResultFound:
            job_offers = None

        return dict(sources=SOURCES,
                    jobs=job_offers,
                    job_offer_search_form=JobsResearchForm)
Exemplo n.º 5
0
 def details(self, offer_id, *args, **kwargs):
     try:
         job = JobAlchemy.get_job_offer(offer_id)
     except NoResultFound:
         raise HTTPNotFound()
     except Exception as exc:
         logging.getLogger(__name__).log(logging.ERROR, exc)
         raise HTTPNotFound()
     else:
         return dict(job=job, sources=SOURCES)
Exemplo n.º 6
0
 def details(self, offer_id, *args, **kwargs):
     try:
         job = JobAlchemy.get_job_offer(offer_id)
     except NoResultFound:
         raise HTTPNotFound()
     except Exception as exc:
         logging.getLogger(__name__).log(logging.ERROR, exc)
         raise HTTPNotFound()
     else:
         return dict(
             job=job,
             sources=SOURCES
         )