def get(self,tag): contents = self.get_contents(tag) if current_app.config.get("PAGINATION_ENABLED",True): contents = contents.items feed_name = u"{0} | {1} | feed".format( Config.get('site','site_name',''), "Tag {0}".format(tag) ) feed = self.make_atom(feed_name,contents) return feed.get_response()
def get(self, tag): contents = self.get_contents(tag) self.channel = None if current_app.config.get('PAGINATION_ENABLED', True): contents = contents.items feed_name = u"{0} | {1} | feed".format( Config.get('site', 'site_name', ''), "Tag {0}".format(tag) ) return self.make_rss(feed_name, contents)
def get(self,long_slug): contents = self.get_contents(long_slug) self.tag = None if current_app.config.get("PAGINATION_ENABLED",True): contents = contents.items feed_name = u"{0} | {1} | feed".format( Config.get('site', 'site_name', ''), self.channel.title ) return self.make_rss(feed_name, contents)
def make_rss(self,feed_name,contents): conf = current_app.config if not self.channel: description = 'Articles with tag:' + self.tag categories = [self.tag] else: description = self.channel.get_text() categories = self.channel.tags rss = pyrss.RSS2( title=feed_name, link=request.url_root, description=description, language=conf.get('RSS_LANGUAGE','en-us'), copyright=conf.get('RSS_COPYRIGHT','All rights reserved.'), lastBuildDate=datetime.now(), categories=categories, ) rss_pubdate = datetime.today() - timedelta(days=365 * 10) for content in contents: if not content.channel.include_in_rss: continue if content.created_at > rss_pubdate: rss_pubdate = content.created_at if content.created_by: author = content.created_by.name else: author = Config.get('site','site_author','') rss.items.append( pyrss.RSSItem( title=content.title, link=content.get_absolute_url(), description=content.get_text(), author=author, categories=content.tags, guid=hashlib.sha1( content.title + content.get_absolute_url() ).hexdigest(), pubDate=content.created_at, ) ) rss.pubDate = rss_pubdate return rss.to_xml(encoding=conf.get('RSS_ENCODING','utf-8'))
def make_atom(self,feed_name,contents): feed = AtomFeed( feed_name, feed_url=request.url, url=request.url_root ) for content in contents: if not content.channel.include_in_rss: continue if content.created_by: author = content.created_by.name else: author = Config.get('site','site_author','') feed.add( content.title, cdata(content.get_text()), content_type="html", author=author, url=self.make_external_url(content.get_absolute_url()), updated=content.updated_at, published=content.created_at ) return feed