当前位置: 首页>>代码示例>>Python>>正文


Python Tiddler.fields["heading"]方法代码示例

本文整理汇总了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
开发者ID:FND,项目名称:tiddlywiki-svn-mirror,代码行数:94,代码来源:imrss.py


注:本文中的tiddlyweb.model.tiddler.Tiddler.fields["heading"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。