def create_feed(data): # Create the feed feed = Feed() # Set the feed/channel level properties feed.feed["title"] = data["title"] feed.feed["link"] = data["permalink_url"] feed.feed["author"] = data["user"]["username"] feed.feed["description"] = data["description"] feed.feed["image"] = data["tracks"][0]["artwork_url"] # Create an item for track in data["tracks"]: item = {} # reset item object pubDate = datetime.datetime.strptime(track["created_at"][:-6], '%Y/%m/%d %H:%M:%S') item["title"] = track["title"] item["enclosure"] = ( track["download_url"]+"?client_id="+SOUNDCLOUD_CLIENTID, str(track["original_content_size"])) item["description"] = track["description"] item["guid"] = str(track["id"]) item["pubDate"] = pubDate.timetuple() # Add item to feed feed.items.append(item) # Print the feed to stdout in various formats return feed.format_rss2_string()
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 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()}))
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 construct_rss(self, channel_name, vods_info): feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "%s's Twitch video RSS" % channel_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" % channel_name # Create an item try: if vods_info['videos'] is not None: for vod in vods_info['videos']: item = {} link = "" if vod["status"] == "recording": link = "http://www.twitch.tv/%s" % channel_name item["title"] = "%s - LIVE" % vod['title'] else: link = vod['url'] item["title"] = vod['title'] item["link"] = link item["description"] = "<a href=\"%s\"><img src=\"%s\" /></a>" % (link, vod['preview']) d = datetime.datetime.strptime(vod['recorded_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 live is over item["guid"] += "_live" item["ttl"] = '10' feed.items.append(item) except KeyError: self.abort(404) return feed.format_rss2_string()
def find(self, query): # Create the feed feed = Feed() # Set the feed/channel level properties feed.feed["title"] = "Translate jobs search: %s" % query feed.feed["link"] = "http://www.diegotolentino.com" feed.feed["author"] = "Diego Tolentino" feed.feed["description"] = u'Extrator de trabalhos de tradução' # @todo Aparentemente o "pq(url=url)" da função get() sempre guarda o cache da primeira url lido, não lendo os demais, por isso sempre será lido somente a primeira pagina for i in [1]: # get itens of the page for item in self.get( "%s/cafe/SearchJobs.asp?Page=%s" % (self.url_base, i)): # If query match in item if query.lower() in item["description"].lower(): # Retrieving the complete description for item html = pq(url=item["link"]) item["description"] = html('table.jobTbl td.thinborder').eq(2).html() # Add item to feed feed.items.append(item) # Return the feed in rss2 format return feed.format_rss2_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 feedsrss(ids_raw): ''' get a bunch of feeds posts as an RSS stream ''' ids = [] feed_names = [] for i in ids_raw.split(','): try: feedid = int(i) if feedid in ids: continue feed = Feed.get(id=feedid) ids.append(feedid) feed_names.append(feed.name) except ValueError: continue except Feed.DoesNotExist: continue time_now = now() feed_posts = [p for p in \ Post.select().join(Feed).where( (Feed.id << ids) &(Post.status == 0) &(Post.active_start < time_now) &(Post.active_end > time_now) &(Post.published) )] feed = RSSFeed() feed.feed["title"] = ",".join(feed_names) feed.feed["link"] = url_for('feeds') feed.feed["description"] = "Posts from " + (','.join(feed_names)) for post in feed_posts: contents = json.loads(post.content) cleantext = bleach.clean(contents["content"], tags=[], strip=True) if len(cleantext) > 20: cleantext = cleantext[0:20] + "..." item = { "title": cleantext, "description": contents["content"], "guid": str(post.id), } feed.items.append(item) resp = make_response(feed.format_rss2_string()) resp.headers["Content-Type"] = "application/xml" return resp
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 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 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(self): from feedformatter import Feed import time feed = Feed() feed.feed["title"] = self.settings["blog_title"] feed.feed["link"] = self.settings["blog_url"] feed.feed["author"] = "*****@*****.**" feed.feed["description"] = u"C#, Objective-C, Python;" entities = db.Query(Entry).order("-published").fetch(limit=100) for x in entities: item = {} item["title"] = x.title item["link"] = self.settings["blog_url"] + "/post/" + str(x.key()) item["description"] = x.slug item["pubDate"] = x.published item["guid"] = str(x.key()) feed.items.append(item) self.set_header("Content-Type", "text/xml") self.write(feed.format_rss2_string())
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")
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())
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()
# Set the feed/channel level properties. feed.feed["title"] = "Sinfest RSS" feed.feed["link"] = "http://www.sinfest.net" feed.feed["author"] = "Tatsuya Ishida" feed.feed["description"] = "RSS feed for Sinfest" # Suggest checking every 12 hours. Normally content will update every 24 hours. # This is an attempt to tell clients there's no point checking the feed # every 5 minutes - it's not a big deal load-wise, but it is pointless. feed.feed["ttl"] = "720" # Create an item. # For this basic feed, I'll only include the latest comic. item = {} item["link"] = todaysSinfest["url"] item["guid"] = todaysSinfest["date"] item["pubDate"] = time.localtime() item["title"] = "Sinfest for %s: %s" % (todaysSinfest["dateFormatted"], todaysSinfest["title"]) if todaysSinfest["imageUrl"] != "": item["summary"] = '<img src="%s" /><br/><br/>%s' % (todaysSinfest["imageUrl"], todaysSinfest["ad"]) else: item["summary"] = "image not found" # Add item to feed. feed.items.append(item) # Save the feed to a file. with open("rss2.xml", "w") as f: f.write(feed.format_rss2_string()) f.write("\n") # Ensure file ends in EOL