def _format_tweet(self, job_id, job_title): self._logging(logging.INFO, 'Formatting tweet.') # The Twitter API automatically shrinks URLs to 23 characters url = get_job_url(job_id, job_title, absolute=True) job_title = job_title.lower() for hashword in (u'devops', u'développeur', u'développeuse', u'startup', u'cdd', u'cdi', u'stage', u'sysadmin', u'django', u'flask', u'python') : job_title = job_title.replace(hashword, u'#%s' % hashword) job_title = job_title.replace(u'adminsys', u'#sysadmin') job_title = job_title.replace(u'administrateur système', u'#sysadmin') job_title = job_title.replace(u'administrateur', u'#sysadmin') job_title = job_title.replace(u'start-up', u'#startup') job_title = job_title.replace(u'data science', u'#DataScience') job_title = job_title.replace(u'data scientist', u'#datascientists') for hashword in (u'nantes', u'lyon', u'paris', u'grenoble', u'toulouse', u'bordeaux', u'marseille', u'lille', u'rennes', u'strasbourg') : job_title = job_title.replace(hashword, u'#%s' % hashword) # Tweet format string tweet_format = u'Recrutement %s %s #emploi' # The number of punctuation characters in the tweet string format punctuation = len(tweet_format.replace(u'%s', u'')) total_length = len(job_title) + self.MAX_URL_LENGTH + punctuation # Make sure our tweet doesn't exceed max_length if total_length > self.MAX_TWEET_LENGTH: diff = total_length - self.MAX_TWEET_LENGTH job_title = job_title[:-diff] # Return the formatted tweet return tweet_format % (job_title, url)
def rss(self, limit=50, source=None, *args, **kwargs): """ RSS feed of jobs :param source: source name :param limit: number of displayed jobs :return: RSS feed content """ site_url = config.get('site.domain_base_url') feed = feedgenerator.Rss201rev2Feed( title=u"pyjobs : le job qu'il vous faut en python", link=site_url, description=u"Agrégation de jobs python", language=u"fr", feed_url=u"http://www.pyjobs.fr/rss?limit=%s" % limit) jobs = DBSession.query(model.JobAlchemy) \ .order_by(model.JobAlchemy.publication_datetime.desc()) \ .limit(limit) if source is not None: jobs = jobs.filter(model.JobAlchemy.source == source) for job in jobs: job_slug = slugify(job.title) feed.add_item(title=job.title, link=get_job_url(job.id, job_title=job.title, absolute=True), description=job.description, pubdate=job.publication_datetime, unique_id="%s/job/%d/%s" % (site_url, job.id, job_slug)) return feed.writeString('utf-8')
def rss(self, limit=50, source=None, *args, **kwargs): """ RSS feed of jobs :param source: source name :param limit: number of displayed jobs :return: RSS feed content """ site_url = config.get('site.domain_base_url') feed = feedgenerator.Rss201rev2Feed( title=u"pyjobs : le job qu'il vous faut en python", link=site_url, description=u"Agrégation de jobs python", language=u"fr", feed_url=u"http://www.pyjobs.fr/rss?limit=%s" % limit ) jobs = DBSession.query(model.JobAlchemy) \ .order_by(model.JobAlchemy.publication_datetime.desc()) \ .limit(limit) if source is not None: jobs = jobs.filter(model.JobAlchemy.source == source) for job in jobs: job_slug = slugify(job.title) feed.add_item( title=job.title, link=get_job_url(job.id, job_title=job.title, absolute=True), description=job.description, pubdate=job.publication_datetime, unique_id="%s/job/%d/%s" % (site_url, job.id, job_slug) ) return feed.writeString('utf-8')
def _get_new_jobs(self, jobs): """ :param jobs: job to parse :return: jobs not listed in jobs file """ cleaned_jobs = [] with codecs.open(self._jobs_file_path, 'r', 'utf-8') as jobs_file: jobs_file_read = jobs_file.read() for job in jobs: pyjobs_url = get_job_url(job.id, job.title, absolute=True) if pyjobs_url not in jobs_file_read: cleaned_jobs.append(job) return cleaned_jobs
def _format_tweet(self, job_id, job_title): self._logging(logging.INFO, 'Formatting tweet.') # The Twitter API automatically shrinks URLs to 23 characters url = get_job_url(job_id, job_title, absolute=True) # Tweet format string tweet_format = u'%s. %s' # The number of punctuation characters in the tweet string format punctuation = len(tweet_format.replace(u'%s', u'')) total_length = len(job_title) + self.MAX_URL_LENGTH + punctuation # Make sure our tweet doesn't exceed max_length if total_length > self.MAX_TWEET_LENGTH: diff = total_length - self.MAX_TWEET_LENGTH job_title = job_title[:-diff] # Return the formatted tweet return tweet_format % (job_title, url)