def atom_list_response(items, title, path, author): feed = Feed() feed.feed["title"] = title feed.feed["link"] = get_domain() + path feed.feed["author"] = author for msg in items: item = {} item[ "title"] = "message from " + msg.user + " on " + msg.created.isoformat( ) item["link"] = get_domain() + "/m/" + str(msg.key()) item["description"] = msg.text item["pubDate"] = msg.created.timetuple() item["guid"] = str(msg.key()) item["author"] = msg.user item["category"] = ["#" + val for val in msg.tags] item["category"] += ["@" + val for val in msg.mentions] feed.items.append(item) body = feed.format_atom_string() return flask.Response(body, 200, mimetype="application/atom+xml")
def feed(request): forum_name = request.matchdict.get('forum_name', None) if forum_name: forum = models.Forum.objects(name__iexact=forum_name).first() topics = models.Topic.objects(status='publish', tags__in=forum.tags).order_by("-published_date").limit(10) else: topics = models.Topic.objects(status='publish').order_by("-published_date").limit(10) # Create the feed feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "Pumbaa feed" feed.feed["link"] = request.current_route_url() feed.feed["author"] = {'name' : "pumbaa"} feed.feed["description"] = "Pumbaa feed" feed.feed["update"] = datetime.datetime.now() for topic in topics: # Create an item item = {} item['title'] = topic.title item['link'] = request.route_url('forums.topics.view', topic_id=topic.id, title=topic.title) item['description'] = topic.description item['pubDate'] = topic.published_date item['guid'] = request.route_url('forums.topics.view', topic_id=topic.id, title=topic.title) item['category'] = ", ".join(topic.tags) item['author'] = {'name' : topic.author.username} # Add item to feed feed.items.append(item) return Response(feed.format_atom_string())
def get(self): feed = Feed() blog_name = self.request.get('blog_name') blog = Blog.query(Blog.name == blog_name).fetch() posts = Post.query(Post.blog_key == blog_key(blog_name)).order( -Post.edit_time).fetch() feed.feed['title'] = "Rss blog feed" feed.feed[ 'link'] = "http://blogger-kcl.appspot.com/?blog_name=" + blog[ 0].name feed.feed['author'] = blog[0].authors[0] feed.feed[ 'description'] = "This is a simple feed of blog " + blog[0].name feed.feed['guid'] = "123456789" feed.feed['blog_name'] = blog[0].name feed.feed['imgs_url'] = ['url1', 'url2', 'url3'] for post in posts: item = {} item['guid'] = str(post.blog_key.urlsafe()) item['title'] = post.title item['link'] = "http://blogger-kcl.appspot.com/?blog_name=" + blog[ 0].name + "&post_id=" + str(post.key.id()) item['description'] = post.content item['imgs_url'] = post.imgs_url item['pubDate'] = time.mktime(post.create_time.timetuple()) feed.items.append(item) rss = JINJA_ENVIRONMENT.get_template('rss.html') self.response.write(rss.render({'rssstr': feed.format_rss2_string()}))
def construct_rss(channel_name, vods_info, display_name, add_live=True): feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "%s's Twitch video RSS" % display_name feed.feed["link"] = "https://twitchrss.appspot.com/" feed.feed["author"] = "Twitch RSS Generated" feed.feed[ "description"] = "The RSS Feed of %s's videos on Twitch" % display_name feed.feed["ttl"] = '10' # Create an item try: if vods_info: for vod in vods_info: item = {} # It seems if the thumbnail is empty then we are live? # Tempted to go in and fix it for them since the source is leaked.. if vod["thumbnail_url"] == '': if not add_live: continue link = "https://www.twitch.tv/%s" % channel_name item["title"] = "%s - LIVE" % vod['title'] item["category"] = "live" item["description"] = "<a href=\"%s\">LIVE LINK</a>" % link else: link = vod['url'] item["title"] = vod['title'] item["category"] = vod['type'] item[ "description"] = "<a href=\"%s\"><img src=\"%s\" /></a>" % ( link, vod['thumbnail_url'].replace( "%{width}", "512").replace("%{height}", "288")) item["link"] = link #@madiele: for some reason the new API does not have the game field anymore... #if vod.get('game'): # item["description"] += "<br/>" + vod['game'] if vod.get('description'): item["description"] += "<br/>" + vod['description'] d = datetime.datetime.strptime(vod['created_at'], '%Y-%m-%dT%H:%M:%SZ') item["pubDate"] = d.timetuple() item["guid"] = vod['id'] if item["category"] == "live": # To show a different news item when recording is over item["guid"] += "_live" feed.items.append(item) except KeyError as e: logging.warning('Issue with json: %s\nException: %s' % (vods_info, e)) abort(404) return feed.format_rss2_string()
def construct_rss(self, channel_name, vods_info, display_name, add_live=True): feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "%s's Twitch video RSS" % display_name feed.feed["link"] = "https://twitchrss.appspot.com/" feed.feed["author"] = "Twitch RSS Gen" feed.feed[ "description"] = "The RSS Feed of %s's videos on Twitch" % display_name feed.feed["ttl"] = '10' # Create an item try: if vods_info['videos']: for vod in vods_info['videos']: item = {} if vod["status"] == "recording": if not add_live: continue link = "http://www.twitch.tv/%s" % channel_name item["title"] = "%s - LIVE" % vod['title'] item["category"] = "live" else: link = vod['url'] item["title"] = vod['title'] item["category"] = vod['broadcast_type'] item["link"] = link item[ "description"] = "<a href=\"%s\"><img src=\"%s\" /></a>" % ( link, vod['preview']['large']) if vod.get('game'): item["description"] += "<br/>" + vod['game'] if vod.get('description_html'): item[ "description"] += "<br/>" + vod['description_html'] d = datetime.datetime.strptime(vod['created_at'], '%Y-%m-%dT%H:%M:%SZ') item["pubDate"] = d.timetuple() item["guid"] = vod['_id'] if vod["status"] == "recording": # To show a different news item when recording is over item["guid"] += "_live" feed.items.append(item) except KeyError as e: logging.warning('Issue with json: %s\nException: %s' % (vods_info, e)) self.abort(404) return feed.format_rss2_string()
def create_feed_container(app): from feedformatter import Feed feed = Feed() feed.feed['title'] = app.config.project feed.feed['link'] = app.config.feed_base_url feed.feed['author'] = app.config.feed_author feed.feed['description'] = app.config.feed_description if app.config.language: feed.feed['language'] = app.config.language if app.config.copyright: feed.feed['copyright'] = app.config.copyright app.builder.env.feed_feed = feed if not hasattr(app.builder.env, 'feed_items'): app.builder.env.feed_items = {}
def make_item_rss(title, row): # Create the feed feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "STATUS - MID-coding on Mechanical Turk" feed.feed["link"] = "http://www.psu.edu" feed.feed["author"] = "The Pennsylvania State University" feed.feed["description"] = "An experiment - row retrieved" item = {} for (key, value) in row.items(): item["mid:"+str(key)] = str(value) item["title"] = u"%s"%title feed.items.append(item) return feed.format_rss2_string()
def get(self): # Create the feed feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "pkt.li" feed.feed["author"] = "pkt.li" feed.feed["link"] = "http://pkt.li/banks/rss" # Create items and add to the feed for item in rss_items: feed.items.append(item) # Print the feed to stdout in various formats self.content_type = 'application/atom+xml' self.write(feed.format_atom_string())
def make_error_rss(s, id=None): # Create the feed feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "STATUS - MID-coding on Mechanical Turk" feed.feed["link"] = "http://www.psu.edu" feed.feed["author"] = "The Pennsylvania State University" feed.feed["description"] = u"%s"%s item = {} item["title"] = u"%s"%s if id: item["mid:id"] = u"%s"%id item["source"] = u"" feed.items.append(item) return feed.format_rss2_string()
def get_feed(url_home, url_day): feed = Feed() feed.feed["title"] = FEED_TITLE feed.feed["link"] = url_home() feed.feed["description"] = FEED_DESCRIPTION feed.feed["author"] = FEED_AUTHOR tz = timezone(POST_NEW_ITEM_AT_TZ) now = datetime.datetime.now(tz) today = now.date() if now.time() < POST_NEW_ITEM_AT: # don't post today's item yet today = today - datetime.timedelta(days=1) for i in range(1, DAYS_BACK + 1): date = today - datetime.timedelta(days=i) shots = service.popular_shots_of_day(date, SHOTS_PER_DAY) if not shots: # skip the day if no shots are recorded continue pubDate = datetime.datetime(date.year, date.month, date.day, POST_NEW_ITEM_AT.hour, POST_NEW_ITEM_AT.minute, POST_NEW_ITEM_AT.second, tzinfo=tz) pubDate = pubDate + datetime.timedelta(days=1) item = { "title": "Popular designs of {0}".format(date.strftime("%b %d")), "link": url_day(date), "pubDate": pubDate.astimezone(UTC).timetuple(), "guid": url_day(date), "description": render_template('feed/shots.html', shots=shots, date=date) } feed.items.append(item) return feed
def doGo(self, result): feed = Feed() feed.feed["title"] = "Test Feed" feed.feed["link"] = "http://code.google.com/p/feedformatter/" feed.feed["author"] = "Luke Maurits" feed.feed["description"] = "A simple test feed for feedformatter" item = { "title": "Test item", "link": "http://www.python.org", "description": "Python programming language", "guid": "1234567890" } feed.items.append(item) atomFeed = AtomFeed() atomFeed.atom_id = "http://code.google.com/p/feedformatter/" atomFeed.atom_title = "Test Feed" atomFeed.atom_author = [{'name': 'Luke Maurits'}] atomFeed.atom_link = [{ 'href': "http://code.google.com/p/feedformatter/", 'rel': 'self', 'type': 'text/html' }] atomFeed.atom_subtitle = "A simple test feed for feedformatter" atomEntry = AtomEntry() atomEntry.atom_id = "1234567890" atomEntry.atom_title = "Test item" atomEntry.atom_content = { 'content': "Python programming language", 'type': 'html' } atomEntry.atom_link = [{ 'href': "http://www.python.org", 'rel': 'self', 'type': 'text/html' }] atomFeed.feed_entries.append(atomEntry) atom, doc = atomFeed.build_atom_entry() atomString = ('<?xml version="1.0" encoding="UTF-8" ?>\n' + etree.tostring(atom, pretty_print=True)) print('%s\n%s' % (atomString, feed.format_atom_string(pretty=True))) return atomString
def feed(self, *args, **kwargs): name = os.path.sep.join(args) if args else None format = kwargs.get("format", "rss1") if not format in ("rss1", "rss2", "atom"): raise Exception("Invalid format %r" % format) feed = Feed() if name is not None: feed.feed["title"] = "%s :: %s" % (name, self.environ.site["name"]) else: feed.feed["title"] = self.environ.site["name"] feed.feed["link"] = self.request.server.base feed.feed["author"] = self.environ.site["author"] feed.feed["description"] = self.environ.site["description"] if name is not None: history = list(self.storage.page_history(name))[:30] for rev, date, author, comment in history: item = {} item["title"] = "%s by %s" % (name, author) item["link"] = self.request.url(name) item["description"] = comment item["pubDate"] = date item["guid"] = str(rev) feed.items.append(item) else: history = list(self.storage.history())[:30] for name, rev, date, author, comment in history: item = {} item["title"] = "%s by %s" % (name, author) item["link"] = self.request.url(name) item["description"] = comment item["pubDate"] = date item["guid"] = str(rev) feed.items.append(item) self.response.headers["Content-Type"] = "application/xml" return getattr(feed, "format_%s_string" % format)()
def get_worker_response(assn_id): if assn_id: # Create the feed feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "MID-coding on Mechanical Turk" feed.feed["link"] = "http://www.psu.edu" feed.feed["author"] = "The Pennsylvania State University" feed.feed["description"] = "An experiment - saved response" existing = connection.execute(assignments.select(assignments.c.id==assn_id)).first() if existing: item = {} for (key, value) in existing.items(): item["mid:"+str(key)] = str(value) item["title"] = str(assn_id) item["description"] = 'saved response' feed.items.append(item) return feed.format_rss2_string() else: return make_error_rss("No assignment with requested ID") else: return make_error_rss("Assignment ID not given to web service")
def make_feed(): feed = Feed() feed.feed["title"] = app.config['FEED_TITLE'] feed.feed["link"] = app.config['FEED_LINK'] feed.feed["author"] = app.config['FEED_AUTHOR'] feed.feed["description"] = app.config['FEED_DESC'] entries = BlogEntry.select().order_by(('date', 'desc'), ).paginate(0, app.config['FEED_ITEMS']) for post in entries: item = {} item["title"] = post.title item["link"] = post.link item["description"] = post.summary item["pubDate"] = post.date.utctimetuple() item["guid"] = post.eid feed.items.append(item) return feed
help= 'Enable CVE ranking (default is False) and only print entries with ranking' ) args = argParser.parse_args() if args.l: last = args.l else: last = 10 ref = "http://adulau.github.com/cve-search/" cves = cves.last(rankinglookup=args.r, namelookup=args.n) if not (args.f == "html"): from feedformatter import Feed feed = Feed() feed.feed['title'] = "cve-search Last " + str( last) + " CVE entries generated on " + str(datetime.datetime.now()) feed.feed['link'] = "http://adulau.github.com/cve-search/" feed.feed[ 'author'] = "Generated with cve-search available at http://adulau.github.com/cve-search/" feed.feed['description'] = "" else: print("<html><head>") print( "<style>.cve table { border-collapse: collapse; text-align: left; width: 100%; } .cve {font: normal 12px/150% Geneva, Arial, Helvetica, sans-serif; background: #fff; overflow: hidden; border: 1px solid #006699; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }.cve table td, .cve table th { padding: 3px 10px; }.cve table tbody td { color: #00496B; border-left: 1px solid #E1EEF4;font-size: 12px;font-weight: normal; }.cve table tbody .alt td { background: #E1EEF4; color: #00496B; }.cve table tbody td:first-child { border-left: none; }.cve table tbody tr:last-child td { border-bottom: none; }.cve table tfoot td div { border-top: 1px solid #006699;background: #E1EEF4;} .cve table tfoot td { padding: 0; font-size: 12px } .cve table tfoot td div{ padding: 0px; }</style>" ) print("<title>Last " + str(args.l) + " CVE entries</title>") print("</head><body>") for x in cves.get(limit=last):
def __init__(self, **kwargs): self.feed = Feed() self.header = FEED_HEADER for k, v in kwargs.items(): self.add_meta(k, v)
def feed_for_docs(alist, appuri=""): # takes a list of assignments, document IDs, or documents global LINK_PREFIX # must give assignments # Create the feed feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "MID-coding on Mechanical Turk" feed.feed["link"] = "http://www.psu.edu" feed.feed["author"] = "The Pennsylvania State University" feed.feed["description"] = "An experiment - document retrieval" print "feed for docs alist=", alist for a in alist: aid = None atoken = None if 'doc' in a: doc = a.doc aid = a.id atoken = a.token else: doc = a if isinstance(doc, basestring): ds = connection.execute(docs.select().where(docs.c.key==doc)) else: ds = [doc] if not ds: # print "ERROR - could not cross-reference document ", doc # print "- this is missing from docs table." return make_error_rss("ERROR - could not cross-reference document %s"%doc) for d in ds: # Create an item # item = {} # item["source"] = u""+d.source.rstrip() # item["mid:file"] = d.filename.rstrip() # item["mid:meta_date"] = d.meta_date.rstrip() # item["mid:meta_class"] = u"%s"%d.meta_class # item["mid:host_level"] = u"%s"%d.host_level # i = 0 # for e in d.meta_entities.split(","): # item["mid:meta_entity_%s"%i] = e # i+=1 # item = {} for (key, value) in d.items(): if not isinstance(value, float): if value is None: item["mid:"+key] = 'none' elif isinstance(value, ( int, long ) ): item["mid:"+key] = str(value) elif isinstance(value, datetime): item["mid:"+key] = value.strftime('%B %-d, %Y') else: item["mid:"+key] = value item["title"] = u""+d.headline.rstrip()#.decode("utf8") #date = d.gskey.split('--')[0] #item["date"] = int(datetime.datetime.strptime(date, '%Y%m%d').strftime('%s')) item["link"] = u""+appuri+"?aid=%s&request=doc"%aid item["mid:token"] = u"%s"%atoken item["mid:aid"] = u"%s"%aid if not LINK_PREFIX: item["mid:text"] = u""+d.text #.decode("utf8") feed.items.append(item) # print len(feed.items) return feed.format_rss2_string()