本文整理汇总了Python中models.Feed.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Feed.get_by_id方法的具体用法?Python Feed.get_by_id怎么用?Python Feed.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Feed
的用法示例。
在下文中一共展示了Feed.get_by_id方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def get(self):
feed_id, feed_url = self.request.get('feed_id'), \
self.request.get('feed_url')
url_result = urllib2.urlopen(feed_url)
feed_result = fd.parse(url_result)
if feed_result.bozo == 1:
logging.error('fetch error, id: %s, url: %s, error: %s',
feed_id, feed_url, feed_result.bozo_exception)
return
feed_update_time = feed_result.get('updated', datetime.utcnow)
has_update = True
f = Feed.get_by_id(int(feed_id))
if f.is_allow_fetch(feed_update_time):
for entry in feed_result.entries:
if entry.published_parsed <= f.lastedPublishedTime:
logging.info('no updated, id: %s, url: %s', feed_id,
feed_url)
has_update = False
break
e = Entry(title = entry.title,
url = entry.link,
author = entry.author,
content = entry.content),
publishedTime = entry.published_parsed)
e.put()
logging.debug('fetch entry, url: %s', entry.link)
示例2: get_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def get_feed(feed_id):
""" Retrieve a feed from memcache or generate it if it does not exist """
xml = memcache.get(feed_id) # In memcache?
if xml is None:
feed = Feed.get_by_id(int(feed_id))
rss = None
if feed:
if feed.public_board:
rss = TrelloRSS(
constants.KEY,
channel_title=feed.channel_title,
rss_channel_link=feed.channel_link,
description=feed.channel_description)
else:
user = feed.user.get()
rss = TrelloRSS(
constants.KEY,
token=user.auth_token,
channel_title=feed.channel_title,
rss_channel_link=feed.channel_link,
description=feed.channel_description)
if feed.get_all:
if feed.actions:
rss.get_all(items=feed.actions)
else:
rss.get_all()
else:
if feed.actions:
rss.get_from(feed.board_id,public_board=feed.public_board,items=feed.actions)
else:
rss.get_from(feed.board_id,public_board=feed.public_board)
xml = rss.rss
memcache.add(key=feed_id, value=xml, time=1800) # Expire after 30 minutes
return xml
示例3: published_entries_for_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def published_entries_for_feed(feed_id):
feed = Feed.get_by_id(feed_id, parent=g.user.key)
if not feed:
return jsonify_error(message="Can't find that feed")
feed_data = feed.to_json()
entries = [entry.to_json(include=['title', 'link', 'published', 'published_at']) for entry in Entry.latest_published(feed).fetch(20)]
feed_data['entries'] = entries
return jsonify(status='ok', data=feed_data)
示例4: delete_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def delete_feed(feed_id):
"""Get a feed"""
feed = Feed.get_by_id(feed_id, parent=g.user.key)
if not feed:
return jsonify_error(message="Can't find that feed")
Entry.delete_for_feed(feed)
feed.key.delete()
return jsonify(status='ok')
示例5: feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def feed(feed_id):
"""Get a feed"""
feed = Feed.get_by_id(feed_id, parent=g.user.key)
if not feed:
return jsonify_error(message="Can't find that feed")
feed_data = feed.to_json()
entries = [entry.to_dict(include=['guid', 'published', 'extra_info']) for entry in Entry.latest_for_feed(feed).fetch(10)]
feed_data['entries'] = entries
return jsonify(status='ok', data=feed_data)
示例6: admin_feed_form
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def admin_feed_form(request, feed_id=None):
if feed_id:
feed = Feed.get_by_id(int(feed_id))
else:
feed = None
if request.method == "POST":
form = FeedForm(request.POST, instance=feed)
if form.is_valid():
feed = form.save(commit=False)
feed.save()
return HttpResponseRedirect("../")
else:
form = FeedForm(instance=feed)
return render_to_response("planet/admin_feed_form.html", {"feed_id": feed_id, "form": form})
示例7: save_feed_preview
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def save_feed_preview(feed_id):
"""preview a saved feed"""
form = FeedUpdate(request.args)
if not form.validate():
return jsonify_error(message="Invalid update data")
feed = Feed.get_by_id(feed_id, parent=g.user.key)
if not feed:
return jsonify_error(message="Can't find that feed")
form.populate_obj(feed)
feed.preview = True
preview_entries = Entry.entry_preview(Entry.latest_published(feed).fetch(3), feed, format=True)
return jsonify(status='ok', data=preview_entries)
示例8: feed_entry_publish
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def feed_entry_publish(feed_id, entry_id):
"""Get a feed"""
logger.info('Manually publishing Feed:%s Entry: %s', feed_id, entry_id)
feed = Feed.get_by_id(feed_id, parent=g.user.key)
if not feed:
return jsonify_error(message="Can't find that feed")
entry = Entry.get_by_id(entry_id, parent=feed.key)
if not entry:
return jsonify_error(message="Can't find that entry")
entry.publish_entry(feed)
entry.overflow = False
entry.put()
return jsonify(status='ok')
示例9: feed_change
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def feed_change(feed_id):
"""Get a feed"""
form = FeedUpdate(request.form)
if not form.validate():
return jsonify_error(message="Invalid update data")
feed = Feed.get_by_id(feed_id, parent=g.user.key)
if not feed:
return jsonify_error(message="Can't find that feed")
form.populate_obj(feed)
feed.put()
feed_data = feed.to_json()
entries = [entry.to_dict(include=['title', 'link', 'published', 'published_at']) for entry in Entry.latest_for_feed(feed).fetch(10)]
feed_data['entries'] = entries
return jsonify(status='ok', data=feed_data)
示例10: feed_entry_publish
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def feed_entry_publish(feed_id, entry_id):
"""Get a feed"""
logger.info('Manually publishing Feed:%s Entry: %s', feed_id, entry_id)
key = ndb.Key(urlsafe=entry_id)
feed = Feed.get_by_id(feed_id, parent=g.user.key)
if not (feed and key.parent() == feed.key):
return jsonify_error(message="Can't find that feed")
entry = key.get()
if not entry:
return jsonify_error(message="Can't find that entry")
entry.publish_entry(feed).get_result()
entry.overflow = False
entry.put()
return jsonify(status='ok')
示例11: admin_feed_cleanup
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import get_by_id [as 别名]
def admin_feed_cleanup(request, feed_id):
feed = Feed.get_by_id(int(feed_id))
for e in db.Query(Entry).filter("feed", feed):
e.delete()
return HttpResponseRedirect("../")