本文整理汇总了Python中models.Entry.get_or_insert方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.get_or_insert方法的具体用法?Python Entry.get_or_insert怎么用?Python Entry.get_or_insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.get_or_insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_or_update_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_or_insert [as 别名]
def insert_or_update_entry(filename):
basename, extension = splitext(filename)
if extension in ['.markdown', '.meta']:
result = urlfetch.fetch(url = build_url(filename))
if result.status_code == 200:
entry = Entry.get_or_insert(basename)
if extension.endswith('.markdown'):
import markdown2
html = markdown2.markdown(result.content.decode('utf-8'))
if html:
jinja2 = Environment(extensions=[ImgurExtension])
entry.content = jinja2.from_string(html).render()
else:
try:
meta = yaml.load(result.content)
except Exception as ex:
logging.error('Failed to parse YAML: %s' % ex)
else:
entry.title = meta['title']
entry.tags = meta['tags']
entry.published = meta['published']
entry.slug = basename
entry.put()
else:
logging.error('failed to fetch %s' % filename)
示例2: add_or_update_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_or_insert [as 别名]
def add_or_update_entry(self, filename):
basename, extension = os.path.splitext(filename)
if extension in [".entry", ".meta"]:
result = urlfetch.fetch(url = build_url(filename))
if result.status_code == 200:
entry = Entry.get_or_insert(basename)
if extension.endswith(".entry"):
entry.content = jinja2_env.from_string(result.content.decode('utf-8')).render()
else:
try:
meta = yaml.load(result.content)
except:
logging.error("failed to parse YAML")
else:
entry.title = meta["name"]
entry.slug = basename
entry.put()
else:
logging.error("failed to fetch %s" % filename)