Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if '/' in repository_or_username:
username, repository = repository_or_username.split('/', 1)
repositories = [repository]
else:
username = repository_or_username
repositories = [rep.name for rep in gh.repos.list(username)]
for repository in repositories:
full_repname = username + '/' + repository
log.info('Processing %s' % full_repname)
# first, we need to get the date of the last commit
commits = gh.commits.list(full_repname, 'master')
last_commit_date = commits[0].committed_date
feed = feedgenerator.Atom1Feed(
title=u'%s forks' % full_repname,
link=u'http://github.com/%s' % full_repname,
description=u'Commits from forks of %s repository at GitHub.' % full_repname,
language=u'en',
)
for fork in gh.repos.network(full_repname):
fork_repname = '%(owner)s/%(name)s' % fork
log.info('Fetching commits from %s' % fork_repname)
fork_commits = gh.commits.list(fork_repname, 'master')
for commit in reversed(fork_commits):
if commit.committed_date > last_commit_date:
short_commit_message = commit.message.split('\n', 1)[0]
log.debug('%s %s %s', fork_repname, commit.committed_date, short_commit_message)
def add_root_elements(self, handler):
super(PagedFeed, self).add_root_elements(handler)
if self.feed.get('next_page_url') is not None:
handler.addQuickElement(u"link",
"",
{u"rel": u"next",
u"href": self.feed['next_page_url']})
if self.feed.get('previous_page_url') is not None:
handler.addQuickElement(u"link",
"",
{u"rel": u"previous",
u"href": self.feed['previous_page_url']})
class CufPagedFeed(feedgenerator.Atom1Feed):
def root_attributes_for_cuf(self, title):
if title == "Server" or title == "NeutronPubIPv4":
if self.feed['language'] is not None:
return {u"xmlns:atom": self.ns, u"xml:lang": self.feed['language']}
else:
return {u"xmlns:atom": self.ns}
if title == "Glance":
return {u"xmlns:atom": self.ns,
u"xmlns": u"http://docs.rackspace.com/core/event",
u"xmlns:glance": u"http://docs.rackspace.com/usage/glance"}
# Get it to care about content elements
def write_item(self, handler, item, root=False, title="Server"):
handler.startElement(u"atom:entry",
self.root_attributes_for_cuf(title) if root else {})
def __init__(self, title, link, description):
self.feed = Atom1Feed(
title = title,
link = link,
description = description,
language=u"en",
)
import json
import uuid
import feedgenerator
def clean_content(cdict):
if cdict.__class__.__name__ == 'dict':
return dict([i for i in cdict.items() if not i[0].startswith('_')])
return cdict
class PagedFeed(feedgenerator.Atom1Feed):
# I hate having to do this, but there is no other way to override
# the link generation
def add_item_elements(self, handler, item):
#glommed wholesale from feed generator to change *one* little thing... (mdragon)
handler.addQuickElement(u"title", item['title'])
if item['link'] is not None:
handler.addQuickElement(u"link", u"", {u"href": item['link'], u"rel": u"alternate"})
if item['pubdate'] is not None:
handler.addQuickElement(u"updated", feedgenerator.rfc3339_date(item['pubdate']).decode('utf-8'))
# Author information.
if item['author_name'] is not None:
handler.startElement(u"author", {})
handler.addQuickElement(u"name", item['author_name'])
if item['author_email'] is not None:
def atom_feed(self) -> str:
"""
Returns:
An Atom feed consisting of the `num_keep` most recent entries from
each of the `feeds`.
"""
return self.__generate_feed(Atom1Feed).writeString('utf-8')
with open(tag_path, mode='wb', encoding='UTF-8') as the_file:
the_file.write(rendered_tag_page)
build_stats['counts']['tag_pages'] += 1
logger.debug("Output %s." % relpath(the_file.name))
# Generate feeds
rss_feed_output_path = ensure_exists(settings.OUTPUT_CACHE_DIR / 'feeds/rss.xml')
atom_feed_output_path = ensure_exists(settings.OUTPUT_CACHE_DIR / 'feeds/atom.xml')
rss_feed = Rss201rev2Feed(
title=settings.FEED_TITLE,
link=settings.SITE_URL,
description=settings.FEED_DESCRIPTION,
feed_url=settings.FEED_URL
)
atom_feed = Atom1Feed(
title=settings.FEED_TITLE,
link=settings.SITE_URL,
description=settings.FEED_DESCRIPTION,
feed_url=settings.FEED_URL
)
for feed in (rss_feed, atom_feed):
for post in all_posts[:settings.FEED_ITEM_LIMIT]:
title = settings.JINJA_ENV.get_template('core/feeds/title.jinja2').render(post=post)
link = settings.JINJA_ENV.get_template('core/feeds/link.jinja2').render(post=post)
content = settings.JINJA_ENV.get_template('core/feeds/content.jinja2').render(post=post)
feed.add_item(
title=title,
link=link,
description=content,
pubdate=post.timestamp,
with open(tag_path, mode='wb', encoding='UTF-8') as the_file:
the_file.write(rendered_tag_page)
build_stats['counts']['tag_pages'] += 1
logger.debug("Output %s." % relpath(the_file.name))
# Generate feeds
rss_feed_output_path = ensure_exists(settings.OUTPUT_CACHE_DIR / 'feeds/rss.xml')
atom_feed_output_path = ensure_exists(settings.OUTPUT_CACHE_DIR / 'feeds/atom.xml')
rss_feed = Rss201rev2Feed(
title=settings.FEED_TITLE,
link=settings.SITE_URL,
description=settings.FEED_DESCRIPTION,
feed_url=settings.FEED_URL
)
atom_feed = Atom1Feed(
title=settings.FEED_TITLE,
link=settings.SITE_URL,
description=settings.FEED_DESCRIPTION,
feed_url=settings.FEED_URL
)
for feed in (rss_feed, atom_feed):
for post in all_posts[:settings.FEED_ITEM_LIMIT]:
title = settings.JINJA_ENV.get_template('core/feeds/title.jinja2').render(post=post)
link = settings.JINJA_ENV.get_template('core/feeds/link.jinja2').render(post=post)
content = settings.JINJA_ENV.get_template('core/feeds/content.jinja2').render(post=post)
feed.add_item(
title=title,
link=link,
description=content,
pubdate=post.timestamp,