def export_feed(self, output): fg = FeedGenerator() fg.load_extension('podcast') fg.podcast.itunes_category('Religion & Spirituality', 'Christianity') fg.podcast.itunes_image("%s/icon.png" % URL_BASE) fg.title('JW.ORG Magazines') fg.description('Combined Feed of Watchtower (public), Watchtower (study), and Awake! in English from jw.org.') fg.link(href="%s/%s" % (URL_BASE, output), rel='self') manifest = self._load() entries = [] for lang, mnemonics in manifest.items(): for mnemonic, issues in mnemonics.items(): for issue, data in issues.items(): entries.append((issue, data)) for issue, entry in sorted(entries, key=lambda i: i[0], reverse=True): fe = fg.add_entry() fe.id( entry['hash'] ) fe.title( entry['title'] ) fe.description( entry['title'] ) fe.published( pytz.utc.localize( entry['created_on'] ) ) url = "%s/%s" % (URL_BASE, os.path.basename(entry['file'])) mime = 'audio/mpeg' fe.enclosure(url, str(entry['duration']), mime) fe.link(href=url, type=mime) fg.rss_str(pretty=True) fg.rss_file(os.path.join(CACHE_DIR, output))
def run(folder, url): from feedgen.feed import FeedGenerator fg = FeedGenerator() head, tail = os.path.split(folder) title = tail.decode("utf-8") fg.id(str(uuid.uuid4())) fg.title(title) fg.link(href="{0}/rss.xml".format(url), rel="self") fg.description(u"Audiobook `{0}` generated with rssbook".format(title)) fg.load_extension("podcast") for item in sorted(os.listdir(folder)): if os.path.splitext(item)[1] == ".mp3": get_node(os.path.join(folder, item)) fullpath = os.path.join(folder, item) fe = fg.add_entry() fe.id(str(uuid.uuid4())) fe.title(title) fe.description(item) fe.link( href="{0}/{1}".format(url, item), rel="enclosure", type="audio/mpeg", length=str(os.stat(fullpath).st_size) ) fg.rss_file(os.path.join(folder, "rss.xml"))
def gen_feed(user, base_url, path, debug=False): # Create feed feed = FeedGenerator() feed.id(urlparse.urljoin(base_url, user + '.xml')) feed.title('Snapchat story for ' + user) feed.link( href=urlparse.urljoin(base_url, user + '.xml'), rel='self' ) feed.language('en') feed.description('Snapchat media') # Iterate through files in path, sort by unix timestamp (newest first), then add to feed files = sorted(os.listdir(path), reverse=True) for filename in files: split = filename.split('~') if split[0] != user: continue if os.path.splitext(filename)[1] in ['.mp4', '.jpg']: entry = feed.add_entry() entry.id(urlparse.urljoin(base_url, filename)) entry.link(href=urlparse.urljoin(base_url, filename)) entry.title(filename) # Write feed to disk feed.rss_file(os.path.join(path, user + '.xml')) date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") if debug: print('{0} Regenerated {1}'.format(date, urlparse.urljoin(base_url, user + '.xml')))
def write_podcast(show, podcast_dir, base_public_url, showlocal_tz): """Create the podcast file.""" fg = FeedGenerator() fg.load_extension('podcast') url = "{}{}.xml".format(base_public_url, show.id) fg.id(url.split('.')[0]) fg.title(show.name) fg.image(show.image_url) fg.description(show.description) fg.link(href=url, rel='self') # collect all mp3s for the given show all_mp3s = glob.glob(os.path.join(podcast_dir, "{}_*.mp3".format(show.id))) for filepath in all_mp3s: filename = os.path.basename(filepath) mp3_date = _get_date_from_mp3_path(filepath, showlocal_tz) mp3_size = os.stat(filepath).st_size mp3_url = base_public_url + filename mp3_id = filename.split('.')[0] title = "Programa del {0:%d}/{0:%m}/{0:%Y}".format(mp3_date) # build the rss entry fe = fg.add_entry() fe.id(mp3_id) fe.pubdate(mp3_date) fe.title(title) fe.enclosure(mp3_url, str(mp3_size), 'audio/mpeg') fg.rss_str(pretty=True) fg.rss_file(os.path.join(podcast_dir, '{}.xml'.format(show.id)))
def main(): session = vk.Session() api = vk.API(session) group_id = '96469126' group_info = api.groups.getById(group_ids=group_id, fields=['description', 'site', 'name', 'photo', 'gid']) assert len(group_info) == 1 group_info = group_info[0] url = 'http://vk.com/club{}'.format(group_info['gid']) # a = api.wall.get(owner_id=-1 * group_info['gid']) # # with open('out', 'wb') as fio: # pickle.dump(a, fio) with open('out', 'rb') as fio: data = pickle.loads(fio.read()) assert len(data) > 1 fg = FeedGenerator() fg.id(url) fg.title(_(group_info['name'])) fg.description(_(group_info['description'])) fg.logo(group_info['photo']) site_url = group_info.get('site', url) if group_info.get('site', url) else url fg.link(href=_(site_url)) fg.link(href=_(site_url), rel='self') fg.link(href=_(site_url), rel='alternate') fg.author({'name': 'Alexander Sapronov', 'email': '*****@*****.**'}) fg.webMaster('[email protected] (Alexander Sapronov)') pat = re.compile(r"#(\w+)") for x in data[1:]: post_link = "{}?w=wall-{}_{}".format(url, group_info['gid'], x['id']) e = fg.add_entry() # text = x.get('text', '').replace('<br>', '\n') text = x.get('text', '') e.description(_(text)) e.author({'name': _(get_author_name(api, x.get('from_id')))}) e.id(post_link) e.link(href=_(post_link)) e.link(href=_(post_link), rel='alternate') tags = pat.findall(text) title = x.get('text', '') for tag in tags: e.category(term=_(tag)) title = title.replace('#{}'.format(tag), '') title = re.sub('<[^<]+?>', ' ', title) title = textwrap.wrap(title, width=80)[0] e.title(_(title.strip())) fg.rss_file('rss.xml')
class YoutubeFeed: ydl_opts = { 'format': 'bestaudio/best', 'outtmpl': '%(id)s.%(ext)s', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }] } 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 add_video(self, url): info = self.ydl.extract_info(url, download=True) entry = self.fg.add_entry() entry.id(info['id']) entry.title(info['title']) entry.description(info['description']) entry.enclosure(info['id'] + ".mp3", str(info['duration']), 'audio/mpeg') def save(self): self.fg.rss_file(name + '.xml')
def generate_feed(output_file, exclude_highlights=True): # Parse RSS feed d = feedparser.parse(ESPN_RSS_FEED) IMAGE_URL = d.feed.image["href"] # RSS feed generation fg = FeedGenerator() fg.load_extension("podcast", rss=True) ## RSS tags # Required fg.title(d.feed.title) fg.link(href="https://github.com/aaearon/lebatard-show-rss") fg.description(d.feed.description) # Optional fg.language(d.feed.language) fg.image(IMAGE_URL) fg.subtitle(d.feed.subtitle) # iTunes fg.podcast.itunes_author(d.feed.author) fg.podcast.itunes_category(itunes_category=d.feed.category) fg.podcast.itunes_image(itunes_image=IMAGE_URL) fg.podcast.itunes_explicit(itunes_explicit="clean") fg.podcast.itunes_owner(name=CONTACT["name"], email=CONTACT["email"]) tz = pytz.timezone("America/Los_Angeles") for e in d.entries: if exclude_highlights and episode_duration_string_to_int(e["itunes_duration"]) > 3600: pass else: fe = fg.add_entry() fe.id(e.id) fe.title(e.title) fe.description(e.description) fe.enclosure(url=e.enclosures[0]["href"], length=e.enclosures[0]["length"], type=e.enclosures[0]["type"]) fe.podcast.itunes_summary(e.description) fe.podcast.itunes_subtitle(e.description) fe.podcast.itunes_duration(e["itunes_duration"]) dt = datetime.fromtimestamp(time.mktime(e.published_parsed)) date = tz.localize(dt) # Local hour if "Show: " in e.title: fe.published(date) elif "Hour 1" in e.title: fe.published(date + timedelta(hours=1)) elif "Hour 2" in e.title: fe.published(date + timedelta(hours=2)) elif "Hour 3" in e.title: fe.published(date + timedelta(hours=3)) else: fe.published(date + timedelta(hours=-1)) fg.rss_str(pretty=True) fg.rss_file(output_file)
def build(): global fg fg = FeedGenerator() fg.title(parser.get('technowatch', 'name')) fg.language('en') fg.description(parser.get('technowatch', 'name')) fg.link(href=parser.get('technowatch', 'link'), rel='alternate') # Cleaning stories if too much if len(known_stories) > int(parser.get('technowatch', 'cache_max')): clean() # Sorting stories by crawled date for item in sorted(known_stories.values(), key=operator.itemgetter('crawledDate'), reverse=True): fe = fg.add_entry() fe.link(href=item['url'], rel='alternate') fe.title("[" + item['type'] + "] " + item['title']) fe.category({ 'label': item['type'], 'term': item['type'] }) fe.author({'name': item['by']}) fe.description(item['desc']) fe.pubdate(item['crawledDate']) # Caching RSS building pickle.dump(known_stories, open(cust_path + "/technowatch.data", "wb")) if parser.get('wsgi', 'activated') == "True": fg.rss_file(cust_path + '/static/rss.xml') if parser.get('ftp', 'activated') == "True": upload()
def rss(conversation, url, author_name, author_email, title, subtitle, language, output_path): """Export all the links of the conversation in a simple RSS feed""" from feedgen.feed import FeedGenerator fg = FeedGenerator() fg.id(url) fg.title(title) fg.author( { 'name': author_name, 'email': author_email, } ) fg.link( href=url, rel='alternate' ) if subtitle: fg.subtitle(subtitle) fg.language(language) for message in conversation.history(): match = re.search( "^.*<(?P<url>[^>|]+)\|?(?P<title>[^>]+)?>.*$", message.data["text"], flags=re.MULTILINE ) if match is not None: fe = fg.add_entry() link = match.group("url") title = match.group("title") or link date = naive_to_local(datetime.datetime.fromtimestamp(float(message.data["ts"]))) description = message.data["text"] if "attachments" in message.data: attachment = [a for a in message.data["attachments"] if a["title_link"] == link][0] title += " | " + attachment["title"] description += """ """ + attachment["text"] fe.id(link) fe.title(title) fe.link(href=link) fe.published(date) user = config.slack.get_user(message.data["user"]) author = { "name": message.data["username"], "email": user.email or "noemail", } fe.author(author) fe.description(description) fg.rss_file(output_path, 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 listen_for_urls(self, msg, match): url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', str(msg)) p = re.compile('\/(.*)') user = re.search(p, str(msg.getFrom())).group()[1:] if len(url) == 1: url = str(url[0]) filename = '/mnt/extern1/SYSTEM/www/foorss/' + user + '.xml' fg = FeedGenerator() # Some pages block urllib2 so we need a fake user agent header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'Accept-Encoding': 'none', 'Accept-Language': 'en-US,en;q=0.8', 'Connection': 'keep-alive'} req = urllib2.Request(url, headers=header) try: soup = BeautifulSoup(urllib2.urlopen(req)) except urllib2.HTTPError, e: print e.fp.read() yield "Error while parsing the website..." if os.path.isfile(filename): fg.from_rss(filename) else: fg.id(user) fg.title('Some Testfeed') fg.link( href='http://nix.da', rel='alternate' ) fg.description('This is a cool feed!') if soup.title != None: title = soup.title.string else: title = url fe = fg.add_entry() fe.id(url) fe.title(title) fe.description('Description') fe.link([{'href': url}]) fg.rss_file(filename) yield title + ' from ' + user + ' (rss updated)'
def make_rss(user, link=False): api = twitter.Api(**secrets) if link: filename = os.path.join(os.path.dirname(__file__), 'rss', user + '_links.rss') try: statuses = [s for s in api.GetUserTimeline(None, user, count=50) if len(s.urls) > 0] except twitter.TwitterError as e: return str(e), 404 else: filename = os.path.join(os.path.dirname(__file__), 'rss', user + '.rss') try: statuses = api.GetUserTimeline(None, user) except twitter.TwitterError as e: return str(e), 404 if len(statuses) == 0: return "No Tweets", 416 fg = FeedGenerator() fg.title(user + ' on twitter') fg.description('RSS feed from a twitter stream') fg.link(href='http://twitter.com/' + statuses[0].GetUser().screen_name, rel='self') for status in statuses: fe = fg.add_entry() fe.title(status.GetUser().screen_name+': '+status.GetText()) statusurl = 'http://twitter.com/' + statuses[0].GetUser().screen_name + '/status/' + status.GetIdStr() fe.guid(statusurl) fe.pubdate(status.created_at) fe.link(href=statusurl, rel='alternate') if link: #fe.link(href=status.urls[0].expanded_url, rel='alternate') urlsummary = '<br/> <ul>' for url in status.urls: urlsummary += '<a href="{0}">{0}</a> <br/>'.format(url.expanded_url) urlsummary += '</ul>' fe.summary(status.GetText() + '\n' + urlsummary) else: fe.summary(status.GetText()) fg.rss_file(filename) return fg.rss_str()
def generate_rss(pages_info=None): fg = FeedGenerator() fg.id(conf['base_url']) fg.title(conf['title']) fg.author( {'name':conf['author'],'email':conf['email']} ) fg.link( href=conf['base_url'], rel='alternate' ) fg.subtitle(conf['description']) fg.link( href=conf['base_url']+'/rss.xml', rel='self' ) fg.language('en') for post in pages_info: fe = fg.add_entry() fe.id('http://blog.elijahcaine.me/'+post['url']) fe.title(post['title']) fe.author( {'name':conf['author'],'email':conf['email']} ) fe.link( href=conf['base_url']+post['url'], rel='alternate' ) fe.description( post['content']['fragment'] ) rssfeed = fg.rss_str(pretty=True) fg.rss_file('build/'+conf['rss_feed']) return rssfeed
def generate_feed(posts): author = {'name': config['default']['author'], 'email': config['default']['email']} fg = FeedGenerator() fg.id('http://%s/rss.xml' % config['default']['domain']) fg.title('%s RSS Feed' % config['default']['domain']) fg.author(author) fg.link(href='http://%s' % config['default']['domain'], rel='alternate') fg.language('en') fg.description('%s RSS Feed' % config['default']['domain']) for post in posts[:10]: fe = fg.add_entry() fe.id('http://%s/posts/%s.html' % (config['default']['domain'], post.slug)) fe.title(post.title) fe.content(content=post.body, type='html') fe.author(author) rssfeed = fg.rss_str(pretty=True) fg.rss_file(os.path.join(config['default']['site_path'], 'rss.xml'))
def export_rss(list_of_updated_groups): print "\nBeginning RSS feed generation." print "Updated groups are:" print list_of_updated_groups for updated_group in list_of_updated_groups: rss_file_path = os.getcwd() + "/static/rss/" + updated_group + ".xml" fg = FeedGenerator() fg.title("VTS Raspored - Grupa " + updated_group) fg.author( {'name':'Veselin Romic','email':'*****@*****.**'} ) fg.language('sr') fg.description("Automatski se salje notifikacija kad se promeni grupni raspored.") fg.link(href='https://eref.vts.su.ac.rs/') new_entry = fg.add_entry() new_entry.title("RASPORED PROMENJEN - " + str(datetime.datetime.now())) new_entry.description("Proverite eref da biste videli promene.") new_entry.link(href='https://eref.vts.su.ac.rs/') if os.path.isfile(rss_file_path): current_feed = feedparser.parse(rss_file_path) items_transferred = 0 for existing_list_item in current_feed["items"]: if items_transferred >= 9: break transferred_entry = fg.add_entry() transferred_entry.title(existing_list_item["title"]) transferred_entry.description("Proverite eref da biste videli promene.") transferred_entry.link(href='https://eref.vts.su.ac.rs/') items_transferred += 1 fg.rss_file(rss_file_path, pretty=True) print "Updated RSS feed /static/rss/%s.xml" % updated_group
def createFeed(links, titles): # feed dosyasini olustur fg = FeedGenerator() fg.load_extension("podcast") fg.id("http://twitter.com/dorukcankisin") fg.title(DIZI_TITLE) fg.author({"name": "dorukcan kisin", "email": "*****@*****.**"}) fg.link(href="http://twitter.com/dorukcankisin", rel="alternate") fg.logo(DIZI_LOGO) fg.subtitle(DIZI_TITLE + " videocast") fg.language("en") for i, url in enumerate(links): fe = fg.add_entry() fe.id(url) fe.enclosure(url, 0, "video/mp4") fe.title(titles[i]) fe.description(titles[i]) fg.rss_file("rss.xml") 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 make_feed(filename='epistles.xml'): fg = FeedGenerator() fg.title('Daily Epistles') fg.author({'name': 'Tim Hopper'}) fg.subtitle('Listen to the New Testament epistles each month.') fg.language('en') fg.link(href='http://www.crossway.com', rel='alternate') for day, division in enumerate(get_divisons(), 1): entry = fg.add_entry() entry.id(division) entry.title(division) pubdate = datetime.datetime(year=datetime.datetime.now().year, month=datetime.datetime.now().month, day=day, hour=pubhour, tzinfo=tz) entry.published(pubdate) entry.enclosure(get_url(division), 0, 'audio/mpeg') fg.rss_str(pretty=True) fg.rss_file('epistles.xml')
def generate_feed(input_file, output_file): fg = FeedGenerator() fg.load_extension('podcast', rss=True) ## RSS tags # Required fg.title(TITLE) fg.link(href=LINK) fg.description(DESCRIPTION) # Optional fg.language('en') fg.image(url=IMAGE_URL, title=TITLE, link=LINK) fg.ttl(720) fg.webMaster(CONTACT['name']) now = datetime.datetime.now() tz = pytz.timezone('Europe/Amsterdam') fg.pubDate(tz.localize(now)) # iTunes fg.podcast.itunes_author('Dan LeBatard') fg.podcast.itunes_category(itunes_category='Sports & Recreation', itunes_subcategory='Professional') fg.podcast.itunes_image(itunes_image=IMAGE_URL) fg.podcast.itunes_explicit(itunes_explicit='clean') fg.podcast.itunes_owner(name=CONTACT['name'], email=CONTACT['email']) # Add items items = read_items(input_file) for item in items: fe = fg.add_entry() ## RSS tags fe.id(item['guid']) fe.title(item['title']) fe.description(item['description']) fe.enclosure(item['link'], 0, 'audio/mpeg') fe.pubdate(item['pubDate']) # Finish off the file fg.rss_str(pretty=True) fg.rss_file(output_file)
def get_feed(db): fg = FeedGenerator() fg.id('http://www.academis.eu/feed') fg.title('Academis Blog') fg.author( {'name':'Kristian Rother','email':'*****@*****.**'} ) fg.link( href='http://www.academis.eu', rel='alternate' ) fg.logo('http://www.academis.eu/static/images/academis_kr350.png') fg.subtitle('Articles on Python programming, Data analysis and Leadership in tech') fg.link( href='http://www.academis.eu/academis.atom', rel='self' ) fg.language('en') fg.contributor( name='Kristian Rother', email='*****@*****.**' ) for title, slug in get_all_posts(db): title, content = get_post(db, slug) fe = fg.add_entry() fe.id('http://www.academis.eu/posts/{}'.format(slug)) fe.link(href='http://www.academis.eu/posts/{}'.format(slug)) fe.title(title) fe.description(content[:300]) rssfeed = fg.rss_str(pretty=True) fg.rss_file('rss.xml') # Write the RSS feed to a file return rssfeed
def makePassThroughRss(self): fg = FeedGenerator() fg.load_extension('podcast') fg.id('http://hypecast.blackmad.com/' + self.mode) fg.title('Hype Machine PassThru Radio: ' + self.mode) fg.author( {'name':'David Blackmad','email':'*****@*****.**'} ) fg.logo('http://themelkerproject.com/wp-content/uploads/2013/10/the-hype-machine.jpg') fg.language('en') fg.link(href='http://hypecast.blackmad.com/' + self.mode) fg.description('Hype Machine PassThru: ' + self.mode) # description = '<br/>'.join(['%s. %s' % (index + 1, self.mk_song_id(s)) for index, s in enumerate(self.songs)]) for s in self.songs: fe = fg.add_entry() fe.title(self.mk_song_id(s)) fe.id(s['mediaid']) fe.description(s['description']) fe.podcast.itunes_image(s['thumb_url']) # add length fe.enclosure(url = 'http://hypecast.blackmad.com/%s/%s' % ('hypecasts', s['filename']), type="audio/mpeg") podcast_xml_file = os.path.join(self.output_dir, 'podcast.xml') fg.rss_file(podcast_xml_file)
def create_mixed_feed(remix_feed, location, output_dir, just_rss=False): """Create an rss feed for mixed sessions. location is the hostname and folder, like 'http://abc.com/remix/ output_dir is the folder to write mixed sessions to """ fg = FeedGenerator() fg.load_extension('podcast') fg.id(location) fg.title(remix_feed.title) fg.subtitle('this is only a remix') fg.link(href=os.path.join(location, 'rss.xml'), rel='self') if os.path.exists(output_dir): if not just_rss: print('output directory exists, overwriting...') shutil.rmtree(output_dir) os.mkdir(output_dir) else: os.mkdir(output_dir) for remix in remix_feed.sessions: fe = fg.add_entry() if not just_rss: mixed = mix_session(remix) mixed.export(os.path.join(output_dir, with_mp3_ext(remix.title)), format='mp3') fe.id(os.path.join(location, urlparse.quote(with_mp3_ext(remix.title)))) fe.title(remix.title) fe.description(remix.description) fe.enclosure(os.path.join(location, urlparse.quote(with_mp3_ext(remix.title))), 0, 'audio/mpeg') fg.rss_file(os.path.join(output_dir, 'rss.xml'), pretty=True)
with open(PUBLIC_DIR + "/" + "index.html", 'w') as index: index.write(assembled_index_html) # ----------------------------------------------- # copy media directory to public post directory # ----------------------------------------------- if os.path.exists(PUBLIC_MEDIA_DIR): rmtree(PUBLIC_MEDIA_DIR) copytree(MD_MEDIA_DIR, PUBLIC_MEDIA_DIR) # ------------------------------------------------------------ # copy css files from template directory to public directory # ------------------------------------------------------------ copyfile(GLOBAL_CSS_TEMPLATE, PUBLIC_DIR + "/styles.css") copyfile("templates/pygments/pastie.css", PUBLIC_DIR + "/pastie.css") copyfile("templates/pygments/monokai.css", PUBLIC_DIR + "/monokai.css") # ----------------------- # save rss / atom files # ----------------------- fg.atom_file(PUBLIC_DIR + '/atom.xml') fg.rss_file(PUBLIC_DIR + '/rss.xml') # ---------------------------------------------------------- # copy public directory to docs directory for github pages # comment out or remove if you aren't using gh-pages # ---------------------------------------------------------- if os.path.exists('docs'): rmtree('docs') copytree(PUBLIC_DIR, 'docs')
file_size = os.path.getsize(track) # Remove the disk and track numbers from the file names and use just the # title as the episode name track_filename = os.path.basename(track) track_name_raw = re.match(r"\d-\d{2} (.*)\.mp3", track_filename) track_name = track_name_raw.group(1) # Get the duration audio = MP3(track) m, s = divmod(audio.info.length, 60) # Convert seconds to h:m:s h, m = divmod(m, 60) if h == 0: duration = "%02d:%02d" % (m, s) else: duration = "%d:%02d:%02d" % (h, m, s) # Generate entry fe = fg.add_entry() fe.guid(base_url + track_filename) fe.link({'href': base_url + track_filename}) fe.title(track_name) fe.description(track_name) fe.published(episode_date) fe.enclosure(base_url + track_filename, str(file_size), 'audio/mpeg') fe.podcast.itunes_order(i + 1) fe.podcast.itunes_duration(duration) # Write the feed to a file fg.rss_file(feed_name, pretty=True)
fg.description(res.title) fg.logo(res.user['avatar_url']) fg.author({'name': res.user['username']}) else: raise Exception('unknown kind %s' % res.kind) # print('🎧 ', res.permalink) tracks = client.get(res.uri + '/tracks', limit=200) fg.link(href=res.permalink_url, rel='alternate') for track in tracks: date = parser.parse(track.created_at) if (now - date).days > MAX_AGE_DAYS: continue file_name = download(track) if not file_name: continue fe = fg.add_entry() fe.id(track.permalink_url) fe.title(track.title) fe.description(clean_xml(track.description)) fe.published(date) url = BASE_URL + '/tracks/' + file_name mime_type = mimetypes.guess_type(file_name)[0] fe.enclosure(url, str(track.original_content_size), mime_type) fg.rss_file('%s/%s.xml' % (OUTPUT_DIR, res.permalink), pretty=True)
# 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?') fe.podcast.itunes_author('Lars Kiesow') print_enc(fg.rss_str(pretty=True)) elif arg == 'dc.atom': fg.load_extension('dc') fg.dc.dc_contributor('Lars Kiesow') fe.dc.dc_contributor('Lars Kiesow') print_enc(fg.atom_str(pretty=True)) elif arg == 'dc.rss': fg.load_extension('dc') fg.dc.dc_contributor('Lars Kiesow') print_enc(fg.rss_str(pretty=True)) elif arg.endswith('atom'): fg.atom_file(arg) elif arg.endswith('rss'): fg.rss_file(arg)
yt_feed = feedparser.parse( f'https://www.youtube.com/feeds/videos.xml?channel_id={yt_channel_id}') yt_videos_list = yt_feed.entries yt_account_username = yt_videos_list[0].author_detail.name yt_channel_url = yt_videos_list[0].author_detail.href fg = FeedGenerator() fg.title(yt_account_username) fg.description(yt_account_username) fg.link(href=yt_channel_url) for video in yt_videos_list[:max_videos_per_channel]: try: yt_video_url = download_yt_video(video.link) except: yt_video_url = video.link yt_video_title = video.title yt_video_id = video.yt_videoid yt_video_publish_time = video.published fe = fg.add_entry() fe.id(yt_video_url) fe.title(yt_video_title) fe.link(href=yt_video_url) fe.pubDate(yt_video_publish_time) os.chdir('../../public_html/yt_rss_feeds') fg.rss_file(f'feeds/{yt_channel_id}.xml')
feedEntry = feed.add_entry() feedEntry.title(entry['title']) feedEntry.link(href=entry['link']) feedEntry.description(entry['description']) feedEntry.pubDate(entry['pubDate']) if __name__ == '__main__': os.makedirs('dist', exist_ok=True) if sys.argv[1] == 'dmzj': feed.title('动漫之家新闻') feed.description('动漫之家新闻RSS') feed.link(href='http://news.dmzj.com') feed.logo( 'https://cdn.jsdelivr.net/gh/Apocalypsor/My-Feeds/assets/dmzj.ico') addEntry(dmzj.main()) feed.rss_file('dist/dmzj.xml') if sys.argv[1] == 'acg178': feed.title('178动漫') feed.description('178动漫RSS') feed.link(href='https://acg.178.com/') feed.logo( 'https://cdn.jsdelivr.net/gh/Apocalypsor/My-Feeds/assets/acg178.ico' ) addEntry(acg178.main()) feed.rss_file('dist/acg178.xml')
def main(): all_tags = {} post_data = [] for post in get_posts(): out_file = post[len('posts/'):] output, title = get_post_data(post) header, date, tags_raw = title[1], title[2], title.get(6, "") tags = tags_raw.split(",") tags_html = get_html_tags(tags) post_data.append((out_file, title[1], title[2], post, output)) for tag in tags: if tag not in all_tags: all_tags[tag] = [] all_tags[tag].append((out_file, title[1], title[2])) title = title[1] with open('dist/' + out_file, 'w') as f: f.write( TEMPLATE.format(post=output, title=title, subtitle=date, tag=title, tags=tags_html)) post_data.sort(key=lambda post: datetime.strptime(post[2], '%B %d, %Y')) post_data.reverse() home_page = HOME_PAGE home_page += "\n".join([POST_SUMMARY.format(*args) for args in post_data]) with open('dist/index.html', 'w') as f: f.write( TEMPLATE.format(post=home_page, title="", tag=TAG, subtitle="", tags="")) with open('dist/style.css', 'w') as fw: with open('style.css') as fr: fw.write(fr.read()) fg = FeedGenerator() for url, title, date, post, content in reversed(post_data): fe = fg.add_entry() fe.id('http://notes.eatonphil.com/' + url) fe.title(title) fe.link(href='http://notes.eatonphil.com/' + url) fe.pubDate( datetime.strptime(date, '%B %d, %Y').replace(tzinfo=timezone.utc)) fe.content(content) fg.id('http://notes.eatonphil.com/') fg.link(href='http://notes.eatonphil.com/') fg.title(TAG) fg.description(TAG) fg.author(name='Phil Eaton', email='*****@*****.**') fg.language('en') fg.rss_file('dist/rss.xml') if not os.path.exists('dist/tags'): os.makedirs('dist/tags') for tag in all_tags: posts = all_tags[tag] with open('dist/tags/%s.html' % tag, 'w') as f: posts.sort( key=lambda post: datetime.strptime(post[2], '%B %d, %Y')) posts.reverse() tag_page = TAG_PAGE.format(tag) tag_page += "\n".join( [POST_SUMMARY.format(*args) for args in posts]) f.write( TEMPLATE.format(post=tag_page, title="", tag=TAG, subtitle="", tags=""))
from feedgen.feed import FeedGenerator fg = FeedGenerator() fg.load_extension('podcast') # Meta fg.id('http://podcast.writethedocs.org/') fg.title('Write the Docs Podcast') fg.author({'name': 'Eric Holscher', 'email': '*****@*****.**'}) #fg.link(href='', rel='alternate') fg.logo('http://conf.writethedocs.org/img/stickers/sticker-wtd-colors.png') fg.subtitle('All things documentation') fg.link(href='http://podcast.writethedocs.org/rss.xml', rel='self') fg.language('en') # Podcast Meta fg.podcast.itunes_category('Technology') fg.podcast.itunes_image('http://conf.writethedocs.org/img/stickers/sticker-wtd-colors.png') fg.podcast.itunes_owner(name='Eric Holscher', email='*****@*****.**') fg.podcast.itunes_summary('A podcast about all things documentation') # Entries fe = fg.add_entry() fe.id('http://podcast.writethedocs.org/episodes/heidi-waterhouse.html') fe.title('Episode One: Heidi Waterhouse') fe.enclosure(url='') # Write fg.rss_str(pretty=True) fg.rss_file('rss.xml')
reverse=True, key=lambda pair: pair[0])) write_index(files.values()) in_feed = sorted(files.values(), reverse=True, key=lambda item: item.date)[0:10] for item in in_feed: fe = fg.add_entry() full_url = feed_root + url_of(item) fe.id(full_url) fe.link(href=full_url, rel='alternate') fe.title(item.title) fe.content(markdown(item.content)) fe.updated(tz.localize(datetime.fromtimestamp(item.mtime))) fe.published(tz.localize(datetime.fromtimestamp(item.mtime))) os.makedirs('out/feed/atom') os.makedirs('out/feed/rss') fg.atom_file('out/feed/atom/index.xml') fg.rss_file('out/feed/rss/index.xml') fg.rss_file('out/feed/index.xml') for static in ['main.css']: with open_out('static/' + static) as f: f.write(slimmer.css_slimmer(templates.get_template(static).render())) shutil.copytree('images', 'out/images')
fg.subtitle('The official podcast of the Satoshi Nakamoto Institute') fg.language('en') fg.copyright('cc-by-sa') fg.podcast.itunes_summary('Michael Goldstein and Daniel Krawisz of the Satoshi Nakamoto Institute discuss Bitcoin, economics, and cryptography.') fg.podcast.itunes_owner('Michael Goldstein', '*****@*****.**') fg.link( href='http://nakamotoinstitute.org/podcast/feed/', rel='self' ) fg.podcast.itunes_explicit('no') fg.image('http://nakamotoinstitute.org/static/img/cryptomises/cmpodcast_144.jpg') fg.podcast.itunes_image('http://nakamotoinstitute.org/static/img/cryptomises/cmpodcast_1440.jpg') fg.podcast.itunes_category('Technology', 'Tech News') eps = Episode.query.order_by(desc(Episode.date)).all() for ep in eps: fe = fg.add_entry() fe.id('http://nakamotoinstitute/podcast/'+ep.slug+'/') fe.title(ep.title) fe.podcast.itunes_summary(ep.summary + ' If you enjoyed this episode, show your support by donating to SNI: ' + ep.address) fe.podcast.itunes_subtitle(ep.subtitle) fe.podcast.itunes_author('Satoshi Nakamoto Institute') fe.enclosure('https://s3.amazonaws.com/nakamotoinstitute/cryptomises/'+ep.slug+'.mp3', 0, 'audio/mpeg') fe.podcast.itunes_duration(ep.duration) fe.pubdate(ep.time) print_enc (fg.rss_str(pretty=True)) #with open("./sni/templates/podcast/feed.xml", "w") as f: # f.write(fg.rss_str(pretty=True)) fg.rss_file('./sni/templates/podcast/feed.xml', pretty=True)
continue item = fg.add_entry() item.id(url + path_folder + "/" + path) item.title(path[11:13] + ':' + path[13:15] + ' ' + (tag.title or '')) item.podcast.itunes_summary(tag.artist or '') item.podcast.itunes_subtitle(tag.artist or '') item.podcast.itunes_author(tag.artist or '') size = '%i' % os.path.getsize(full_path) path_for_url = path if not aac else (path + '.m4a') item.enclosure( url + path_folder + "/" + urllib.quote(path_for_url.encode('utf8')), size, 'audio/mpeg') try: audio = MP3(full_path) rr = audio.info.length except: print u"Cannot parse:", full_path.encode('utf-8') normTime = time.strftime('%H:%M:%S', time.gmtime(audio.info.length)) item.podcast.itunes_duration(normTime) dat = creation_date(path_files + "/" + path) item.pubDate( str(datetime.datetime.fromtimestamp(dat)) + time.strftime("%z")) if (datetime.datetime.now() - datetime.datetime.fromtimestamp(dat) < datetime.timedelta(14)): items.append(item) fg.rss_file(output_file, pretty=True)
def main( # Absolute or relateive path to MP3 files on your local computer # # NB: Use the *.mp3 syntax to select and parse all MP3s in the folder # Also NB: Make sure each file follows this naming convention: # n-xx Name of the track.mp3 # where `n` is the disc number (e.g. 1), and `xx` is the track number (e.g. 07) # Example: 2-14 Act IV Scene iii.mp3 # # If you want, you can change the regular expression that parses these # filenames below at `track_name_raw = re.match(...)` # local_location = '/path/to/ripped/mp3s/*.mp3' *local_files, # ---------------------------------- # Configure variables for the feed # ---------------------------------- # Base URL for where the podcast files and feed will ultimately live base_url = 'http://files.example.com/fauxcasts/book_name/', # Name for the RSS file feed_name = 'feed.rss', # Information about the podcast feed_title = 'Podcast title', feed_description = "Description of podcast", feed_author = 'Some name here', feed_author_email = '*****@*****.**', feed_homepage = 'http://www.example.com' ): feed_url = base_url + feed_name # Name of the pre-uploaded podcast cover image cover_image = base_url + 'cover.jpg' # ---------------------- # Generate actual feed # ---------------------- # Generate feed fg = FeedGenerator() fg.load_extension('podcast') # Add descriptive variables to the feed fg.id(feed_url) fg.title(feed_title) fg.author({'name': feed_author, 'email': feed_author_email}) fg.link(href=feed_homepage, rel='alternate') fg.logo(cover_image) fg.subtitle(feed_description) fg.link(href=feed_url, rel='self') fg.language('en') fg.podcast.itunes_block(True) fg.podcast.itunes_complete(True) # Loop through each MP3 and add it to the feed as an episode for i, track in enumerate(sorted(local_files)): # Some podcast players respect the itunes_order attribute, which is set # below, but many only look at the date and time of the episode. So, here # we pretend that the first episode happened 7 days ago, and each # subsequent episode is released 1 hour later. episode_date = (datetime.now(tz=pytz.utc) - timedelta(days=7) + timedelta(hours=i + 1)) # Get the file size file_size = os.path.getsize(track) # Remove the disk and track numbers from the file names and use just the # title as the episode name track_filename = track track_name = track_filename # Get the duration try : audio = MP3(track) m, s = divmod(audio.info.length, 60) # Convert seconds to h:m:s h, m = divmod(m, 60) if h == 0: duration = "%02d:%02d" % (m, s) else: duration = "%d:%02d:%02d" % (h, m, s) except : duration = "99:99" # Generate entry fe = fg.add_entry() fe.guid(base_url + track_filename) fe.link({'href': base_url + track_filename}) fe.title(track_name) fe.description(track_name) fe.published(episode_date) fe.enclosure(base_url + track_filename, str(file_size), 'audio/mpeg') fe.podcast.itunes_order(i + 1) fe.podcast.itunes_duration(duration) # Write the feed to a file fg.rss_file(feed_name, pretty=True)
fg.subtitle('The official podcast of the Satoshi Nakamoto Institute') fg.language('en') fg.copyright('cc-by-sa') fg.podcast.itunes_summary('Michael Goldstein and Daniel Krawisz of the Satoshi Nakamoto Institute discuss Bitcoin, economics, and cryptography.') fg.podcast.itunes_owner('Michael Goldstein', '*****@*****.**') fg.link(href='http://nakamotoinstitute.org/podcast/feed/', rel='self') fg.podcast.itunes_explicit('no') fg.image('http://nakamotoinstitute.org/static/img/cryptomises/cmpodcast_144.jpg') fg.podcast.itunes_image('http://nakamotoinstitute.org/static/img/cryptomises/cmpodcast_1440.jpg') fg.podcast.itunes_category('Technology', 'Tech News') eps = Episode.query.order_by(desc(Episode.date)).all() for ep in eps: fe = fg.add_entry() fe.id('http://nakamotoinstitute/podcast/'+ep.slug+'/') fe.title(ep.title) fe.podcast.itunes_summary(ep.summary + ' If you enjoyed this episode, show your support by donating to SNI: ' + ep.address) fe.podcast.itunes_subtitle(ep.subtitle) fe.podcast.itunes_author('Satoshi Nakamoto Institute') fe.enclosure('https://s3.amazonaws.com/nakamotoinstitute/cryptomises/'+ep.slug+'.mp3', 0, 'audio/mpeg') fe.podcast.itunes_duration(ep.duration) fe.pubdate(ep.time) print_enc(fg.rss_str(pretty=True)) # with open("./sni/templates/podcast/feed.xml", "w") as f: # f.write(fg.rss_str(pretty=True)) fg.rss_file('./sni/templates/podcast/feed.xml', pretty=True)
from feedgen.feed import FeedGenerator # TODO: get url from cmd line # TODO: get text_regex and url_regex from command line url = sys.argv[1] regex = sys.argv[2] fname = sys.argv[3] # scrapping br = Browser() br.open(url) soup = br.get_soup() m = re.findall(regex, br.data, flags=re.DOTALL) # feed generation fg = FeedGenerator() fg.link(href=url) fg.id(url) title = unicode(soup.find('title').renderContents(), 'utf-8') fg.title(title) fg.description(title) for link in m: fe = fg.add_entry() fe.id(link[0]) fe.link(href=link[0]) fe.title(unicode(link[1], 'utf-8')) fg.rss_file(fname) # Write the RSS feed to a file
import yaml from manganelo import MangaInfo from feedgen.feed import FeedGenerator cstream = open('config.yaml', 'r') config = yaml.load(cstream, Loader=yaml.FullLoader) fg = FeedGenerator() fg.id(config['self']) fg.title('Manganelo RSS') fg.subtitle('Following releases') fg.link(href=config['self'], rel='self') fg.language('en') for url in config['mangas']: manga_info = MangaInfo(url, threaded=True) manga_page = manga_info.results() for c in manga_page.chapters[-5:]: fe = fg.add_entry() fe.id(c.url) fe.title(c.title + ' - ' + manga_page.title) fe.link(href=c.url) fe.source(url=url, title=manga_page.title) fg.rss_file(config['xmlpath'])
DATADIR = config.get('Common', 'datadir') RSS = len(args.rss) > 0 TZ = config.get('Common', 'timezone') TWEET = args.tweet SITE = config.get('Common', 'site') if RSS: rssfile = args.rss rsstitle = config.get('RSS', 'rsstitle') fg = FeedGenerator() fg.title(rsstitle) fg.description(config.get('RSS', 'rssdescription')) rsslink = config.get('RSS', 'rsslink') fg.link(href=rsslink, rel='self') rssfeed = fg.rss_str(pretty=True) fg.rss_file(rssfile) fg.copyright(copyright="CC-BY 4.0") rssauthor = { 'name': config.get('RSS', 'rssauthorname'), 'email': config.get('RSS', 'rssauthoremail'), } fg.author(author=rssauthor, replace=True) if TWEET: APP_KEY = config.get('Twitter', 'appkey') APP_SECRET = config.get('Twitter', 'appsecret') OAUTH_TOKEN = config.get('Twitter', 'token') OAUTH_TOKEN_SECRET = config.get('Twitter', 'tokensecret') twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) timezone = pytz.timezone(TZ) today = datetime.now(timezone).date()
import bs4 as bs import feedgen import requests url="https://holod.media" r = requests.get(url, headers={'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}, timeout=15) a=r.content.decode("utf-8") soup = bs.BeautifulSoup(a,'lxml') tab=[] for row in soup.find_all('a',attrs={"class" : "t404__link"}): tab.append([str(row.get('href')),url+str(row.get('href'))]) from feedgen.feed import FeedGenerator fg = FeedGenerator() fg.title('HOLOD') fg.link( href='http://192.168.1.25', rel='alternate' ) fg.id('http://192.168.1.25') fg.subtitle('HOLOD') for entry in tab: fe = fg.add_entry() fe.id(str(entry[1])) fe.title(str(entry[0])) fe.link(href=str(entry[1])) fg.rss_file('a.xml')
def create_podcast(title, podcast_root, podcast_folder=None, toc_path=None, html_root=r"https://students.cs.byu.edu/~tarch", category="Literature", description="N/A", alphabetize=True, image_link=None, google_drive=True, reverse_order=True, name="podcast.xml", output_folder_root=None, rel_url=""): """ Creates a .XML file of the podcast podcast_root: /home/pi/public_html/podcasts - needed to calculate podcast folder relative to root so URLs are correct podcast_folder: /home/pi/public_html/podcasts/Brandon Sanderson - Infinity Blade Redemption (Unabridged) output_folder_root: usually podcast folder, could be somewhere else though; rel_url: /podcasts - IDK why this is needed, apparently you have TOPLEVEL/rel_url/[path to podcast] """ if VERBOSE: print("ROOT:", podcast_root, "\nFolder:", podcast_folder) # With reverse order, we make "Chapter 1" be the most recent entry # Open CSV if not podcast_folder: podcast_folder = Path(podcast_root) / title if not toc_path: toc_path = Path(podcast_folder) / "TOC.csv" if not output_folder_root: output_folder_root = podcast_root episode_list = open_csv_as_dict(toc_path) #Create RSS feed fg = FeedGenerator() fg.load_extension('podcast') fg.podcast.itunes_category(category) fg.id(title.replace(" ", "")) fg.title(title) fg.author({'name': 'TheFrostyBoss', 'email': '*****@*****.**'}) fg.link(href="taylorarchibald.com", rel='alternate') #fg.subtitle('This is a cool feed!') fg.description(description) fg.podcast.itunes_block(True) # Sort the list if alphabetize: episode_list = sorted(episode_list, key=lambda x: add_zero_to_chapter(x["Title"])) #print(episode_list) if reverse_order: episode_list = episode_list[::-1] for i, episode in enumerate(episode_list): add_episode(fg, episode["Link"], episode["Title"], episode["Series"], episode["Image"], index=len(episode_list) - i - 1) # DEBUG SPECIFIC EPISODE #if "good" in episode["Title"].lower(): # print(id, title, description, episode) # input() image_url = image_link if not image_link is None else episode["Image"] fg.image(url=image_url, title=None, link=None, width=None, height=None, description=None) fg.rss_str(pretty=True) # Add podcast name to path, create if needed relative_path = Path(podcast_folder).relative_to(podcast_root) / name output = Path(output_folder_root) / relative_path output.parent.mkdir(exist_ok=True, parents=True) fg.rss_file(str(output)) if google_drive: link1 = input( "Upload your podcast XML to Google drive. What is the download link for the podcast.xml? (it should have id= somewhere in the link)" ) print(convert_link2(link1)) else: print("Link: ", Path(html_root) / rel_url / url_quote(relative_path.as_posix())) return output
fg.podcast.itunes_category('Music', 'Podcasting') fg.title('Full Duplex Radio') fg.description( "R&R play what they like, which is a lot. And they tell you about it.") fg.link(link={'href': fdr}) myhost = socket.getfqdn("0.0.0.0") # TODO: make this configurable fg.image('https://*****:*****@{}:8080/FDR.jpg'.format(myhost), title='Full Duplex Radio', link=fdr) local_tz = tz.tzlocal() fg.lastBuildDate(datetime.now(tz=local_tz)) fg.rss_str(pretty=True) response = requests.get(fdr) if response.status_code == 200: rows = response.content.decode().split('\n') # '<a href="pl/FD406.html">Episode #406: Do You Know Any Nice Jewish Girls? (2020-11-07)</a>' for row in rows: match = re.match( r'<a href="(?P<rel>[^"]*)">Episode #(?P<ep>[0-9]+): (?P<title>.*) \((?P<date>.*)\)</a>', row) if match: add_episode(fg, match) urls = [ 'https://fullduplexradio.us/audio/Full%20Duplex%20405%20-%202020-10-31.mp3', ] fg.rss_file('podcast.xml')
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?') fe.podcast.itunes_author('Lars Kiesow') 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)
fg.podcast.itunes_category('Technology', 'Podcasting') r = requests.get('https://api.patreon.com/campaigns/157274/posts?filter[is_by_creator]=true&page[count]=100') patreon_posts = r.json() entry_list = [] for data in patreon_posts['data']: post = data['attributes'] if post['post_type'] == 'audio_file' and post['post_file'] is not None: # insert Paris attacks special episode if post['published_at'] == '2015-11-15T07:06:53+00:00': insert_paris_attacks_episode(fg) fe = fg.add_entry() fe.id(post['post_file']['url']) fe.title(post['title']) fe.description(post['content']) fe.enclosure(post['post_file']['url'], 0, 'audio/mpeg') fe.pubdate(iso8601.parse_date(post['published_at'])) fg.title('Radio War Nerd') fg.podcast.itunes_author('Gary Brecher') fg.link({'href': 'https://www.patreon.com/radiowarnerd'}) fg.description("The War Nerd Podcast") fg.logo('https://c10.patreon.com/3/eyJ3Ijo0MDB9/patreon-user/n4H3wobwI3jPQ5ZY5vPlYLmFgn7NZq6K6IbNEI5DvpFYMlozBQB33OZF1kHCjk4y_large_2.jpeg?token-time=2145916800&token-hash=ScHYE7uDDc6w7HeFV1b33guW7-sHpbKVT84yR-HXwJI%3D') fg.rss_str(pretty=True) fg.rss_file('rwn.xml')
def pbs_show(slug): print('processing %s' % slug) cache_glob = list(p.glob(slug + "*")) if cache_glob: recent_cache_path = sorted(cache_glob)[-1] cache_time_str = re.search(slug + '.([^\.]+).xml', recent_cache_path.name).group(1) cache_time = datetime.datetime.strptime(cache_time_str, '%Y-%m-%dT%H:%M:%S') print(cache_time_str) print(datetime.datetime.now().isoformat()) if cache_time + datetime.timedelta(days=7) > datetime.datetime.now(): # cached file is still valid; return that return send_file(recent_cache_path.open(), mimetype='application/rss+xml') show_url = show_format.format(slug=slug) show_info = requests.get(show_url).json() show_title = show_info['name'] feed = FeedGenerator() feed.load_extension('podcast') feed.podcast.itunes_category('Music') feed.id(show_url) feed.link(href=show_website_format.format(slug=slug), rel='alternate') feed.title(show_title) desc = show_info['description'] presenters = show_info['broadcasters'] if presenters: feed.author(name=presenters) feed.description(desc + "Presented by " + presenters + ".") else: feed.description(desc) feed.logo(show_info['profileImageUrl']) feed.language('en') episodes = requests.get(show_info['episodesRestUrl']).json() episode_times = [] for episode in reversed(episodes): start_time = datetime.datetime.strptime(episode['start'], '%Y-%m-%d %H:%M:%S') episode_times.append(start_time) title = "{} {}".format(show_title, start_time.date()) media_url = media_format.format( slug=slug, timestamp=start_time.strftime("%Y%m%d%H%M")) feed_entry = feed.add_entry() feed_entry.id(media_url) feed_entry.title(title) feed_entry.author(name=presenters) feed_entry.enclosure(media_url, 0, 'audio/mp4') try: ep_data = requests.get(episode['episodeRestUrl']).json() tracklist_data = requests.get(ep_data['playlistRestUrl']).json() tracklist = "<h3>Tracklist</h3>" + "<br>".join( [track['title'] for track in tracklist_data]) feed_entry.description(tracklist) except: feed_entry.description(title) if episode_times: # remove all old cache files for this program for cachefile in p.glob(slug + "*"): cachefile.unlink() recent_ep_time = sorted(episode_times)[-1].isoformat() feed.rss_file(CACHE_DIR + "/" + slug + " " + recent_ep_time + ".xml", pretty=True) return Response(feed.rss_str(pretty=True), mimetype='application/rss+xml')
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 cap = DesiredCapabilities().FIREFOX cap["marionette"] = True #optional driver = webdriver.Firefox(options=options, capabilities=cap, executable_path="geckodriver.exe") # Render Page url = 'https://www.indefenseofplants.com/podcast' driver.get(url) # Process the return of the first page process_page(driver.page_source) # While we have an "older-posts" link, keep clicking the link and processing # the new page while driver.find_elements_by_class_name('older-posts'): driver.find_element_by_class_name('older-posts').click() process_page(driver.page_source) fg.rss_file('idop.xml')
DATADIR = config.get('Common', 'datadir') RSS = len(args.rss) > 0 TZ = config.get('Common', 'timezone') TWEET = args.tweet SITE = config.get('Common', 'site') if RSS: rssfile = args.rss rsstitle = config.get('RSS', 'rsstitle') fg = FeedGenerator() fg.title(rsstitle) fg.description(config.get('RSS', 'rssdescription')) rsslink = config.get('RSS', 'rsslink') fg.link(href=rsslink, rel='self') rssfeed = fg.rss_str(pretty=True) fg.rss_file(rssfile) fg.copyright(copyright="CC-BY 4.0") rssauthor = {'name': config.get('RSS', 'rssauthorname'), 'email': config.get('RSS', 'rssauthoremail'), } fg.author(author=rssauthor, replace=True) if TWEET: APP_KEY = config.get('Twitter', 'appkey') APP_SECRET = config.get('Twitter', 'appsecret') OAUTH_TOKEN = config.get('Twitter', 'token') OAUTH_TOKEN_SECRET = config.get('Twitter', 'tokensecret') twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) timezone = pytz.timezone(TZ) today = datetime.now(timezone).date()
if True: external_ip = requests.get('https://api.ipify.org').text gen = FeedGenerator() gen.load_extension('podcast') gen.title(chan_name) gen.description(chan_desc) gen.link(href=chan_url, rel='alternate') gen.link(href=('https://' + external_ip + '/rss?chan=' + chan_name), rel='self') gen.logo(chan_info['items'][0]['snippet']['thumbnails']['high']['url']) gen.language('en') # gen.podcast.itunes_category('Games & Hobbies', 'Video Games') # gen.podcast.itunes_explicit('no') gen.podcast.itunes_complete('no') gen.podcast.itunes_new_feed_url(chan_url) # gen.podcast.itunes_owner('videogamedunkey', '*****@*****.**') gen.podcast.itunes_summary(chan_desc) gen.podcast.itunes_author(chan_name) for root, dirs, files in os.walk(output_folder): for file in files: if file_ext in file: entry = gen.add_entry() entry.id( 'some link for now' ) # TODO What does this need to be for the webserver to find it? entry.title(file) entry.podcast.itunes_author(chan_name) gen.rss_file(os.path.join(output_folder, 'feed.xml'))
sort='pubdate') #Extract info allp = [] for p in papers: allp.append({'title': p.title[0], 'bibcode': p.bibcode, 'pub': p.pubdate}) sleep(0.01) #Most recent first allp = sorted(allp, key=lambda k: k['pub'], reverse=False) #Make RSS feed fg = FeedGenerator() fg.id(BASE_URL) fg.link(href=BASE_URL, rel='self') #fg.link(href=BASE_URL,rel='alternate') fg.title('ADS citation feed') fg.author({'name': 'abc', 'email': '*****@*****.**'}) fg.logo('') fg.subtitle('RSS feed of my ads keywords') fg.language('en') for i in allp: fe = fg.add_entry() fe.id(BASE_URL + i['bibcode']) fe.link(href=BASE_URL + i['bibcode']) fe.title(i['title']) rssfeed = fg.rss_str(pretty=True) fg.rss_file(RSS_FILE)
path_files = root_path + path_folder only_files = [ f for f in listdir(path_files) if isfile(join(path_files, f)) and not islink(join(path_files, f)) ] for p in only_files: path = p.decode('utf-8') tag = Tag() tag.parse(path_files + "/" + path) item = fg.add_entry() item.id(u"https://www.simx.mobi/weszlo/" + path_folder + "/" + path) item.title(tag.title) item.podcast.itunes_summary(tag.artist + " " + tag.title) item.podcast.itunes_subtitle(tag.artist) item.podcast.itunes_author(tag.artist) item.enclosure( u"https://www.simx.mobi/weszlo/" + path_folder + "/" + path, 0, 'audio/mpeg') audio = MP3(path_files + "/" + path) normTime = time.strftime('%H:%M:%S', time.gmtime(audio.info.length)) item.podcast.itunes_duration(normTime) dat = creation_date(path_files + "/" + path) item.pubdate( str(datetime.datetime.fromtimestamp(dat)) + time.strftime("%z")) items.append(item) fg.rss_file('./feed.xml', pretty=True)
from config import config Base.metadata.create_all(engine) searchListing = SearchListing(config, sys.argv[1], sys.argv[2], sys.argv[3]) for result in searchListing.listing_results: matched = session.query(GTItem).filter(GTItem.url == result.url).all() if len(matched) == 0: session.add(result) session.commit() from feedgen.feed import FeedGenerator fg = FeedGenerator() fg.title('Gumtree feed') fg.description('Gumtree feed') fg.link(href='http://example.com', rel='alternate') all_result = session.query(GTItem).order_by( GTItem.creation_date.desc()).limit(1000).all() for result in all_result: fe = fg.add_entry() url = "{0[baseurl]}{1.url}".format(config, result) fe.id(url) fe.link(href=url, rel='alternate') fe.title(result.price + ' ' + result.title) fe.description(result.summary) fg.rss_file('rss.xml')
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!') }
from feedgen.feed import FeedGenerator fg = FeedGenerator() fg.id('http://lernfunk.de/media/654321') fg.title('Some Testfeed') fg.author({'name': 'John Doe', 'email': '*****@*****.**'}) fg.link(href='http://example.com', rel='alternate') fg.logo('http://ex.com/logo.jpg') fg.subtitle('This is a cool feed!') fg.link(href='http://larskiesow.de/test.atom', rel='self') fg.language('en') atomfeed = fg.atom_str(pretty=True) # Get the ATOM feed as string rssfeed = fg.rss_str(pretty=True) # Get the RSS feed as string fg.atom_file('atom.xml') # Write the ATOM feed to a file fg.rss_file('rss.xml') # Write the RSS feed to a file fe = fg.add_entry() fe.id('http://lernfunk.de/media/654321/1') fe.title('The First Episode') fe.link(href="http://lernfunk.de/feed")
}) fg.description('OpenMods update feed') fg.lastBuildDate(datetime.datetime.utcnow().replace(tzinfo=pytz.utc)) for (bundle, mods) in sorted(data.items(), key=lambda (bundle, mods): bundle, reverse=True): bundle_date = datetime.datetime.strptime( bundle, "%Y-%m-%d").replace(tzinfo=pytz.utc) ue = fg.add_entry() ue.id("openmods.info:update:" + bundle) ue.title("New OpenMods update: " + bundle) ue.description( ", ".join(sorted([e.mod + " " + e.version for e in mods.values()])), True) ue.link({'href': 'https://openmods.info'}) ue.published(bundle_date) ue.updated(bundle_date) for (mod_id, mod_data) in mods.items(): fe = fg.add_entry() fe.id("openmods.info:update:" + bundle + ":" + mod_id) fe.title("New file: " + mod_data.file) fe.published(bundle_date) fe.updated(bundle_date) fe.link( {'href': "https://openmods.info/downloads/" + mod_data.file}) fg.atom_file('../openmods.info/atom.xml', pretty=True) fg.rss_file('../openmods.info/rss.xml', pretty=True)
def _feed_gen(segments): # TODO wow this got ugly _fast_ -- refactor fg = FeedGenerator() fg.load_extension('podcast') fg.link(href='http://www.c-span.org/series/?washingtonJournal', rel="alternate") fg.description('C-SPAN\'s Washington Journal') fg.title('Washington Journal') fg.podcast.itunes_image(get_segment_image([x for x in segments if x['seq'] == 1][0])) copied_mp3s = [] for program_date in reversed(sorted(list(set([x['date'] for x in segments])))): date_segments = list(reversed([x for x in segments if x['date'] == program_date])) segments_with_audio = [x for x in date_segments if x.get('mp3_file')] if len(segments_with_audio) != 3: # sometimes WJ airs for less than three hours when they switch to coverage # of the house or senate, so this is a warning not an exception logging.warning( "We do not have the expected 3 mp3s for %s -- got %s instead", program_date, len(segments_with_audio) ) segments_with_audio_counter = 0 for seg in date_segments: if not seg.get('mp3_file'): # we should always start with a segment that has an mp3 if segments_with_audio_counter == 0: logging.warning('first segment does not have an mp3: %s', seg['key']) continue # this segment will be collapsed into a preceding one mp3_filename = seg['mp3_file'].split(os.sep)[-1] mp3_url = 'https://dl.dropboxusercontent.com/u/{}/wj/{}'.format( CONFIG['dropbox_public_id'], mp3_filename ) target_mp3 = os.path.join(CONFIG['podcast_dir'], mp3_filename) if not os.path.exists(target_mp3): logging.info('copying %s -> %s', seg['mp3_file'], target_mp3) shutil.copyfile(seg['mp3_file'], target_mp3) copied_mp3s.append(mp3_filename) collapse_segments = [ x for x in date_segments if x['video_identifier'] == seg['video_identifier'] ] fe = fg.add_entry() fe.id(mp3_url) fe.title("{} [{}] {}".format( seg['date'], str(segments_with_audio_counter + 1), " / ".join([x['title'] for x in collapse_segments]) )) host_name = "[{}] ".format(seg['host']) if seg.get('host') else '' fe.description(host_name + " /// ".join([x['descrip'] for x in collapse_segments])) fe.enclosure(mp3_url, str(os.path.getsize(seg.get('mp3_file'))), 'audio/mpeg') pub_year, pub_month, pub_day = [int(x) for x in seg['date'].split('-')] fe.published( datetime( year=pub_year, month=pub_month, day=pub_day, hour=(7 + segments_with_audio_counter), # show starts at 7 am tzinfo=pytz.timezone("US/Eastern"), ) ) segments_with_audio_counter += 1 fg.rss_str(pretty=True) rss_filename = os.path.join(CONFIG['podcast_dir'], CONFIG['rss_file']) logging.info('writing %s', rss_filename) fg.rss_file(rss_filename, pretty=True) # remove truncated mp3s for mp3_file in [x for x in os.listdir(CONFIG['podcast_dir']) if x.endswith('.mp3')]: if mp3_file not in copied_mp3s: logging.info('removing stale target mp3: %s', mp3_file) os.unlink(os.path.join(CONFIG['podcast_dir'], mp3_file))
print("DELETING: " + delete) os.remove(delete) # keep only MAX_ITEMS newest items, reverse to be oldest to newest items = items[:MAX_ITEMS][::-1] fg = FeedGenerator() fg.load_extension("podcast") fg.title(TITLE) fg.description(DESC) fg.author({"name": "Rayquaza01"}) fg.link(href=SERVER + "podcast.rss", rel="self") fg.logo(LOGO) fg.podcast.itunes_image(LOGO) # add entries for item in items: fe = fg.add_entry() url = SERVER + urllib.parse.quote(item) fe.id(url) fe.published( datetime.datetime.fromtimestamp(os.path.getmtime(item), tz=datetime.timezone.utc)) fe.title(item) fe.description(url) fe.enclosure(url, 0, "audio/mpeg") # export to rss fg.rss_str(pretty=True) fg.rss_file("podcast.rss")
fg.title( data['category']['name'] ) fg.description( data['category']['description'] ) fg.link(href='https://crgwbr.com/jwb.atom', rel='self') for item in data['category']['media']: fe = fg.add_entry() fe.id( item['guid'] ) fe.title( item['title'] ) fe.description( item['description'] ) fe.published( item['firstPublished'] ) files = [f for f in item['files'] if not f['subtitled']] files.sort(key=lambda file: file['bitRate'], reverse=True) file = files[0] url = file['progressiveDownloadURL'] mime = file['mimetype'] fe.enclosure(url, 0, mime) fe.link(href=url, type=mime) for size in ('wsr', 'wss', 'sqr', 'sqs'): try: fe.podcast.itunes_image( item['images'][size]['lg'] ) break except KeyError: pass fg.rss_str(pretty=True) fg.rss_file('podcast.xml')
def write_rss(self, audio=False): """Write podcast feeds to files.""" print("playlist self.info", flush=True) pp.pprint(self.info) prefix = "audio-" if audio else "" feed_url = self.controller.base_url + self.folder + '/' + prefix + 'podcast.xml' feedgen = FeedGenerator() feedgen.load_extension('podcast') feedgen.generator('Adafruit-Podcast') feedgen.id(feed_url) feedgen.title(self.info['title']) feedgen.subtitle(self.info['itunesSubtitle']) feedgen.author({'name': self.info['author']}) for category in self.info['categories']: feedgen.category(term=category) feedgen.webMaster(self.info['webMaster']) feedgen.managingEditor(self.info['managingEditor']) feedgen.link(href=feed_url, rel='self') # Link to a chosen URL as an alternate, if set. if 'htmlUrl' in self.info: feedgen.link(href=self.info['htmlUrl'], rel='alternate') else: # Otherwise link to the original YouTube playlist as an alternate: if isinstance(self.url, list): for url in self.url: feedgen.link(href=url, rel='alternate') else: feedgen.link(href=self.url, rel='alternate') feedgen.language('en') # feedgen.logo('http://ex.com/logo.jpg') # pylint: disable=no-member feedgen.podcast.itunes_category(self.info['itunesCategory']['text']) feedgen.podcast.itunes_subtitle(self.info['itunesSubtitle']) feedgen.podcast.itunes_summary(self.info['description']) feedgen.podcast.itunes_owner(email=self.info['itunesOwner']['email'], name=self.info['itunesOwner']['name']) feedgen.podcast.itunes_author(self.info['itunesOwner']['name']) feedgen.podcast.itunes_image(self.controller.base_url + self.folder + '/image.jpg') feedgen.podcast.itunes_explicit('clean') for vid in self.videos: print("vid:\n", flush=True) pp.pprint(vid) print("\n", flush=True) vid_filename = vid['_filename'].split('.')[0] + (".mp3" if audio else ".mp4") vid_url = self.video_url(vid_filename) # Size of enclosed file in bytes: vid_size = os.path.getsize(vid_filename) # Date of upload (from the youtube-dl JSON data) eastern = pytz.timezone('US/Eastern') vid_date = eastern.localize( datetime.datetime.strptime(vid['upload_date'], '%Y%m%d')) entry = feedgen.add_entry() entry.id(vid_url) entry.title(vid['fulltitle']) entry.published(vid_date) for category in vid['categories']: entry.category(term=category) entry.description(vid['description']) entry.enclosure(vid_url, str(vid_size), ('audio/mp3' if audio else 'video/mp4')) entry.podcast.itunes_image(self.controller.base_url + self.folder + '/image.jpg') entry.podcast.itunes_author(self.info['author']) entry.podcast.itunes_summary(vid['description']) entry.podcast.itunes_duration(vid['duration']) feedgen.rss_str(pretty=True) # Ensure output folder for this podcast exists: os.makedirs(os.path.join(self.controller.output_dir, self.folder), exist_ok=True) # Generate RSS file in output folder: feedgen.rss_file( os.path.join(self.controller.output_dir, self.folder, prefix + 'podcast.xml'))
# 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?') fe.podcast.itunes_author('Lars Kiesow') print_enc (fg.rss_str(pretty=True)) elif arg == 'dc.atom': fg.load_extension('dc') fg.dc.dc_contributor('Lars Kiesow') fe.dc.dc_contributor('Lars Kiesow') print_enc (fg.atom_str(pretty=True)) elif arg == 'dc.rss': fg.load_extension('dc') fg.dc.dc_contributor('Lars Kiesow') print_enc (fg.rss_str(pretty=True)) elif arg.endswith('atom'): fg.atom_file(arg) elif arg.endswith('rss'): fg.rss_file(arg)
def main(): all_tags = {} post_data = [] for post in get_posts(): out_file = post[len('posts/'):] output, title = get_post_data(post) header, date, tags_raw = title[1], title[2], title.get(6, "") tags = tags_raw.split(",") tags_html = get_html_tags(tags) post_data.append( (out_file, title[1], title[2], post, output, tags_html)) for tag in tags: if tag not in all_tags: all_tags[tag] = [] all_tags[tag].append((out_file, title[1], title[2])) title = title[1] with open('docs/' + out_file, 'w') as f: f.write( TEMPLATE.format(post=output, title=title, subtitle=date, tag=title, tags=tags_html, meta="")) for post in get_event_posts(): out_file = post[len('event-data/'):].split('.')[0] m, d, y = out_file.split('-') date = f'{m.title()} {d}, {y}' out_file = f'week-of-{out_file}.html' with open(post) as f: data = yaml.safe_load(f) week = data['week'] header = f'Community speakers appearing the week of {week}' output = [ '<p>Events in this list are chosen because of their particularly high-caliber content. If there is an event or series that you think should be considered in this list please email <a href="mailto:[email protected]">[email protected]</a>. Community feedback is extremely welcome.</p>' ] output.append('<div class="events">') for day, events in data['events'].items(): output.append(' <div class="day">') output.append(f' <div class="day-name">{day}</div>') for event in events: output.append(' <div class="event">') output.append( f' <div class="event-group">{event["group"]}</div>') output.append( f' <span class="event-title">{event["title"]}</span><span class="event-time">{event["time"]}</span>' ) if 'who' in event: output.append( f' <span class="event-by">by {event["who"]}</span>' ) output.append( f' <a href="{event["link"]}" class="event-link">Link</a>' ) output.append(' </div>') output.append(' </div>') output.append('</div>') output = '\n'.join(output) with open('docs/' + out_file, 'w') as f: f.write( TEMPLATE.format(post=output, title=header, subtitle=date, tag=header, tags='', meta='')) post_data.append((out_file, header, date, post, output, '')) post_data.sort(key=lambda post: datetime.strptime(post[2], '%B %d, %Y')) post_data.reverse() notes = [] for i, args in enumerate(post_data): year = args[2].split(' ')[-1] prev_post_year = str(datetime.today().year + 1) if i == 0 else post_data[i - 1][2].split(' ')[-1] if year != prev_post_year: notes.append('<h3>{}</h3>'.format(year)) note = POST_SUMMARY.format(*args[:2], args[5], *args[2:3]) notes.append(note) home_page = HOME_PAGE.format(notes="\n".join(notes)) with open('docs/index.html', 'w') as f: meta = '' f.write( TEMPLATE.format(post=home_page, title="", tag=TAG, subtitle="", tags="", meta=meta)) with open('docs/style.css', 'w') as fw: with open('style.css') as fr: fw.write(fr.read()) fg = FeedGenerator() for url, title, date, post, content, _ in reversed(post_data): fe = fg.add_entry() fe.id('http://learn.multiprocess.io/' + url) fe.title(title) fe.link(href='http://learn.multiprocess.io/' + url) fe.pubDate( datetime.strptime(date, '%B %d, %Y').replace(tzinfo=timezone.utc)) fe.content(content) fg.id('http://learn.multiprocess.io/') fg.link(href='http://learn.multiprocess.io/') fg.title(TAG) fg.description(TAG) fg.language('en') fg.rss_file('docs/rss.xml') if not os.path.exists('docs/tags'): os.makedirs('docs/tags') for tag in all_tags: posts = all_tags[tag] with open('docs/tags/%s.html' % tag.replace(' ', '-'), 'w') as f: posts.sort( key=lambda post: datetime.strptime(post[2], '%B %d, %Y')) posts.reverse() tag_page = TAG_PAGE.format(tag) tag_page += "\n".join( [TAG_SUMMARY.format(*args) for args in posts]) f.write( TEMPLATE.format(post=tag_page, title="", tag=TAG, subtitle="", tags="", meta=""))