本文整理汇总了Python中feedgen.feed.FeedGenerator.atom_file方法的典型用法代码示例。如果您正苦于以下问题:Python FeedGenerator.atom_file方法的具体用法?Python FeedGenerator.atom_file怎么用?Python FeedGenerator.atom_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feedgen.feed.FeedGenerator
的用法示例。
在下文中一共展示了FeedGenerator.atom_file方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import atom_file [as 别名]
def main():
client = moduleSocial.connectTumblr()
posts = client.posts('fernand0')
fg = FeedGenerator()
fg.id(posts['blog']['url'])
fg.title(posts['blog']['title'])
fg.author( {'name':posts['blog']['name'],'email':'[email protected]'} )
fg.link( href=posts['blog']['url'], rel='alternate' )
fg.subtitle('Alternate feed due to Tumblr GDPR restrictions')
fg.language('en')
print(len(posts['posts']))
for i in range(len(posts['posts'])):
fe = fg.add_entry()
print(posts['posts'][i]['post_url'])
if 'title' in posts['posts'][i]:
title = posts['posts'][i]['title']
print('T', posts['posts'][i]['title'])
else:
title = posts['posts'][i]['summary'].split('\n')[0]
print('S', posts['posts'][i]['summary'].split('\n')[0])
fe.title(title)
fe.link(href=posts['posts'][i]['post_url'])
fe.id(posts['posts'][i]['post_url'])
print(fg.atom_file('/var/www/html/elmundoesimperfecto/tumblr.xml'))
sys.exit()
示例2: create_feed
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import atom_file [as 别名]
def create_feed(episodes, output_filepath=None):
woe_feed = FeedGenerator()
woe_feed.load_extension('podcast', atom=True)
woe_feed.title(u"Willkommen Österreich")
woe_feed.id(EPISODES_SCRAPING_URL)
woe_feed.link(href=BASE_URL, rel='self')
woe_feed.description(u"Inoffizieller RSS-Feed für 'Willkommen Österreich'-Episoden")
woe_feed.language('de')
for episode in episodes:
episode_entry = woe_feed.add_entry()
episode_entry.id(episode.page)
episode_entry.link(href=episode.page, rel='alternate')
episode_entry.title(u"Folge {0} - {1}: {2}".format(episode.num, episode.date, episode.description))
for video in episode.videos:
episode_entry.enclosure(url=video, length=0, type='mp4')
if output_filepath:
woe_feed.atom_file(output_filepath)
else:
print(woe_feed.atom_str(pretty=True))
示例3: getDataFeed
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import atom_file [as 别名]
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()
示例4: generate_feed
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import atom_file [as 别名]
def generate_feed():
tz = pytz.timezone(config.timezone)
# Get latest X entries from database
entries = dbhelper.get_latest_entries()
fg = FeedGenerator()
# Feed id
fg.id(config.bot_link)
# Creator info (for Atom)
fg.author(name=config.author_name, email=config.author_email, replace=True )
# Self link to the feed
fg.link(href=config.feed_link, rel='self')
# Set description of your feed
fg.description(config.feed_description)
# Last time feed updated (use system time with timezone)
fg.lastBuildDate(formatdate(datetime.timestamp(datetime.now(tz)), localtime=True))
fg.title(config.feed_title)
# Set time-to-live (I really don't know why set this)
fg.ttl(5)
# Does this parameter mean anything?
fg.language(config.feed_language)
for entry in entries:
item = fg.add_entry()
# Use message id to form valid URL (new feature in Telegram since Feb 2016)
item.id("{!s}".format(entry["pid"]))
item.link(href="{!s}/{!s}".format(config.bot_link, entry["pid"]), rel="alternate")
# Set title and content from message text
item.title(entry["ptext"])
item.content(entry["ptext"])
# Set publish/update datetime
item.pubdate(entry["pdate"])
item.updated(entry["pdate"])
# Write RSS/Atom feed to file
# It's preferred to have only one type at a time (or just create two functions)
fg.atom_file('static/atom.xml')
示例5: print_enc
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import atom_file [as 别名]
# 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', '[email protected]')
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)
示例6: main
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import atom_file [as 别名]
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': '[email protected]'})
fg.link(href='http://example.com', rel='alternate')
fg.category(term='test')
fg.contributor(name='Lars Kiesow', email='[email protected]')
fg.contributor(name='John Doe', email='[email protected]')
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='[email protected]')
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', '[email protected]')
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)
示例7: main
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import atom_file [as 别名]
#.........这里部分代码省略.........
# get metadata about the collection
context = '{0}/collections/{1}'.format(config['zotero_account'], config['zotero_collection'])
url = '/'.join((ZOT_BASE, context, '?format=json'))
response = zot_get(url)
alt_html = json.loads(response['content'])['links']['alternate']['href']
# get list of items in collection
context = '{0}/collections/{1}/items/top'.format(config['zotero_account'], config['zotero_collection'])
url = '/'.join((ZOT_BASE, context, '?format=keys&sort=dateModified&direction=desc&limit={0}'.format(config['maximum'])))
logger.debug('fetching: {0}'.format(url))
response = zot_get(url)
if int(response['length']) > 0:
keys = response['content'].split('\n')
else:
print "boom"
if len(keys) > config['maximum']+1:
logger.error("gigantic: {0}".format(len(keys)))
raise Exception
fg = FeedGenerator()
feed_id = u'tag:{domain},{date}:{slug}'.format(
domain=config['tag_domain'],
date=config['tag_date'],
slug=config['tag_slug'])
fg.id(feed_id)
fg.title(config['title'])
fg.author( {'name':config['author_name'],'email':config['author_email']} )
fg.link( href=config['self'], rel='self' )
fg.link( href=alt_html, rel='alternate' )
fg.logo('https://www.zotero.org/support/_media/logo/zotero_256x256x32.png')
fg.language('en')
fg.updated(datetime.now(pytz.utc))
context = '{0}/items'.format(config['zotero_account'])
entries = {}
for key in [k for k in keys if len(k.strip()) > 0]:
logger.info(u'zotero key: "{0}"'.format(key))
url = '/'.join((ZOT_BASE, context, key))
response = zot_get(url)
data = json.loads(response['content'])
zot_link_html = data['links']['alternate']['href']
zot_link_json = data['links']['self']['href']
data = data['data']
logger.info(u'zotero itemType: "{0}"'.format(data['itemType']))
if data['itemType'] == 'note':
logger.warning('ignored note (key="{0}")'.format(key))
elif data['itemType'] == 'attachment':
if data['linkMode'] == u'linked_url':
fe = entries[data['parentItem']]
fe.link(href=data['url'], title=data['title'], rel='alternate')
else:
raise NotImplemented('Zotero attachment (key="{0}") with unhandled linkMode="{1}"'.format(key, data['linkMode']))
else:
fe = fg.add_entry()
entries[key] = fe
entry_id = u'tag:{domain},{date}:{slug}'.format(
domain='zotero.org',
date=data['dateAdded'].split('T')[0],
slug='/'.join((context, key)))
fe.id(entry_id)
try:
fe.title(data['title'])
except KeyError:
logger.warning("unexpected lack of title in zotero record")
logger.debug(pformat(data, indent=2))
raise
try:
creators = data['creators']
except KeyError:
pass
else:
authors = [c for c in data['creators'] if c['creatorType'] == u'author']
for a in authors:
if 'name' in a.keys():
fe.author({'name':a['name']})
else:
fe.author({'name':u'{0} {1}'.format(a['firstName'], a['lastName']), })
try:
fe.link(href=data['url'], rel='alternate', title='link to resource')
except KeyError:
pass
fe.link(href=zot_link_html, rel='alternate', title='link to zotero record (html)')
#fe.link(href=zot_link_json, rel='alternate', title='link to zotero record (json)')
try:
fe.description(data['abstractNote'], isSummary=True)
except KeyError:
pass
url = '/'.join((ZOT_BASE, context, key, '?format=bib'))
bib = zot_get(url)
logger.debug(pformat(bib, indent=4))
bib = bib['content'].split('\n')[2].strip()
logger.debug("bib: '{0}'".format(bib))
fe.content(content=bib, type='xhtml')
fe.published(data['dateAdded'])
fe.updated(data['dateModified'])
#fe.updated(datetime.now(pytz.utc))
with open(config['out_path'], 'w') as f:
fg.atom_file(f)
示例8: execute
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import atom_file [as 别名]
def execute():
feed_items = {}
added_entry_urls = set()
sections = {
'jap': "日本の昔話 (Japanese Legends)",
'minwa': "日本の民話 (Japanese Folktales)",
'world': "世界の昔話 (World Folktales)",
'aesop': "イソップ童話 (Aesop's Fables)",
'kobanashi': "江戸小話 (Edo Short Stories)",
'kaidan': "百物語 (Japanese Ghost Stories)",
}
for section in sections:
feed_items[section] = []
for batch in [_month_urls(section) for section in sections]:
for section, month, month_url in batch:
root = _fetch_root(month_url)
for link in root.cssselect('a'):
url = urljoin(month_url, link.get('href'))
if url in added_entry_urls:
continue
if re.match(
r'^http://hukumusume.com/douwa/pc/(jap|minwa|world|aesop|kobanashi|kaidan)/{:02}/\w+\.html?$'.format(month),
url,
):
title = link.text
if not title:
continue
table = link.xpath('./ancestor::table[1]')[0]
texts = table.itertext()
description = ''
for text1, text2 in zip(texts, texts[1:]):
if '内容 :' in text1:
description = (text1 + text2)[len('内容 :'):]
try:
image_relative_url = table.cssselect('img')[0].get('src')
# Avoid weird case with "001", "002" links in Aesop feed (and maybe elsewhere).
if 'corner' in image_relative_url:
continue
image_url = urljoin(month_url, image_relative_url)
except IndexError:
# Every one has an image.
continue
feed_items[section].append({
'url': url,
'title': link.text,
'description': description,
'image_url': image_url,
})
added_entry_urls.add(url)
for section, title in sections.items():
fg = FeedGenerator()
fg.id('http://hukumusume.com/douwa/pc/{}/index.html'.format(section))
fg.title(title)
fg.language('ja')
for item in feed_items[section]:
entry = fg.add_entry()
entry.id(item['url'])
entry.title(item['title'])
entry.link(href=item['url'], rel='alternate')
entry.summary(item['description'])
entry.content('<img src="{}" />'.format(item['image_url']), type='CDATA')
fg.atom_file('manabi/static/reader/feeds/hukumusume-{}.rss'.format(section))