class FeedGenerator(object): def __init__(self, **kwargs): self.feed = Feed() self.header = FEED_HEADER for k, v in kwargs.items(): self.add_meta(k,v) def add_meta(self, label, val): self.feed.feed[label] = val def add_item(self, title, link, desc='', pub_date='', post_id=''): self.feed.items.append({ 'title': title, 'link': link, 'description': desc, 'pubDate': pub_date.utctimetuple() if pub_date else None, 'guid': post_id, }) def render(self, format='rss'): if format.lower().count('atom'): feed_str = self.feed.format_atom_string() else: feed_str = self.feed.format_rss2_string() return FEED_TEMPLATE % (self.header, feed_str) def rss(self): return self.render('rss') def atom(self): return self.render('atom')
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
class FeedGenerator(object): def __init__(self, **kwargs): self.feed = Feed() self.header = FEED_HEADER for k, v in kwargs.items(): self.add_meta(k, v) def add_meta(self, label, val): self.feed.feed[label] = val def add_item(self, title, link, desc='', pub_date='', post_id=''): self.feed.items.append({ 'title': title, 'link': link, 'description': desc, 'pubDate': pub_date.utctimetuple() if pub_date else None, 'guid': post_id, }) def render(self, format='rss'): if format.lower().count('atom'): feed_str = self.feed.format_atom_string() else: feed_str = self.feed.format_rss2_string() return FEED_TEMPLATE % (self.header, feed_str) def rss(self): return self.render('rss') def atom(self): return self.render('atom')
def generate_stream_atom(username=None): """generate an atom feed from the notices of an user """ feed = Feed() if username is None: notices = stream feed.feed["title"] = "live stream" feed.feed["link"] = DOMAIN + "/atom/stream/" feed.feed["author"] = DOMAIN else: notices = user_notices.get(username, None) feed.feed["title"] = username + "'s stream" feed.feed["link"] = DOMAIN + "/atom/stream/" + username feed.feed["author"] = username if notices is None: return tubes.Response('nothing to see here, please move along', 404) for notice in notices: item = {} item["title"] = notice.title item["link"] = DOMAIN + "notice/" + notice.uid item["description"] = notice.body item["pubDate"] = notice.creation item["guid"] = notice.uid feed.items.insert(0, item) return feed.format_atom_string()
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 render(self): feed = FeedGenerator() feed.feed["title"] = self.site["main"]["title"] feed.feed["author"] = self.site["main"]["author"] feed.feed["link"] = self.site["main"]["url"] for entry in self.entries: feed.items.append({ "title": entry.title, "link": "%s%s" % (feed.feed["link"], entry.item.location), "pubDate": entry.published_date.timetuple(), "guid": entry.item.location, }) return feed.format_atom_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 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 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")
print("<tr><td>CVSS: " + str(x['cvss']) + " Published: " + x['Published'] + "</td></tr>") print("<tr>") print("<td> Summary: " + x['summary'] + "</td>") print("</tr>") print("<tr><td>Vulnerable configuration:</td></tr>") print("<tr><td><ul>") for v in x['vulnerable_configuration']: sys.stdout.write("<li>" + cves.getcpe(v) + "</li>") print("</ul></td></tr>") if args.r: print("<tr><td>Ranking:" + str(x['ranking']) + "</td></tr>") print("<tr><td>References:<td></tr>") print("<tr><td><ul>") for r in x['references']: sys.stdout.write("<li><a href=\"" + str(r) + "\">" + str(r) + "</a></li>") print("</ul></tr></td>") print("</tbody></table></div><br/>") if args.f == "rss1": print(feed.format_rss1_string()) elif args.f == "atom": print(feed.format_atom_string()) elif args.f == "html": print( "Generated with <a href=\"https://github.com/adulau/cve-search\">cve-search</a> at " + str(datetime.datetime.today()) + ".") print("</body></html>") else: print(feed.format_rss2_string())
print ("<tr class=\"alt\">") print ("<td>"+str(x['id'])+ " - " +x['summary'][:90]+"...</td>") print ("</tr>") print ("<tr><td>CVSS: "+str(x['cvss'])+" Published: "+x['Published']+"</td></tr>") print ("<tr>") print ("<td> Summary: "+x['summary']+"</td>") print ("</tr>") print ("<tr><td>Vulnerable configuration:</td></tr>") print ("<tr><td><ul>") for v in x['vulnerable_configuration']: sys.stdout.write("<li>"+cves.getcpe(v) + "</li>") print ("</ul></td></tr>") if args.r: print ("<tr><td>Ranking:"+str(x['ranking'])+"</td></tr>") print ("<tr><td>References:<td></tr>") print ("<tr><td><ul>") for r in x['references']: sys.stdout.write("<li><a href=\""+str(r)+"\">"+str(r)+"</a></li>") print ("</ul></tr></td>") print ("</tbody></table></div><br/>") if args.f == "rss1": print (feed.format_rss1_string()) elif args.f == "atom": print (feed.format_atom_string()) elif args.f == "html": print ("Generated with <a href=\"https://github.com/adulau/cve-search\">cve-search</a> at "+str(datetime.datetime.today())+".") print ("</body></html>") else: print (feed.format_rss2_string())
author_uri = "%s/people/%s?fields=displayName&key=%s" % (base_uri, user_id, public_key) feed_uri = "%s/people/%s/activities/public?key=%s" % (base_uri, user_id, public_key) def get_data(uri): req = Request(uri) req.add_header("Referer", public_host) r = urlopen(req) return json.load(r) author = get_data(author_uri)['displayName'] feed = Feed() feed.feed['title'] = author + " G+" feed.feed['link'] = "https://plus.google.com/%s/posts" % (user_id) feed.feed['author'] = author for item in get_data(feed_uri)['items']: feed_item = {} feed_item['title'] = item['title'] feed_item['url'] = item['url'] feed_item['pubDate'] = time.strptime(item['published'].split(".")[0], "%Y-%m-%dT%H:%M:%S") feed_item['title'] = "" feed_item['content'] = item['object']['content'] feed.items.append(feed_item) print feed.format_atom_string()