def build_feed(session, feed, final_url='', limit=None, stream=sys.stdout): items = session.query(model.FeedItem) \ .filter(model.FeedItem.feed_id==feed.id) \ .order_by(model.FeedItem.pubdate.desc()) \ .limit(min(limit, len(feed.items))).all() fg = FeedGenerator() fg.title(feed.name) fg.link(href=feed.url, rel='alternate') fg.image(feed.imgurl, feed.name, final_url) fg.description(feed.description) fg.link(href=final_url, rel='self') fg.language('en') fg.ttl(60) fg.generator('arxiv-decent-feeds') if not items: stream.write(fg.rss_str(pretty=True)) return for item in items: if not item.pubdate.tzinfo: # Add UTC to a naive datetime session.expunge(item) item.pubdate = pytz.utc.localize(item.pubdate) fe = fg.add_entry() fe.title(item.title) fe.link(href=item.link) fe.pubdate(item.pubdate) fe.description(item.summary) fe.guid(item.guid) stream.write(fg.rss_str(pretty=True))
def cache_rss_latest(user_slug): articles = data.userDocumentLastChanged_list(user_slug) netloc = bottle.request.urlparts.netloc fg = FeedGenerator() fg.id(abs_url(bottle.request, '/user/%s' % user_slug)) fg.title('Nigel Chapman (%s)' % netloc) fg.subtitle('Long reads on Christian thought') # <-- Set METADATA for this # fg.author( {'name':'Nigel Chapman','email':'*****@*****.**'} ) fg.logo('https://%s/static/site-image.png' % (netloc)) fg.link(href='https://%s' % netloc, rel='self') # fg.link(href='https://%s/rss/%s.xml' % (netloc, user_slug), rel='self') fg.language('en') fg.ttl(24 * 3600) for a in articles: fe = fg.add_entry() article_uri = 'read/%s/%s' % (a['user'], a['slug']) fe.id(abs_url(bottle.request, article_uri)) fe.title(a['title']) fe.description(a['summary']) fe.link(href=abs_url(bottle.request, article_uri)) fe.author(name=a['email'], email=a['author']) # <-- Wierdly backwards fe.published(a['published_time']) feed_xml = fg.rss_str(pretty=True) return feed_xml
def build_xml_feed(allchapters, verbose=True): if verbose: print print "Generating feeds..." if len(allchapters) == 0: raise CRMangaFeedException("Empty chapter list") crtz = pytz.timezone('America/New_York') fg = FeedGenerator() fg.id('http://utils.senpai.moe/') fg.title('Crunchyroll Manga - Latest Chapters (Unofficial)') fg.author({'name': 'Nosgoroth', 'email': '*****@*****.**'}) fg.link(href='http://utils.senpai.moe/') fg.subtitle( 'Latest manga chapters, updated daily, using undocumented API.') fg.language('en') fg.ttl(15) allchapters = sorted(allchapters, key=itemgetter('updated_t'), reverse=True) first = allchapters[0]["updated_t"].replace(tzinfo=crtz) fg.updated(first) fg.lastBuildDate(first) for chapter in allchapters[0:100]: fe = fg.add_entry() fe.id(chapter["url"]) fe.link({ "href": chapter["url"], "rel": "alternate", "title": "Read online" }) fe.title("%s - %s" % (chapter["series"], chapter["name"])) fe.summary("<p>%s has been added to %s in Crunchyroll Manga.</p>" % (chapter["name"], chapter["series"])) fe.published(chapter["updated_t"].replace(tzinfo=crtz)) chapter_serial = chapter.copy() chapter_serial.pop("updated_t", None) chapter_serial.pop("url", None) chapter_serial.pop("thumb", None) chapter_serial["chapter_id"] = chapter_serial["guid"] chapter_serial.pop("guid", None) content = "<p>%s has been added to %s in Crunchyroll Manga.</p><p>Updated: %s</p><img src=\"%s\" />" % ( chapter["name"], chapter["series"], chapter["updated"], chapter["thumb"]) content += "<!--JSON:[[%s]]-->" % json.dumps(chapter_serial) fe.content(content) fg.rss_file(os.path.join(DESTINATION_FOLDER, 'updates_rss.xml'), pretty=DEBUG) # Write the RSS feed to a file fg.atom_file(os.path.join(DESTINATION_FOLDER, 'updates_atom.xml'), pretty=DEBUG) # Write the ATOM feed to a file
def user_rss(service, id): cursor = get_cursor() query = "SELECT * FROM posts WHERE \"user\" = %s AND service = %s " params = (id, service) query += "ORDER BY added desc " query += "LIMIT 10" cursor.execute(query, params) results = cursor.fetchall() cursor3 = get_cursor() query3 = "SELECT * FROM lookup WHERE id = %s AND service = %s" params3 = (id, service) cursor3.execute(query3, params3) results3 = cursor.fetchall() name = results3[0]['name'] if len(results3) > 0 else '' fg = FeedGenerator() fg.title(name) fg.description('Feed for posts from ' + name + '.') fg.id(f'http://{request.headers.get("host")}/{service}/user/{id}') fg.link(href=f'http://{request.headers.get("host")}/{service}/user/{id}') fg.generator(generator='Kemono') fg.ttl(ttl=40) for post in results: fe = fg.add_entry() fe.title(post['title']) fe.id( f'http://{request.headers.get("host")}/{service}/user/{id}/post/{post["id"]}' ) fe.link( href= f'http://{request.headers.get("host")}/{service}/user/{id}/post/{post["id"]}' ) fe.content(content=post["content"]) fe.pubDate(pytz.utc.localize(post["added"])) response = make_response(fg.atom_str(pretty=True), 200) response.headers['Content-Type'] = 'application/rss+xml' return response
def generate_feed(input_file, output_file): fg = FeedGenerator() fg.load_extension('podcast', rss=True) ## RSS tags # Required fg.title(TITLE) fg.link(href=LINK) fg.description(DESCRIPTION) # Optional fg.language('en') fg.image(url=IMAGE_URL, title=TITLE, link=LINK) fg.ttl(720) fg.webMaster(CONTACT['name']) now = datetime.datetime.now() tz = pytz.timezone('Europe/Amsterdam') fg.pubDate(tz.localize(now)) # iTunes fg.podcast.itunes_author('Dan LeBatard') fg.podcast.itunes_category(itunes_category='Sports & Recreation', itunes_subcategory='Professional') fg.podcast.itunes_image(itunes_image=IMAGE_URL) fg.podcast.itunes_explicit(itunes_explicit='clean') fg.podcast.itunes_owner(name=CONTACT['name'], email=CONTACT['email']) # Add items items = read_items(input_file) for item in items: fe = fg.add_entry() ## RSS tags fe.id(item['guid']) fe.title(item['title']) fe.description(item['description']) fe.enclosure(item['link'], 0, 'audio/mpeg') fe.pubdate(item['pubDate']) # Finish off the file fg.rss_str(pretty=True) fg.rss_file(output_file)
def generate_feed(): tz = pytz.timezone(config.timezone) # Get latest X entries from database entries = dbhelper.get_latest_entries() fg = FeedGenerator() # Feed id fg.id(config.bot_link) # Creator info (for Atom) fg.author(name=config.author_name, email=config.author_email, replace=True) # Self link to the feed fg.link(href=config.feed_link, rel='self') # Set description of your feed fg.description(config.feed_description) # Last time feed updated (use system time with timezone) fg.lastBuildDate( formatdate(datetime.timestamp(datetime.now(tz)), localtime=True)) fg.title(config.feed_title) # Set time-to-live (I really don't know why set this) fg.ttl(5) # Does this parameter mean anything? fg.language(config.feed_language) for entry in entries: item = fg.add_entry() # Use message id to form valid URL (new feature in Telegram since Feb 2016) item.id("{!s}".format(entry["pid"])) item.link(href="{!s}/{!s}".format(config.bot_link, entry["pid"]), rel="alternate") # Set title and content from message text item.title(entry["ptext"]) item.content(entry["ptext"]) # Set publish/update datetime item.pubdate(entry["pdate"]) item.updated(entry["pdate"]) # Write RSS/Atom feed to file # It's preferred to have only one type at a time (or just create two functions) fg.atom_file('static/atom.xml')
def generate_feed(): tz = pytz.timezone(config.timezone) # Get latest X entries from database entries = dbhelper.get_latest_entries() fg = FeedGenerator() # Feed id fg.id(config.bot_link) # Creator info (for Atom) fg.author(name=config.author_name, email=config.author_email, replace=True ) # Self link to the feed fg.link(href=config.feed_link, rel='self') # Set description of your feed fg.description(config.feed_description) # Last time feed updated (use system time with timezone) fg.lastBuildDate(formatdate(datetime.timestamp(datetime.now(tz)), localtime=True)) fg.title(config.feed_title) # Set time-to-live (I really don't know why set this) fg.ttl(5) # Does this parameter mean anything? fg.language(config.feed_language) for entry in entries: item = fg.add_entry() # Use message id to form valid URL (new feature in Telegram since Feb 2016) item.id("{!s}".format(entry["pid"])) item.link(href="{!s}/{!s}".format(config.bot_link, entry["pid"]), rel="alternate") # Set title and content from message text item.title(entry["ptext"]) item.content(entry["ptext"]) # Set publish/update datetime item.pubdate(entry["pdate"]) item.updated(entry["pdate"]) # Write RSS/Atom feed to file # It's preferred to have only one type at a time (or just create two functions) fg.atom_file('static/atom.xml')
def setUp(self): fg = FeedGenerator() self.nsAtom = "http://www.w3.org/2005/Atom" self.nsRss = "http://purl.org/rss/1.0/modules/content/" self.feedId = 'http://lernfunk.de/media/654321' self.title = 'Some Testfeed' self.authorName = 'John Doe' self.authorMail = '*****@*****.**' self.author = {'name': self.authorName, 'email': self.authorMail} self.linkHref = 'http://example.com' self.linkRel = 'alternate' self.logo = 'http://ex.com/logo.jpg' self.subtitle = 'This is a cool feed!' self.link2Href = 'http://larskiesow.de/test.atom' self.link2Rel = 'self' self.language = 'en' self.categoryTerm = 'This category term' self.categoryScheme = 'This category scheme' self.categoryLabel = 'This category label' self.cloudDomain = 'example.com' self.cloudPort = '4711' self.cloudPath = '/ws/example' self.cloudRegisterProcedure = 'registerProcedure' self.cloudProtocol = 'SOAP 1.1' self.icon = "http://example.com/icon.png" self.contributor = { 'name': "Contributor Name", 'uri': "Contributor Uri", 'email': 'Contributor email' } self.copyright = "The copyright notice" self.docs = 'http://www.rssboard.org/rss-specification' self.managingEditor = '*****@*****.**' self.rating = '(PICS-1.1 "http://www.classify.org/safesurf/" ' + \ '1 r (SS~~000 1))' self.skipDays = 'Tuesday' self.skipHours = 23 self.textInputTitle = "Text input title" self.textInputDescription = "Text input description" self.textInputName = "Text input name" self.textInputLink = "Text input link" self.ttl = 900 self.webMaster = '*****@*****.**' fg.id(self.feedId) fg.title(self.title) fg.author(self.author) fg.link(href=self.linkHref, rel=self.linkRel) fg.logo(self.logo) fg.subtitle(self.subtitle) fg.link(href=self.link2Href, rel=self.link2Rel) fg.language(self.language) fg.cloud(domain=self.cloudDomain, port=self.cloudPort, path=self.cloudPath, registerProcedure=self.cloudRegisterProcedure, protocol=self.cloudProtocol) fg.icon(self.icon) fg.category(term=self.categoryTerm, scheme=self.categoryScheme, label=self.categoryLabel) fg.contributor(self.contributor) fg.copyright(self.copyright) fg.docs(docs=self.docs) fg.managingEditor(self.managingEditor) fg.rating(self.rating) fg.skipDays(self.skipDays) fg.skipHours(self.skipHours) fg.textInput(title=self.textInputTitle, description=self.textInputDescription, name=self.textInputName, link=self.textInputLink) fg.ttl(self.ttl) fg.webMaster(self.webMaster) fg.updated('2017-02-05 13:26:58+01:00') fg.pubDate('2017-02-05 13:26:58+01:00') fg.generator('python-feedgen', 'x', uri='http://github.com/lkie...') fg.image(url=self.logo, title=self.title, link=self.link2Href, width='123', height='123', description='Example Inage') self.fg = fg
def setUp(self): fg = FeedGenerator() self.nsAtom = "http://www.w3.org/2005/Atom" self.nsRss = "http://purl.org/rss/1.0/modules/content/" self.feedId = 'http://lernfunk.de/media/654321' self.title = 'Some Testfeed' self.authorName = 'John Doe' self.authorMail = '*****@*****.**' self.author = {'name': self.authorName, 'email': self.authorMail} self.linkHref = 'http://example.com' self.linkRel = 'alternate' self.logo = 'http://ex.com/logo.jpg' self.subtitle = 'This is a cool feed!' self.link2Href = 'http://larskiesow.de/test.atom' self.link2Rel = 'self' self.language = 'en' self.categoryTerm = 'This category term' self.categoryScheme = 'This category scheme' self.categoryLabel = 'This category label' self.cloudDomain = 'example.com' self.cloudPort = '4711' self.cloudPath = '/ws/example' self.cloudRegisterProcedure = 'registerProcedure' self.cloudProtocol = 'SOAP 1.1' self.icon = "http://example.com/icon.png" self.contributor = {'name': "Contributor Name", 'uri': "Contributor Uri", 'email': 'Contributor email'} self.copyright = "The copyright notice" self.docs = 'http://www.rssboard.org/rss-specification' self.managingEditor = '*****@*****.**' self.rating = '(PICS-1.1 "http://www.classify.org/safesurf/" ' + \ '1 r (SS~~000 1))' self.skipDays = 'Tuesday' self.skipHours = 23 self.textInputTitle = "Text input title" self.textInputDescription = "Text input description" self.textInputName = "Text input name" self.textInputLink = "Text input link" self.ttl = 900 self.webMaster = '*****@*****.**' fg.id(self.feedId) fg.title(self.title) fg.author(self.author) fg.link(href=self.linkHref, rel=self.linkRel) fg.logo(self.logo) fg.subtitle(self.subtitle) fg.link(href=self.link2Href, rel=self.link2Rel) fg.language(self.language) fg.cloud(domain=self.cloudDomain, port=self.cloudPort, path=self.cloudPath, registerProcedure=self.cloudRegisterProcedure, protocol=self.cloudProtocol) fg.icon(self.icon) fg.category(term=self.categoryTerm, scheme=self.categoryScheme, label=self.categoryLabel) fg.contributor(self.contributor) fg.copyright(self.copyright) fg.docs(docs=self.docs) fg.managingEditor(self.managingEditor) fg.rating(self.rating) fg.skipDays(self.skipDays) fg.skipHours(self.skipHours) fg.textInput(title=self.textInputTitle, description=self.textInputDescription, name=self.textInputName, link=self.textInputLink) fg.ttl(self.ttl) fg.webMaster(self.webMaster) fg.updated('2017-02-05 13:26:58+01:00') fg.pubDate('2017-02-05 13:26:58+01:00') fg.generator('python-feedgen', 'x', uri='http://github.com/lkie...') fg.image(url=self.logo, title=self.title, link=self.link2Href, width='123', height='123', description='Example Inage') self.fg = fg