class Feeder(): def __init__( self, url, title='', feedURL='' ): scraper = None if url.startswith( "https://twitter.com/" ): scraper = TwitterScraper( url ) if title == '': title = "Twitter: @" + url.split('/')[3] elif url.startswith( "http://www.lindwurm-linden.de/termine" ): scraper = LindwurmScraper( url ) if title == '': title = "Lindwurm: Termine" else: raise UnsupportedService( "No scraper found for this URL." ) self.feed = FeedGenerator() self.feed.id( url ) self.feed.title( title ) self.feed.author( { "name": url } ) if feedURL != '': self.feed.link( href=feedURL, rel='self' ) for entry in scraper.entries: fe = self.feed.add_entry() fe.id( entry['url'] ) fe.title( entry['title'] ) fe.link( href=entry['url'], rel='alternate' ) fe.content( entry['text'] ) def GetAtom( self ): return self.feed.atom_str( pretty=True ).decode()
def generate_feed(self): fg = FeedGenerator() fg.load_extension('podcast') for field in self.MAPPINGS: value_names = field[0] methods = field[1] values = [] # collect the values from self for value_name in value_names: values.append( getattr(self, value_name) ) # decend the attribute tree method = get_method(methods, fg) # apply the values to the found method method(*values) for episode in self.episodes.all(): # This is the same pattern as above, I wonder if I can DRY this out. entry = fg.add_entry() value_names, method_names = zip(*episode.MAPPINGS) values = [] for ind, value_name in enumerate(value_names): print value_name values = [getattr(episode, v) for v in value_name] if None not in values: print values method = get_method(method_names[ind], entry) method(*values) print "DONE" return fg
class TestExtensionTorrent(unittest.TestCase): def setUp(self): self.fg = FeedGenerator() self.fg.load_extension('torrent') self.fg.title('title') self.fg.link(href='http://example.com', rel='self') self.fg.description('description') def test_podcastEntryItems(self): fe = self.fg.add_item() fe.title('y') fe.torrent.filename('file.xy') fe.torrent.infohash('123') fe.torrent.contentlength('23') fe.torrent.seeds('1') fe.torrent.peers('2') fe.torrent.verified('1') assert fe.torrent.filename() == 'file.xy' assert fe.torrent.infohash() == '123' assert fe.torrent.contentlength() == '23' assert fe.torrent.seeds() == '1' assert fe.torrent.peers() == '2' assert fe.torrent.verified() == '1' # Check that we have the item in the resulting XML ns = {'torrent': 'http://xmlns.ezrss.it/0.1/dtd/'} root = etree.fromstring(self.fg.rss_str()) filename = root.xpath('/rss/channel/item/torrent:filename/text()', namespaces=ns) assert filename == ['file.xy']
def run(feeds): fgen = FeedGenerator() fgen.load_extension('podcast') result = reduce(merge, map(feed_parse, feeds), FeedGenerator()) result.rss_file(sys.stdout)
def generate_rss(language, since): url = "{0}?since={1}".format(language["url"], since) file_name = "github_trends_{0}_{1}.rss".format(language["key"], since) title = "GitHub Trends - {0} - {1}".format(language["name"], since.capitalize()) print(url) page = requests.get(url) tree = html.fromstring(page.content) lis = tree.cssselect("ol.repo-list li") fg = FeedGenerator() fg.title(title) fg.link(href="http://github-trends.ryotarai.info/rss/{0}".format(file_name)) fg.description(title) index = 1 for li in lis: a = li.cssselect("h3 a")[0] description = "" ps = li.cssselect("p") if len(ps) > 0: description = ps[0].text_content().strip() fe = fg.add_entry() fe.link(href="https://github.com{0}".format(a.get("href"))) fe.title("{0} (#{1} - {2} - {3})".format( a.text_content().strip().replace(" / ", "/"), index, language["name"], since.capitalize(), )) fe.description(description) index += 1 rssfeed = fg.rss_str(pretty=True) s3.Object(bucket, 'rss/{0}'.format(file_name)).put(Body=rssfeed, ContentType="application/xml")
def generate_feed(channel_dict, file_metadatas): fg = FeedGenerator() fg.load_extension("podcast") fg.link(href=channel_dict["url"], rel="self") fg.title(channel_dict["title"]) fg.description(channel_dict["description"]) for file_metadata in file_metadatas: add_entry(fg, file_metadata) return fg.rss_str(pretty=True)
def generate_feed(location, events): fg = FeedGenerator() fg.title('Upcoming Concerts in {}'.format(location.capitalize())) fg.link(href='http://example.com', rel='alternate' ) fg.description('Upcoming rockin\' concerts') for event in events.values(): fe = fg.add_entry() fe.id(event['link']) fe.title(event['groups']) fe.description(u'{} / {} / {}'.format(event['date'], event['city_venue'], event['price'])) fe.link(href=event['link']) fg.rss_file('html/feeds/{}.rss'.format(location))
def _get_header(self): rss = FeedGenerator() rss.load_extension('dc') rss.title('Feed title: %s' % self._rss_path) rss.link(href=self.__URL, rel='self') rss.description('Feed description') return rss
def build_feed_generator(query=None): gen = FeedGenerator() gen.title(FEED_TITLE) gen.subtitle(FEED_SUBTITLE) gen.language(FEED_LANG) feed_link = url_for('views.feed', query=query, _external=True) gen.link(href=feed_link, rel='self', type='application/rss+xml') return gen
def _get_header(self): title, desc, self.__uploads_id = self.__get_channel_details(self._rss_path) rss = FeedGenerator() rss.load_extension('dc') rss.title(title) rss.link(href=self.__PLAYLIST_URL % self.__uploads_id, rel='self') rss.description(desc or title) return rss
def setUp(self): self.fg = FeedGenerator() self.fg.load_extension('media') self.fg.id('id') self.fg.title('title') self.fg.link(href='http://example.com', rel='self') self.fg.description('description')
def _get_header(self): rss = FeedGenerator() rss.load_extension('dc') # channel xml tags chan_details = self.__get_xml_dict( self.__rss_xml.find('channel'), ['title', 'description', 'link'] ) rss.title(chan_details['title']) rss.link(href=chan_details['link'], rel='self') rss.description(chan_details['description']) return rss
def serve_filter(type, filtername): try: fil = trn.select_unique(Filter, name=filtername, insert=False) except: logging.exception("serve_filter failed for filter %s" % (filtername,)) raise out_feed = FeedGenerator() out_feed.title(fil.title) out_feed.subtitle(fil.subtitle) out_feed.id(filtername) for entry in fil.entries(): d = entry.definition out_entry = out_feed.add_entry() out_entry.title(d.title) out_entry.published(getattr(d, "published", None)) out_entry.updated(getattr(d, "updated", None)) out_entry.id(d.id) out_entry.summary(d.summary) for c in getattr(d, "content", []): out_entry.content(content=c.value, type=c.type) #, src=c.base for l in getattr(d, "links", []): out_entry.link(link=l) try: if type == "atom": mimetype = "application/atom+xml" result = out_feed.atom_str() else: mimetype = "application/rss+xml" result = out_feed.rss_str() except: logging.exception("%s error", type) mimetype = "text/plain" result = """ An error occurred while trying to produce this feed. You could try using %s instead. """ % ("rss" if type == "atom" else "atom",) response.content_type = mimetype return result
def parseString(html, url, tag): parsed_html = BeautifulSoup(html) parsedUrl = urlparse(url) baseUrl = parsedUrl.scheme+"://"+parsedUrl.netloc fg = FeedGenerator() fg.id(url) fg.title('Generated feed for ' + url) fg.link( href=url, rel='alternate' ) fg.subtitle('Autogenerated by alltorss.py based on tag ' + tag) for item in parsed_html.body.find_all(tag): topic = item.text.strip() #check if item contains a link innerLink = findInnerLink(item) outerLink = findOuterLink(item) if (innerLink != None): link = innerLink elif (outerLink != None): link = outerLink else: link = None if isinstance(link, Tag) and link.has_attr('href'): linkHref = link['href'] fe = fg.add_entry() if (linkIsAbsolute(linkHref)): fullLink = linkHref else: fullLink = baseUrl + linkHref fe.id(fullLink) fe.title(topic) fe.link( href=fullLink ) return fg
def test_categoryHasDomain(self): fg = FeedGenerator() fg.title('some title') fg.link(href='http://www.dontcare.com', rel='alternate') fg.description('description') fe = fg.add_entry() fe.id('http://lernfunk.de/media/654321/1') fe.title('some title') fe.category([ {'term': 'category', 'scheme': 'http://www.somedomain.com/category', 'label': 'Category', }]) result = fg.rss_str() assert b'domain="http://www.somedomain.com/category"' in result
def blog_feed(self, values): domain = request.httprequest.host_url.rstrip('/') blog = values['blog'] fg = FeedGenerator() fg.id(domain + values['pager']['page']['url']) fg.title(blog.name) fg.subtitle(blog.subtitle) for post in values['blog_posts']: fe = fg.add_entry() fe.id(domain + '/blog/{}/post/{}'.format(slug(blog), slug(post))) fe.title(post.name) fe.content(post.content) return fg
def __init__(self, name): self.name = name self.ydl = youtube_dl.YoutubeDL(self.ydl_opts) self.fg = FeedGenerator() self.fg.title(name) self.fg.author({"name": "Youtube Audio Feed", "email": ""}) self.fg.link(href="http://www.foo.bar.baz.com", rel="alternate") self.fg.description("Personalized Youtube audio feed") self.fg.generator("") self.fg.docs("")
def GET(self, query): engine = DIGBTSearchEngine(query=query) feed = FeedGenerator() feed.title(query) feed.link(href=engine.url) feed.description(query) for torrent in engine.torrents: entry = feed.add_entry() entry.id(torrent['id']) entry.title(torrent['title']) entry.link(href=torrent['url']) web.header('Content-Type', 'application/rss+xml') return feed.rss_str()
def generate_feed(channel_dict, file_metadatas): fg = FeedGenerator() fg.load_extension("podcast") fg.link(href=channel_dict["url"], rel="self") fg.title(channel_dict["title"]) fg.description(channel_dict["description"]) try: category = channel_dict["category"] except KeyError: category = None try: subcategory = channel_dict["subcategory"] except KeyError: subcategory = None fg.podcast.itunes_category(category, subcategory) for file_metadata in file_metadatas: add_entry(fg, file_metadata) return fg.rss_str(pretty=True)
def build(rss_file, latest): fg = FeedGenerator() fg.title('QI Feed') fg.link(href='qi.com/feed') fg.description('Facts from QI') maximum = latest for e in feed(latest): fe = fg.add_entry() fe.id(e['id']) fe.title(e['title']) fe.content(e['body']) fe.link(href=e['link']) fe.published(e['date'] + ' GMT') eid = int(e['id']) if eid > maximum: maximum = eid fg.rss_file(rss_file) return maximum
def test_content_cdata_type(self): fg = FeedGenerator() fg.title('some title') fg.id('http://lernfunk.de/media/654322/1') fe = fg.add_entry() fe.id('http://lernfunk.de/media/654322/1') fe.title('some title') fe.content('content', type='CDATA') result = fg.atom_str() assert b'<content type="CDATA"><![CDATA[content]]></content>' in result
class TestExtensionGeo(unittest.TestCase): def setUp(self): self.fg = FeedGenerator() self.fg.load_extension('geo') self.fg.title('title') self.fg.link(href='http://example.com', rel='self') self.fg.description('description') def test_geoEntryItems(self): fe = self.fg.add_item() fe.title('y') fe.geo.point('42.36 -71.05') assert fe.geo.point() == '42.36 -71.05' # Check that we have the item in the resulting XML ns = {'georss': 'http://www.georss.org/georss'} root = etree.fromstring(self.fg.rss_str()) point = root.xpath('/rss/channel/item/georss:point/text()', namespaces=ns) assert point == ['42.36 -71.05']
def __init__(self): self.feedgen_connection = FeedGenerator() self.feedgen_connection.id('http://lernfunk.de/media/654321') self.feedgen_connection.title('MediaKraken Notification Feed') self.feedgen_connection.author( {'name': 'John Doe', 'email': '*****@*****.**'}) self.feedgen_connection.link( href='http://example.com', rel='alternate') self.feedgen_connection.logo('http://ex.com/logo.jpg') self.feedgen_connection.subtitle('This is a cool feed!') self.feedgen_connection.link( href='http://larskiesow.de/test.atom', rel='self') self.feedgen_connection.language('en')
def test_removeEntryByIndex(self): fg = FeedGenerator() self.feedId = 'http://example.com' self.title = 'Some Testfeed' fe = fg.add_entry() fe.id('http://lernfunk.de/media/654321/1') fe.title('The Third Episode') assert len(fg.entry()) == 1 fg.remove_entry(0) assert len(fg.entry()) == 0
def __init__(self, baseURL, audioDir): self.baseURL = baseURL self.dir = audioDir self.fg = FeedGenerator() self.fg.load_extension('podcast') self.fg.id(baseURL) self.fg.title('Yesterdays Baseball') self.fg.author( name='MLB' ) self.fg.link( href=baseURL, rel='alternate' ) self.fg.logo('http://en.wikipedia.org/wiki/Major_League_Baseball_logo#/media/File:Major_League_Baseball.svg') self.fg.icon('http://en.wikipedia.org/wiki/Major_League_Baseball_logo#/media/File:Major_League_Baseball.svg') self.fg.subtitle("Awright, 'arry? See that ludicrous display last night?") self.fg.link( href=baseURL+'podcast.xml', rel='self' ) self.fg.language('en') self.fg.podcast.itunes_explicit('no') self.fg.podcast.itunes_complete('no') self.fg.podcast.itunes_new_feed_url(baseURL+'podcast.xml') self.fg.podcast.itunes_summary("Awright, 'arry? See that ludicrous display last night?") self.addAllEntries()
def getDataFeed(): # have a useragent so we do not look like a robot useragent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" sesh = requests.Session() # type: requests.Session sesh.headers.update({"User-Agent": useragent}) r = sesh.get(fmeasure) # ok to make the gotten feed slimmer I will be building a new one # containing only the title of the blog, the feed it # and the entries so I am using feedgen library to do so fg = FeedGenerator() feed = feedparser.parse(r.text) fg.title(feed.feed.title) fg.id(feed.feed.id) entries = [] # concatenate every entry from the current pagination entries.extend(feed.entries) # as usual check next and while good get next set of entries # and extract the entries good, nl = check_next(r.text) while good: r = sesh.get(nl) feed = feedparser.parse(r.text) entries.extend(feed.entries) good, nl = check_next(r.text) r.close() # for each of the entries for e in entries: # create a new entry fe = fg.add_entry() # add the entry id, title and content fe.id(e.id) fe.title(e.title) c = e.content[0] fe.content(content=c.value, type=c.type) # write the new feed file out fg.atom_file("datafiles/f-measure.xml", pretty=True) sesh.close() # now to get the genres get_genres()
def get_feed(csv_path, feed_type): """Writes a podcast feed based on a CSV file of URLS. Parameters: urlfilepath -- path of CSV file containing date,url entries feedtype -- type of feed, possible values: 'atom' or 'rss' """ with open(csv_path, encoding='utf-8') as file: rows = [row for row in csv.reader(file)] fg = FeedGenerator() fg.title("Audio from the interwebs") fg.logo(FEED_LOGO) fg.id(FEED_ID) for row in rows: # for each row from CSV file, add a FeedEntry object to the # Feedgenerator date, url, title = row url_quoted = urllib.parse.quote(url, ':/') domain = urllib.parse.urlparse(url).netloc content = "This audio file from {} was added on {}.".format(domain, date) fe = fg.add_entry() fe.id(url) fe.title(title) fe.link({'href': url_quoted, 'rel' : 'enclosure'}) fe.content(content) fe.published(date) if feed_type == 'atom': func = fg.atom_str else: func = fg.rss_str return func(pretty=True, encoding='UTF-8')
def gen_feed(endpoint): # Make sure we have somewhere to save the files if not os.path.isdir('./gen'): print('There is no gen directory. Create ./gen') # Uses parse_dir.py to get the books and files books = parse_dir.getbooks_r('./audiobooks') for (book, files) in books: # Creates a new feed for each book fg = FeedGenerator() fg.load_extension('podcast') fg.podcast.itunes_category('Audiobook') for (file_name, file_path) in files: # the 1: removes the period because the base dir is ./audiobooks url = endpoint + file_path[1:] fe = fg.add_entry() fe.id(url) fe.title(file_name) fe.description(file_name) fe.enclosure(requote_uri(url), str(os.path.getsize(file_path)), 'audio/mpeg') fg.title(book) fg.link(href=endpoint, rel='self') fg.description(book) fg.rss_str(pretty=True) # Saves the file rss_file_path = os.path.join('./gen/', book + '.xml') ensure_dir(rss_file_path) logging.info("generate feed: %s" % rss_file_path) fg.rss_file(rss_file_path)
# -*- coding: utf-8 -*- from feedgen.feed import FeedGenerator feed = FeedGenerator() feed.title("Customed RARBG Torrent Feed") feed.link(href="https://github.com/Apocalypsor/Rarbg") feed.description("Make RARBG Greater Again! by Apocalypsor") feed.language("en") feed.logo("https://cdn.jsdelivr.net/gh/Apocalypsor/Rarbg@master/assets/favicon.png") def getRSS(entries): for entry in entries: feedEntry = feed.add_entry() feedEntry.title(entry.filename) feedEntry.link(href=entry.download) feedEntry.guid(entry.download) response = feed.rss_str(pretty=True) return response if __name__ == "__main__": print("rarbg.to")
def create_feed(feed_type: FeedType) -> str: feed_generator = FeedGenerator() search_params = extract_search_params(request.args) base_url = f"{FDK_BASE_URI}/datasets" query_string = build_query_string(search_params) feed_generator.id(f"{base_url}{query_string}") feed_generator.title("Felles datakatalog - Datasett") feed_generator.description("En samling av datasett publisert i Felles datakataog") feed_generator.link(href=f"{base_url}{query_string}") datasets = get_datasets_for_feed( map_search_params_to_search_request_body(search_params) ) for dataset in datasets: feed_entry = feed_generator.add_entry() feed_entry.id(f"{base_url}/{dataset['id']}") feed_entry.title(translate(dataset["title"])) feed_entry.description(translate(dataset["description"])) feed_entry.link(href=f"{base_url}/{dataset['id']}") feed_entry.author( name=translate( dataset["publisher"]["prefLabel"] or dataset["publisher"]["name"] ) ) feed_entry.published(dataset["harvest"]["firstHarvested"]) if feed_type == FeedType.RSS: return feed_generator.rss_str(pretty=True) elif feed_type == FeedType.ATOM: return feed_generator.atom_str(pretty=True) else: return ""
def setUp(self): self.fg = FeedGenerator() self.fg.load_extension('podcast') self.fg.title('title') self.fg.link(href='http://example.com', rel='self') self.fg.description('description')
def build_rss_feeds(blog_posts): feed = FeedGenerator() feed.load_extension("media", rss=True, atom=True) base = "https://whotracks.me" for post in blog_posts: if post["publish"]: entry = feed.add_entry() entry.id(f'{base}/blog/{post["filename"]}.html') entry.title(post["title"]) entry.link(link={"href": f"{base}/blog/{post['filename']}.html"}) entry.author({"name": post["author"]}) entry.pubDate( datetime.strptime(post["date"], "%Y-%m-%d").replace(tzinfo=timezone("CET"))) entry.description(post["subtitle"]) entry.media.thumbnail( url=f'https://whotracks.me/static/img/{post["header_img"]}') feed.title("WhoTracksMe blog") feed.description("By the tech teams at Cliqz and Ghostery") feed.link(link={"href": f"{base}/blog.html"}) feed.id("wtm") feed.language("en") feed.logo(f"{base}/static/img/who-tracksme-logo.png") feed.rss_file("_site/blog/feed.xml")
def main(): now = datetime.now() today_day_of_week = now.weekday() most_recent_sunday = now - timedelta( days=today_day_of_week + 1) # sunday is day 6 fg = FeedGenerator() fg.load_extension('podcast') fg.id(URL) fg.title('Wicked Bites Radio') fg.category(term='Food') fg.language('en') fg.logo( 'http://www.nedine.com/wp-content/themes/wickedbites/images/logo.png') fg.link(href='http://www.nedine.com', rel='alternate') fg.link(href=URL, rel='self') fg.description('The Pat Whitley Restaurant Show') fg.podcast.itunes_category('Food') fg.podcast.itunes_summary('Pat Whitley Restaurant Show') fg.podcast.itunes_explicit('no') fg.podcast.itunes_new_feed_url(URL) fg.podcast.itunes_category('Arts', 'Food') fg.podcast.itunes_owner('Eric Biagiotti', '*****@*****.**') for i in range(10): datestamp = (most_recent_sunday - timedelta(weeks=i)) url = 'http://www.nedine.com/Radio/Shows/%s.mp3' % datestamp.strftime( '%m%d%y') r = requests.head(url) if r.status_code == 200: entry = fg.add_entry(order='append') entry.id(url) entry.title(datestamp.strftime('%m/%d/%Y')) entry.pubDate(datestamp.strftime('%Y-%m-%d 00:00:00 UTC')) entry.description( datestamp.strftime('Wicked Bites Radio show for %A, %B %e %Y')) entry.podcast.itunes_summary( datestamp.strftime('Wicked Bites Radio show for %A, %B %e %Y')) entry.enclosure(url, r.headers.get('Content-Length', 0), 'audio/mpeg') fg.rss_file('wickedbites.rss') s3_connection = boto.connect_s3() bucket = s3_connection.get_bucket('ebiagiotti') key = boto.s3.key.Key(bucket, 'wickedbites.rss') key.set_contents_from_filename('wickedbites.rss', policy='public-read')
def index(): global messages limit_tag = request.args.get('tag') pause_uuid = request.args.get('pause') if pause_uuid: try: datastore.data['watching'][pause_uuid]['paused'] ^= True datastore.needs_write = True return redirect(url_for('index', tag = limit_tag)) except KeyError: pass # Sort by last_changed and add the uuid which is usually the key.. sorted_watches = [] for uuid, watch in datastore.data['watching'].items(): if limit_tag != None: # Support for comma separated list of tags. for tag_in_watch in watch['tag'].split(','): tag_in_watch = tag_in_watch.strip() if tag_in_watch == limit_tag: watch['uuid'] = uuid sorted_watches.append(watch) else: watch['uuid'] = uuid sorted_watches.append(watch) sorted_watches.sort(key=lambda x: x['last_changed'], reverse=True) existing_tags = datastore.get_all_tags() rss = request.args.get('rss') if rss: fg = FeedGenerator() fg.title('changedetection.io') fg.description('Feed description') fg.link(href='https://changedetection.io') for watch in sorted_watches: if not watch['viewed']: fe = fg.add_entry() fe.title(watch['url']) fe.link(href=watch['url']) fe.description(watch['url']) fe.guid(watch['uuid'], permalink=False) dt = datetime.datetime.fromtimestamp(int(watch['newest_history_key'])) dt = dt.replace(tzinfo=pytz.UTC) fe.pubDate(dt) response = make_response(fg.rss_str()) response.headers.set('Content-Type', 'application/rss+xml') return response else: output = render_template("watch-overview.html", watches=sorted_watches, messages=messages, tags=existing_tags, active_tag=limit_tag, has_unviewed=datastore.data['has_unviewed']) # Show messages but once. messages = [] return output
#!/usr/bin/env python3 import yaml from feedgen.feed import FeedGenerator import glob import os fg = FeedGenerator() fg.load_extension('podcast') fg.podcast.itunes_category('Technology') fg.logo('https://edgecollective.io/podcast/pod.png') fg.podcast.itunes_image('https://edgecollective.io/podcast/pod.png') fg.podcast.itunes_author('Edge Collective') with open('podcast_meta.yaml') as f: data = yaml.load(f, Loader=yaml.FullLoader) fg.title(data['title']) fg.link(href=data['link'], rel=data['rel']) fg.description(data['description']) fg.language(data['language']) for filename in glob.glob('episodes/*.yaml'): with open(filename, 'r') as f: fe = fg.add_entry() data = yaml.load(f, Loader=yaml.FullLoader) fe.id(data['id']) fe.title(data['title']) fe.description(data['description']) fe.enclosure(data['id'], 0, data['format']) fe.published(data['date'])
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
import sys import urllib def creation_date(path_to_file): if platform.system() == 'Windows': return os.path.getctime(path_to_file) else: stat = os.stat(path_to_file) try: return stat.st_birthtime except AttributeError: return stat.st_mtime fg = FeedGenerator() fg.load_extension('podcast') fg.language('pl') fg.podcast.itunes_explicit('no') if (len(sys.argv) > 1 and sys.argv[1] == '3'): fg.title(u'Trójka') fg.podcast.itunes_author(u'Trójka') fg.link(href='https://www.polskieradio.pl/9,Trojka', rel='alternate') fg.subtitle(u'Nieoficjalny podcast Trójki') fg.copyright('cc-by-PolskieRadio') fg.podcast.itunes_summary(u'Podcast Trójki') fg.image('https://www.simx.mobi/trojka/trojka.jpg') fg.podcast.itunes_image('https://www.simx.mobi/trojka/trojka.jpg') fg.podcast.itunes_category('International', 'Polish') url = u'https://www.simx.mobi/trojka/'
def _build_feed(self): router = Router(self._config) fp = filterPlaceholders fg = FeedGenerator() fg.id(self._config.site_prefix) fg.title(self._config.site_name) fg.author({ 'name': fp(self._config.author), 'email': fp(self._config.email) }) fg.link(href=self._config.site_prefix, rel='alternate') fg.logo(fp(self._config.site_logo)) fg.subtitle(fp(self._config.description)) fg.language(fp(self._config.language)) fg.lastBuildDate(moment.now().locale(self._config.locale).date) fg.pubDate(moment.now().locale(self._config.locale).date) for post in self._posts[:10]: meta = post.meta fe = fg.add_entry() fe.title(meta['title']) fe.link(href=router.gen_permalink_by_meta(meta)) fe.guid(router.gen_permalink_by_meta(meta), True) fe.pubDate(meta['date'].date) fe.author({ 'name': meta['author'], 'uri': fp(self._config.author_homepage), 'email': fp(self._config.email) }) fe.content(post.parsed) if not os.path.exists( unify_joinpath(self._config.build_dir, 'feed/atom')): os.makedirs(unify_joinpath(self._config.build_dir, 'feed/atom')) fg.rss_file(unify_joinpath(self._config.build_dir, 'feed/index.xml')) fg.rss_file(unify_joinpath(self._config.build_dir, 'feed/index.html')) fg.atom_file( unify_joinpath(self._config.build_dir, 'feed/atom/index.xml')) fg.atom_file( unify_joinpath(self._config.build_dir, 'feed/atom/index.html'))
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
or sys.argv[1].endswith('atom') \ or sys.argv[1].endswith('podcast') ): print_enc ('Usage: %s ( <file>.atom | atom | <file>.rss | rss | podcast )' % \ 'python -m feedgen') print_enc ('') print_enc (' atom -- Generate ATOM test output and print it to stdout.') print_enc (' rss -- Generate RSS test output and print it to stdout.') print_enc (' <file>.atom -- Generate ATOM test feed and write it to file.atom.') print_enc (' <file>.rss -- Generate RSS test teed and write it to file.rss.') print_enc (' podcast -- Generator Podcast test output and print it to stdout.') print_enc ('') exit() arg = sys.argv[1] fg = FeedGenerator() fg.id('http://lernfunk.de/_MEDIAID_123') fg.title('Testfeed') fg.author( {'name':'Lars Kiesow','email':'*****@*****.**'} ) fg.link( href='http://example.com', rel='alternate' ) fg.category(term='test') fg.contributor( name='Lars Kiesow', email='*****@*****.**' ) fg.contributor( name='John Doe', email='*****@*****.**' ) fg.icon('http://ex.com/icon.jpg') fg.logo('http://ex.com/logo.jpg') fg.rights('cc-by') fg.subtitle('This is a cool feed!') fg.link( href='http://larskiesow.de/test.atom', rel='self' ) fg.language('de') fe = fg.add_entry() fe.id('http://lernfunk.de/_MEDIAID_123#1')
def generateFeed(): fg = FeedGenerator() fg.id(URL) fg.title('Package Tracking') fg.link(href=URL) fg.description('Delivers Package Tracking Updates') for entry in database.all(): fe = fg.add_entry() fe.link(href=entry.get('link')) fe.id(URL + '/' + str(entry.doc_id)) fe.title(entry.get('edd')) fe.description(entry.get('discr')) fe.updated( datetime.datetime.fromtimestamp(entry.get('epoch'), datetime.timezone.utc)) atomfeed = fg.atom_str(pretty=True) # Get the ATOM feed as string fg.atom_file('/srv/atom.xml') # Write the ATOM feed to a file
def rssvideoschannel(request, channel_id): channel = Channel.objects.get(channel_id=channel_id) if not channel: return Http404 videos = channel.video_set.order_by('-pub_date') fg = FeedGenerator() fg.load_extension('podcast') channelURL = ''.join([ 'http://', get_current_site(request).domain, reverse('you2rss:videoperchannel', args=(channel_id, )) ]) fg.id(channelURL) fg.title(channel.title_text) fg.author({'name': 'pon sko', 'email': '*****@*****.**'}) fg.link(href=channelURL, rel='alternate') description = channel.description_text if len(description) < 2: description = "no desc" fg.subtitle(description) fg.description(description) fg.language('en') fg.logo(logo=channel.thumbnail) fg.image(url=channel.thumbnail, title=channel.title_text) fg.podcast.itunes_image(channel.thumbnail) for video in videos: fe = fg.add_entry() fe.author(name=channel.title_text) videodesc = video.description_text if len(videodesc) < 2: videodesc = "no desc" fe.content(videodesc) fileURL = ''.join([ 'http://', get_current_site(request).domain, reverse('you2rss:rssfile', args=(video.video_id, )) ]) fe.enclosure(fileURL, '1337', 'audio/mpeg') fe.id(fileURL) fe.link(href=fileURL, rel='alternate') fe.podcast.itunes_image(video.thumbnail) fe.pubdate(video.pub_date) fe.published(video.pub_date) fe.title(video.title_text) rssdata = fg.rss_str(pretty=True) response = HttpResponse(rssdata, content_type='application/rss+xml; charset=UTF-8') response['Content-Length'] = len(rssdata) return response
def staticrss(request, podcast_id): podcast = Podcast.objects.get(id=podcast_id) if not podcast: return Http404 pods = podcast.pod_set.order_by('-audio_link') fg = FeedGenerator() fg.load_extension('podcast') channelURL = ''.join([ 'http://', get_current_site(request).domain, reverse('you2rss:staticrss', args=(podcast_id, )) ]) fg.id(channelURL) fg.title(podcast.title_text) fg.author({'name': 'pon sko', 'email': '*****@*****.**'}) fg.link(href=channelURL, rel='alternate') description = podcast.description_text if len(description) < 2: description = "no desc" fg.subtitle(description) fg.description(description) fg.language('en') fg.logo(logo=podcast.thumbnail) fg.image(url=podcast.thumbnail, title=podcast.title_text) fg.podcast.itunes_image(podcast.thumbnail) for pod in pods: fe = fg.add_entry() fe.author(name=podcast.title_text) desc = pod.description_text if len(desc) < 2: desc = "no desc" fe.content(desc) fileURL = pod.audio_link #''.join(['http://', get_current_site(request).domain, # reverse('you2rss:rssfile', args=(video.video_id,))]) fe.enclosure(fileURL, pod.audio_size, pod.audio_type) fe.id(fileURL) fe.link(href=fileURL, rel='alternate') fe.podcast.itunes_image(podcast.thumbnail) fe.pubdate(pod.pub_date) fe.published(pod.pub_date) fe.title(pod.title_text) rssdata = fg.rss_str(pretty=True) response = HttpResponse(rssdata, content_type='application/rss+xml; charset=UTF-8') response['Content-Length'] = len(rssdata) return response
def lambda_handler(event, context): # obtain all entries in database response = table.scan( FilterExpression=Attr('episode_int').gte(1) ) # save object with the items themselves items = response['Items'] #print(items) items_sorted = sorted(items, key = lambda i: i['episode_int']) # set up overall feed metadata fg = FeedGenerator() # general feed params fg.id('https://r-podcast.org') fg.title('Residual Snippets') fg.author( {'name':'Eric Nantz', 'email':'*****@*****.**'}) fg.link(href='https://r-podcast.org', rel='alternate' ) fg.logo(LOGO_URL) fg.subtitle('Musings on R, data science, linux, and life') fg.link( href=RSS_URL, rel='self') fg.language('en') fg.load_extension('podcast') # podcast-specific params fg.podcast.itunes_category('Technology') fg.podcast.itunes_author('Eric Nantz') fg.podcast.itunes_explicit('no') fg.podcast.itunes_owner('Eric Nantz', '*****@*****.**') fg.podcast.itunes_summary('Residual Snippets is an informal, unedited, and free-flowing audio podcast from Eric Nantz. If you enjoy hearing quick takes from a data scientist on their journey to blend innovative uses of open-source technology, contributing back to their brilliant communities, and juggling the curveballs life throws at them, this podcast is for you!') for x in range(len(items_sorted)): #print(items[x]) fe = fg.add_entry() fe.title(items_sorted[x]['episode_title']) fe.author( {'name':'Eric Nantz', 'email':'*****@*****.**'} ) fe.enclosure(url=items_sorted[x]['episode_url'], type = 'audio/mpeg') # process description before adding to feed ep_desc = create_summary(items_sorted[x]['episode_summary']) #fe.description(items_sorted[x]['episode_summary']) fe.description(ep_desc) # populate xml file for RSS feed feed_string = fg.rss_str(pretty=True) fg.rss_file('/tmp/residual_snippets.xml', pretty=True) # upload xml feed to pcloud and s3 pc = PyCloud(PCLOUD_USERNAME, PCLOUD_PASS) pc.uploadfile(data = feed_string, filename='residual_snippets.xml', folderid=PCLOUD_FOLDER_ID) #upload_file("/tmp/residual_snippets.xml", BUCKET_NAME, object_name = 'residual_snippets.xml') s3_client.upload_file("/tmp/residual_snippets.xml", BUCKET_NAME, 'residual_snippets.xml') # create export of dynamodb and upload to s3 # obtain all entries in database response2 = table.scan( FilterExpression=Attr('episode_int').gte(1) ) # save object with the items themselves items2 = response2['Items'] items2_sorted = sorted(items2, key = lambda i: i['episode_int']) db_export = "/tmp/dbexport.json" f = open(db_export, "w") f.write(json.dumps(items2_sorted, indent=2, default=decimal_default)) f.close() # upload to s3 bucket success = s3_client.upload_file(db_export, BUCKET_NAME, 'dbexport.json') return { 'statusCode': 200, 'body': json.dumps('Hello from Lambda!') }
def create_feed(posts): fg = FeedGenerator() fg.id(SITE_URL) fg.title(SITE_NAME) fg.author(AUTHOR_INFO) fg.link(href=SITE_URL, rel='alternate') fg.link(href=SITE_URL + '/feed.atom', rel='self') fg.language(FEED_LANGUAGE) fg.image(url=IMG_URL) for i in range(min(10, len(posts))): post = posts[i] content = makeAtomContent(post['content']) fe = fg.add_entry() fe.id(fg.id() + '/' + post['url']) fe.title(post['title']) fe.link(href=fe.id()) fe.published(post['date'].replace(tzinfo=tzutc())) fe.content(content, type="CDATA") return fg.atom_str(pretty=True).decode('utf-8')
def _construct_feeds(self) -> Dict[str, Dict[str, str]]: """ Takes the current content and returns a constructed dictionary of atom-formatted feeds. This method should only be called by the background thread. :return: A dictionary with string keys, one for each board command and one for ``master``. The values are XML-formated feeds. """ def id_generator(name, ts): return ('tag:{feed_domain},{date}:{name}'.format( feed_domain=self.feed_domain, date=datetime.fromtimestamp(ts).strftime('%Y-%m-%d'), name=name)) def translate_content_to_xhtml(content): """Try to render a board post as faithfully as possible in xhtml.""" # Unfortunately most readers I find strip the style attribute so we'll probably have to work on this. return '<p style="white-space:pre-wrap;">{}</p>'.format( escape(content).replace('\n', '<br />')) # TODO(hyena): It would be more useful if these links were absolute. # Consider adding that if we ever make the web-app aware of its own # url. new_feeds = {} master_feedgen = FeedGenerator() master_feedgen.title("SpinDizzy Boards Master") master_feedgen.link({'href': '/sdb/atom', 'rel': 'self'}) master_feedgen.description("All posts as scraped from SpinDizzy") master_feedgen.id(id_generator('master', 0)) master_entry_list = [] for board_command in self.current_content: board_feedgen = FeedGenerator() board_feedgen.title("SpinDizzy {}".format( self.board_names[board_command])) board_feedgen.link({ 'href': '/sdb/{}/atom'.format(board_command), 'rel': 'self' }) board_feedgen.description("Posts scraped from {}".format( self.board_names[board_command])) board_feedgen.id(id_generator(board_command, 0)) for post in sorted(self.current_content[board_command].values(), key=lambda p: -p['time']): entry = board_feedgen.add_entry() entry.title(post['title']) # RSS insists on an email which is annoying. entry.author({'name': post['owner_name']}) entry.updated(datetime.fromtimestamp(post['time'], tz=self.tz)) entry.link({ 'href': '/sdb/{}/{}'.format(board_command, post['time']), 'rel': 'alternate' }) entry.content(translate_content_to_xhtml(post['content']), type='xhtml') entry.id( id_generator(name='/sdb/{}/{}'.format( board_command, post['time']), ts=post['time'])) master_entry_list.append(entry) new_feeds[board_command] = board_feedgen.atom_str(pretty=True) # Add the entries to the master feed in the right order. for entry in sorted(master_entry_list, key=lambda e: -e.updated().timestamp()): master_feedgen.add_entry(feedEntry=entry) new_feeds['master'] = master_feedgen.atom_str(pretty=True) return new_feeds
def generate_feed(feed_config: FeedModel): rss_feed = FeedGenerator() rss_feed.id(feed_config.url) rss_feed.title(feed_config.name) req = Request(f"{feed_config.url}/navigate", data=None, headers={'User-Agent': UA}) with urlopen(req) as request: soup = BeautifulSoup(request.read(), features="html.parser") rss_feed.author({ 'name': soup.find('a', { 'rel': 'author' }).text, 'email': '*****@*****.**' }) rss_feed.description(soup.find('h2', {'class': 'heading'}).find('a').text) rss_feed.link(href=feed_config.url, rel='alternate') rss_feed.language('en') for chapter in soup.find(id='main').find_all('li'): feed_entry = rss_feed.add_entry() link = urljoin(feed_config.url, chapter.find('a')['href']) time = datetime.strptime( chapter.find(class_='datetime').text, '(%Y-%m-%d)').replace(tzinfo=timezone.utc) title = chapter.find('a').text.strip() feed_entry.id(link) feed_entry.title(title) feed_entry.description(title) feed_entry.link(href=link, rel='alternate') feed_entry.published(time) return rss_feed
# episode length timedelta = datetime.timedelta(milliseconds=int(eaudio['data-duration-in-ms'])) fe.podcast.itunes_duration(timedelta) # episode description is in the first paragraph tag desc = entry.find('p') fe.summary(desc.text) # Get the publication time info etime = entry.find('time', {'class': 'published'}) d = datetime.datetime.strptime(etime['datetime'], '%Y-%m-%d') d = d.replace(tzinfo = pytz.timezone('UTC')) fe.published(d) # Create the FeedGenerator object fg = FeedGenerator() fg.load_extension('podcast') fg.podcast.itunes_category('Science & Medicine','Natural Sciences') fg.id('Mastel Generated: Indefense of Plants') fg.title('In Defense Of Plants') fg.description('It would seem that most people don’t pay any attention to plants unless they are pretty or useful in some way. I reject this reality outright. Plants are everything on this planet. They have this amazing ability to use our nearest star to break apart water and CO2 gas in order to grow and reproduce. From the smallest duckweed to the tallest redwood, the botanical world is full of amazing evolutionary stories. I am here to tell those stories. My name is Matt and I am obsessed with the botanical world. In Defense of Plants is my way of sharing that love with you. ') fg.author({'name': 'Matt Candeias', 'email':'*****@*****.**'}) fg.link(href='https://www.indefenseofplants.com/podcast') fg.logo('https://images.squarespace-cdn.com/content/v1/544591e6e4b0135285aeb5b6/1512588666285-UBKCIK0UFIBDHV2ZFKBU/ke17ZwdGBToddI8pDm48kEnKpXrmwkJNOlSTKwNL29RZw-zPPgdn4jUwVcJE1ZvWQUxwkmyExglNqGp0IvTJZamWLI2zvYWH8K3-s_4yszcp2ryTI0HqTOaaUohrI8PIh4iASq-5YOPh5eoH282P5lK1nuApnfj5Amkpayu2HR4/image-asset.png?format=256w') fg.language('en') # Initalize Selenium binary = r'C:\Program Files\Mozilla Firefox\firefox.exe' options = Options() options.headless = True options.binary = binary
def main(): if len(sys.argv) != 2 or not ( sys.argv[1].endswith('rss') or sys.argv[1].endswith('atom') or sys.argv[1] == 'torrent' or sys.argv[1] == 'podcast'): print(USAGE) exit() arg = sys.argv[1] fg = FeedGenerator() fg.id('http://lernfunk.de/_MEDIAID_123') fg.title('Testfeed') fg.author({'name': 'Lars Kiesow', 'email': '*****@*****.**'}) fg.link(href='http://example.com', rel='alternate') fg.category(term='test') fg.contributor(name='Lars Kiesow', email='*****@*****.**') fg.contributor(name='John Doe', email='*****@*****.**') fg.icon('http://ex.com/icon.jpg') fg.logo('http://ex.com/logo.jpg') fg.rights('cc-by') fg.subtitle('This is a cool feed!') fg.link(href='http://larskiesow.de/test.atom', rel='self') fg.language('de') fe = fg.add_entry() fe.id('http://lernfunk.de/_MEDIAID_123#1') fe.title('First Element') fe.content( '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Tamen aberramus a proposito, et, ne longius, prorsus, inquam, Piso, si ista mala sunt, placet. Aut etiam, ut vestitum, sic sententiam habeas aliam domesticam, aliam forensem, ut in fronte ostentatio sit, intus veritas occultetur? Cum id fugiunt, re eadem defendunt, quae Peripatetici, verba.''') fe.summary(u'Lorem ipsum dolor sit amet, consectetur adipiscing elit…') fe.link(href='http://example.com', rel='alternate') fe.author(name='Lars Kiesow', email='*****@*****.**') if arg == 'atom': print_enc(fg.atom_str(pretty=True)) elif arg == 'rss': print_enc(fg.rss_str(pretty=True)) elif arg == 'podcast': # Load the podcast extension. It will automatically be loaded for all # entries in the feed, too. Thus also for our “fe”. fg.load_extension('podcast') fg.podcast.itunes_author('Lars Kiesow') fg.podcast.itunes_category('Technology', 'Podcasting') fg.podcast.itunes_explicit('no') fg.podcast.itunes_complete('no') fg.podcast.itunes_new_feed_url('http://example.com/new-feed.rss') fg.podcast.itunes_owner('John Doe', '*****@*****.**') fg.podcast.itunes_summary('Lorem ipsum dolor sit amet, consectetur ' + 'adipiscing elit. Verba tu fingas et ea ' + 'dicas, quae non sentias?') fg.podcast.itunes_type('episodic') fe.podcast.itunes_author('Lars Kiesow') fe.podcast.itunes_season(1) fe.podcast.itunes_episode(1) fe.podcast.itunes_title('First podcast episode') fe.podcast.itunes_episode_type('full') print_enc(fg.rss_str(pretty=True)) elif arg == 'torrent': fg.load_extension('torrent') fe.link(href='http://example.com/torrent/debian-8-netint.iso.torrent', rel='alternate', type='application/x-bittorrent, length=1000') fe.torrent.filename('debian-8.4.0-i386-netint.iso.torrent') fe.torrent.infohash('7661229811ef32014879ceedcdf4a48f256c88ba') fe.torrent.contentlength('331350016') fe.torrent.seeds('789') fe.torrent.peers('456') fe.torrent.verified('123') print_enc(fg.rss_str(pretty=True)) elif arg.startswith('dc.'): fg.load_extension('dc') fg.dc.dc_contributor('Lars Kiesow') if arg.endswith('.atom'): print_enc(fg.atom_str(pretty=True)) else: print_enc(fg.rss_str(pretty=True)) elif arg.startswith('syndication'): fg.load_extension('syndication') fg.syndication.update_period('daily') fg.syndication.update_frequency(2) fg.syndication.update_base('2000-01-01T12:00+00:00') if arg.endswith('.rss'): print_enc(fg.rss_str(pretty=True)) else: print_enc(fg.atom_str(pretty=True)) elif arg.endswith('atom'): fg.atom_file(arg) elif arg.endswith('rss'): fg.rss_file(arg)
def make_feed(events, url): from feedgen.feed import FeedGenerator fg = FeedGenerator() fg.id('http://pyvo.cz') fg.title('Pyvo') fg.logo(url_for('static', filename='images/krygl.png', _external=True)) fg.link(href=url, rel='self') fg.subtitle('Srazy Pyvo.cz') for event in events: fe = fg.add_entry() url = filters.event_url(event, _external=True) fe.id(url) fe.link(href=url, rel='alternate') fe.title(event.title) fe.summary(event.description) fe.published(event.start) fe.updated(event.start) # XXX: Put talks into fe.dscription(), # videos in link(..., rel='related') return fg
class TestExtensionSyndication(unittest.TestCase): SYN_NS = {'sy': 'http://purl.org/rss/1.0/modules/syndication/'} def setUp(self): self.fg = FeedGenerator() self.fg.load_extension('syndication') self.fg.title('title') self.fg.link(href='http://example.com', rel='self') self.fg.description('description') def test_update_period(self): for period_type in ('hourly', 'daily', 'weekly', 'monthly', 'yearly'): self.fg.syndication.update_period(period_type) root = etree.fromstring(self.fg.rss_str()) a = root.xpath('/rss/channel/sy:UpdatePeriod', namespaces=self.SYN_NS) assert a[0].text == period_type def test_update_frequency(self): for frequency in (1, 100, 2000, 100000): self.fg.syndication.update_frequency(frequency) root = etree.fromstring(self.fg.rss_str()) a = root.xpath('/rss/channel/sy:UpdateFrequency', namespaces=self.SYN_NS) assert a[0].text == str(frequency) def test_update_base(self): base = '2000-01-01T12:00+00:00' self.fg.syndication.update_base(base) root = etree.fromstring(self.fg.rss_str()) a = root.xpath('/rss/channel/sy:UpdateBase', namespaces=self.SYN_NS) assert a[0].text == base
''' Created on 08.02.2015 @author: Sebastian Gerhards ''' if __name__ == '__main__': pass from feedgen.feed import FeedGenerator from podcast_data_fetcher import PuppetLabsPodcastDataFetcher fg = FeedGenerator() fg.load_extension('podcast') fg.podcast.itunes_category('Technology', 'Podcasting') fg.id('Puppetlabs Podcasts') fg.title('Puppetlabs Podcasts') fg.author({'name': 'Sebastian Gerhards', 'email': '*****@*****.**'}) fg.link(href='http://puppetlabs.com/resources/podcasts', rel='alternate') logo_url = 'http://puppetlabs.com/sites/default/files/puppet-labs-podcast-icon.png' fg.logo(logo_url) fg.subtitle('All Puppet Labs podcast') fg.language('en') f = PuppetLabsPodcastDataFetcher() podcast_urls = f.get_podcast_urls() for podcast_url in podcast_urls:
or sys.argv[1].endswith('atom') \ or sys.argv[1].endswith('podcast') ): print 'Usage: %s ( <file>.atom | atom | <file>.rss | rss | podcast )' % \ 'pythom -m feedgen' print '' print ' atom -- Generate ATOM test output and print it to stdout.' print ' rss -- Generate RSS test output and print it to stdout.' print ' <file>.atom -- Generate ATOM test feed and write it to file.atom.' print ' <file>.rss -- Generate RSS test teed and write it to file.rss.' print ' podcast -- Generator Podcast test output and print it to stdout.' print '' exit() arg = sys.argv[1] fg = FeedGenerator() fg.id('http://lernfunk.de/_MEDIAID_123') fg.title('Testfeed') fg.author( {'name':'Lars Kiesow','email':'*****@*****.**'} ) fg.link( href='http://example.com', rel='alternate' ) fg.category(term='test') fg.contributor( name='Lars Kiesow', email='*****@*****.**' ) fg.contributor( name='John Doe', email='*****@*****.**' ) fg.icon('http://ex.com/icon.jpg') fg.logo('http://ex.com/logo.jpg') fg.rights('cc-by') fg.subtitle('This is a cool feed!') fg.link( href='http://larskiesow.de/test.atom', rel='self' ) fg.language('de') fe = fg.add_entry() fe.id('http://lernfunk.de/_MEDIAID_123#1')
def notices_feed(feed_type): if feed_type not in ["atom", "rss"]: flask.abort(404) url_root = flask.request.url_root base_url = flask.request.base_url feed = FeedGenerator() feed.generator("Feedgen") feed.id(url_root) feed.copyright( f"{datetime.now().year} Canonical Ltd. " "Ubuntu and Canonical are registered trademarks of Canonical Ltd.") feed.title("Ubuntu security notices") feed.description("Recent content on Ubuntu security notices") feed.link(href=base_url, rel="self") def feed_entry(notice, url_root): _id = notice.id title = f"{_id}: {notice.title}" description = notice.details published = notice.published notice_path = flask.url_for(".notice", notice_id=notice.id).lstrip("/") link = f"{url_root}{notice_path}" entry = FeedEntry() entry.id(link) entry.title(title) entry.description(description) entry.link(href=link) entry.published(f"{published} UTC") entry.author({"name": "Ubuntu Security Team"}) return entry notices = (db_session.query(Notice).order_by(desc( Notice.published)).limit(10).all()) for notice in notices: feed.add_entry(feed_entry(notice, url_root), order="append") payload = feed.atom_str() if feed_type == "atom" else feed.rss_str() return flask.Response(payload, mimetype="text/xml")
def generate(query, min_votes): with urllib.request.urlopen( "https://derpibooru.org/search.json?q=upvotes.gte:%d,%s" % (min_votes, query)) as conn: content = conn.read().decode("utf-8") result = json.loads(content) fg = FeedGenerator() fg.id('https://derpibooru.org/search?q=upvotes.gte:%d,%s' % (min_votes, query)) fg.title('Derpibooru (%s with at least %d upvotes)' % (query.replace('+', ' '), min_votes)) fg.link(href='https://derpibooru.org/', rel='alternate') fg.logo('https://derpibooru.org/favicon.ico') fg.language('en') for image in result['search']: fe = fg.add_entry() fe.link(href='https://derpibooru.org/%d' % image['id'], rel='alternate') fe.guid('https://derpibooru.org/%d' % image['id']) fe.pubdate( datetime.datetime.fromtimestamp(time.mktime( time.strptime(image['created_at'].split('.')[0], "%Y-%m-%dT%H:%M:%S")), tz=datetime.timezone.utc)) fe.content('''<img alt="test_pic" src="https:%s" /> Upvotes: %d <br/> %s''' % (image['representations']['thumb'], image['upvotes'], image['description'].replace('[bq]', '<bq>').replace( '[/bq]', '</bq>').replace('\n', '<br/>\n')), type='CDATA') artists = [ tag[0:len('artists:')] for tag in image['tags'].split(', ') if tag.startswith('artists:') ] fe.author({'name': artist for artist in artists}) fe.title(image['tags']) atomfeed = fg.atom_str(pretty=True) return atomfeed
def lambda_handler(event, context): rss = event['rss'] bucket_name = event['bucket'] logging.info("Processing url: %s" % rss) logging.info("Using bucket: %s" % bucket_name) # session = boto3.Config(region_name="us-west-2") polly = boto3.client("polly") s3 = boto3.resource('s3') bucket = s3.Bucket(bucket_name) logging.info("getting list of existing objects in the given bucket") files = set(o.key for o in bucket.objects.all()) feed = feedparser.parse(rss) title = feed['feed']['title'] fg = FeedGenerator() fg.load_extension('podcast') fg.title('Audio podcast based on: %s' % title) fg.link(href=feed.feed.link, rel='alternate') fg.subtitle(feed.feed.description) ENTRY_URL = "http://s3-{region}.amazonaws.com/{bucket}/{filename}" for entry in get_entries(feed): filename = "%s.mp3" % entry['id'] fe = fg.add_entry() fe.id(entry['id']) fe.title(entry['title']) fe.published(entry['published']) entry_url = ENTRY_URL.format( bucket=bucket_name, filename=filename, region=os.environ["AWS_REGION_BUCKET"] ) fe.enclosure(entry_url, 0, 'audio/mpeg') if filename in files: logging.info('Article "%s" with id %s already exist, skipping.' % (entry['title'], entry['id'])) continue try: logging.info("Next entry, size: %d" % len(entry['content'])) logging.debug("Content: %s" % entry['content']) response = polly.synthesize_speech( Text=entry['content'], OutputFormat="mp3", VoiceId="Joanna" ) with closing(response["AudioStream"]) as stream: bucket.put_object(Key=filename, Body=stream.read()) except BotoCoreError as error: logging.error(error) bucket.put_object(Key='podcast.xml', Body=fg.rss_str(pretty=True))
def rss(): fg = FeedGenerator() fg.id('http://shockham.com/') fg.title('shockham.') fg.author({'name': 'shockham', 'email': ''}) fg.link(href='http://shockham.com', rel='alternate') fg.logo(url_for('static', filename='images/new_logo.png')) fg.subtitle('RSS feed for shockhams site!') fg.link(href='http://shockham.com/rss', rel='self') fg.language('en') concepts = Concept.objects(Q(slug__ne='none') & Q(parent__ne='none')) for concept in concepts: fe = fg.add_entry() fe.id('http://shockham.com/' + concept.slug) fe.title(concept.title) response = make_response(fg.rss_str(pretty=True)) response.headers["Content-Type"] = "application/xml" return response
for i in range(1, len(text_splitted)): srl = text_splitted[i].split('">')[0].split('#comment')[0] if (is_number(srl) and srl not in srl_arr): # second statement : to prevent duplication srl_arr.append(srl) if (srl not in num): count_new += 1 f.write(',' + srl) print('New post found : ' + srl) f.close() if (count_new != 0): print('Started generating feed...') # make FeedGenerator fg = FeedGenerator() fg.id('asdf') fg.title('SNU Physics Board RSS feed - notices') fg.author({'name': 'Seungwon Park', 'email': 'yyyyy at snu dot ac dot kr'}) fg.link(href='asdf') fg.subtitle('SNU Physics Board RSS - notices') fg.language('ko') for srl in srl_arr: print('Parsing post #' + srl + '...') fe = fg.add_entry() fe.id(baseurl + srl) fe.title(post_title(srl)) fe.author({'name': post_author(srl), 'email': 'unknown'}) fe.link(href=baseurl + srl) atomfeed = fg.atom_str(pretty=True)
def __call__(self, value, system): feed = FeedGenerator() feed.id(system["request"].url) feed.title(value["title"]) feed.description("Log Cabin") feed.link(rel="self", href=system["request"].url) feed.language("en") if system["renderer_name"] == "atom": feed.link([ {"rel": "alternate", "type": content_type, "href": url} for content_type, url in system["request"].extensions ]) for entry in value["entries"]: feed.add_entry(entry) system["request"].response.headers["Content-type"] = extension_content_types[system["renderer_name"]] + "; charset=UTF-8" if system["renderer_name"] == "rss": return feed.rss_str(pretty=True) else: return feed.atom_str(pretty=True)
def create_podcast_from_channel(url, podcast_root_url, items_to_process): feed = feedparser.parse(url) fg = FeedGenerator() fg.load_extension('podcast') fg.title(feed['channel']['title']) fg.link(href=feed['channel']['href'], rel='alternate') fg.description('Audio tracks from YouTube Channel "{}"'.format(feed['channel']['title'])) # fg.image(url=feed.image.href, width=feed.image.width, height=feed.image.height) output_dir = '/y2p/output' for item in feed['items'][:items_to_process]: sys.stdout.write(item['link'] + '\n') our_id = hashlib.md5(item['link'].encode()).hexdigest() audio_fname = our_id + '.m4a' audio_fullpath = os.path.join(output_dir, audio_fname) if not os.path.exists(audio_fullpath): create_audio_file(audio_fullpath, our_id, item['link']) p_entry = fg.add_entry() p_entry.id(item['id']) p_entry.title(item['title']) p_entry.description(item['summary']) p_entry.enclosure(podcast_root_url + '/' + audio_fname, 0, 'audio/m4a') p_entry.published(item['published']) fg.rss_str(pretty=True) fg.rss_file(os.path.join(output_dir, 'feed.xml'))