本文整理汇总了Python中tiddlyweb.model.tiddler.Tiddler.fields["heading"]方法的典型用法代码示例。如果您正苦于以下问题:Python Tiddler.fields["heading"]方法的具体用法?Python Tiddler.fields["heading"]怎么用?Python Tiddler.fields["heading"]使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tiddlyweb.model.tiddler.Tiddler
的用法示例。
在下文中一共展示了Tiddler.fields["heading"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tiddlers_from_rss
# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import fields["heading"] [as 别名]
def tiddlers_from_rss(rss_url):
"""Import an rss feed into a bag using a given rule number <url> <bag>"""
DEFAULT_TIDDLER_TEXT = u"<html><p><a href=\"%s\">%s</a><br/>%s</p></html>"
h = httplib2.Http()
try:
resp,content = h.request(rss_url,method='GET')
except httplib2.RelativeURIError:
try:
content = open(rss_url,"r")
content = "".join(content.readlines())
except IOError:
content = ""
resp = {"status":200}
content = content.replace("media:thumbnail","media_thumbnail") #this is a workaround to allow media thumbnails to work.
content = content.replace("media:content","media_thumbnail") #this is a workaround to allow media thumbnails to work.
feed = feedparser.parse(content)
print "url returned status code %s"%resp["status"]
tiddlers = []
for entry in feed.entries:
try:
unique_title = entry.id
except AttributeError:
try:
unique_title= entry.link
except AttributeError:
unique_title= "%s_%s"%(entry.title,rss_url)
unique_title = unique_title.replace("/","_").replace(".","_").replace(":","_")
imtiddler = Tiddler(unique_title)
imtiddler.fields["heading"] = entry.title #save the original title for display purposes
tags = []
try:
for tag in entry.tags:
tags.append("["+tag.term+"]")
except AttributeError:
pass
imtiddler.tags = tags
description = None
try:
description = entry.summary
except AttributeError:
try:
description = entry.content[0]["value"]
except AttributeError:
description = u"No description."
try:
imtiddler.modifier = entry.author
except AttributeError:
imtiddler.modifier = "Unknown"
try:
posted_date = entry["updated_parsed"]
yr = posted_date[0]
mo = posted_date[1]
dy = posted_date[2]
hr = posted_date[3]
mi = posted_date[4]
sec = posted_date[5]
imtiddler.modified = "%02d%02d%02d%02d%02d%02d"%(yr,mo,dy,hr,mi,sec)
except KeyError:
pass #use default
if "pos" in entry:
longlat = entry["pos"].split(" ")
imtiddler.fields["geo.lat"] = longlat[0]
imtiddler.fields["geo.long"] = longlat[1]
elif "point" in entry:
longlat = entry["point"].split(" ")
imtiddler.fields["geo.lat"] = longlat[0]
imtiddler.fields["geo.long"] = longlat[1]
try:
link = entry.link
except AttributeError:
link = ""
imtiddler.text = DEFAULT_TIDDLER_TEXT%(link,entry.title,description)
imtiddler.fields.update({"rssurl":rss_url})
try:
name = config['imrss']['module']
f = __import__(name,fromlist=True)
imtiddler = f.handler(rss_url,imtiddler,entry,feed=feed)
except KeyError:
pass
if imtiddler:
tiddlers.append(imtiddler)
print "tiddlers ready for store (%s)"%(len(tiddlers))
return tiddlers