本文整理汇总了Python中model.Entry.link方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.link方法的具体用法?Python Entry.link怎么用?Python Entry.link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Entry
的用法示例。
在下文中一共展示了Entry.link方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import link [as 别名]
def post(self):
"""Parsing queued feeds"""
doc = feedparser.parse(self.request.body)
# Bozo feed handling
# stealed from PubSubHubbub subscriber repo
if doc.bozo:
logging.error("Bozo feed data. %s: %r", doc.bozo_exception.__class__.__name__, doc.bozo_exception)
if hasattr(doc.bozo_exception, "getLineNumber") and hasattr(doc.bozo_exception, "getMessage"):
line = doc.bozo_exception.getLineNumber()
logging.error("Line %d: %s", line, doc.bozo_exception.getMessage())
segment = self.request.body.split("\n")[line - 1]
logging.info("Body segment with error: %r", segment.decode("utf-8"))
return # fail fast
# WORKER['parser'] + `key`
key = self.request.path[len(WORKER["parser"]) :]
# Try to get the channel by key;
# fallback to feed id, if not found;
# and at last we'll resort to entry source id,
# to find out the associated channel
channel = None
uid = doc.feed.id
try:
channel = Channel.get(key)
except:
channel = Channel.all().filter("uid =", uid).get()
else:
# First time get the notification,
# so update channel's properties
if channel and not channel.uid:
channel.title = doc.feed.title.split(" - ")[0]
channel.uid = uid
# Fallback to topic feed, if no link found
channel.link = doc.feed.get("link", channel.topic)
channel.put()
updates = []
for e in doc.entries:
author = e.author if e.get("author") else None
content = e.content[0].value if e.get("content") else e.summary
# Fallback to published if no updated field.
t = e.updated_parsed if e.get("updated_parsed") else e.published_parsed
updated = datetime(t[0], t[1], t[2], t[3], t[4], t[5])
# If we have this entry already in datastore, then the entry
# should be updated instead of inserted.
ent = Entry.all().filter("uid =", e.id).get()
if not ent:
if not channel:
uid = e.source.id
channel = Channel.all().filter("uid =", uid).get()
ent = Entry(
title=e.title,
link=e.link,
content=content,
author=author,
updated=updated,
uid=e.id,
channel=channel,
)
logging.info("Get new entry: %s" % e.id)
else:
ent.title = e.title
ent.link = e.link
ent.content = content
ent.author = author
ent.updated = updated
logging.info("Get updated entry: %s" % e.id)
updates.append(ent)
db.put(updates)