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


Python Entry.author方法代码示例

本文整理汇总了Python中model.Entry.author方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.author方法的具体用法?Python Entry.author怎么用?Python Entry.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Entry的用法示例。


在下文中一共展示了Entry.author方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import author [as 别名]
	def post(self):

		if not self.is_login:
			self.redirect(users.create_login_url(self.request.uri))
		filename=self.param('filename')
		do_comment=self.paramint('c',0)
		if filename[:4]=='img/':#处理图片
			new_filename=filename.split('/')[1]
			mtype =new_filename.split('.')[1]
			bits = self.request.body
			media=Media.all().filter('name =',new_filename)
			if media.count()>0:
				media=media[0]
			else:
				media=Media()
			media.name=new_filename
			media.mtype=mtype
			media.bits=bits
			media.put()
			bid='_'.join(new_filename.split('_')[:-1])
			entries=Entry.all().filter('slug =',bid)
			if entries.count()>0:
				entry=entries[0]
				entry.content=entry.content.replace(filename,'/media/'+str(media.key()))
				entry.put()
			return

		if filename=="index.html" or filename[-5:]!='.html':
			return
		#处理html页面
		bid=filename[:-5]
		try:

			soup=BeautifulSoup(self.request.body)
			bp=soup.find(id='bp')
			title=self.getChineseStr( soup.title.text)
			logging.info(bid)
			pubdate=self.getdate( bp.find(id='bp-'+bid+'-publish').text)
			body=bp.find('div','blogpost')

			entries=Entry.all().filter('title = ',title)
			if entries.count()<1:
				entry=Entry()
			else:
				entry=entries[0]
##			entry=Entry.get_by_key_name(bid)
##			if not entry:
##				entry=Entry(key_name=bid)
			entry.slug=bid
			entry.title=title
			entry.author_name=self.login_user.nickname()
			entry.date=pubdate
			entry.settags("")
			entry.content=unicode(body)
			entry.author=self.login_user

			entry.save(True)
			if do_comment>0:
				comments=soup.find('div','comments','div')
				if comments:
					for comment in comments.contents:
						name,date=comment.h5.text.split(' - ')
						# modify by lastmind4
						name_date_pair = comment.h5.text
						if name_date_pair.index('- ') == 0:
							name_date_pair = 'Anonymous ' + name_date_pair
						name,date=name_date_pair.split(' - ')

						key_id=comment.h5['id']
						date=self.getdate(date)
						content=comment.contents[1].text
						comment=Comment.get_or_insert(key_id,content=content)
						comment.entry=entry
						comment.date=date
						comment.author=name
						comment.save()

		except Exception,e :
			logging.info("import error: %s"%e.message)
开发者ID:Alwnikrotikz,项目名称:micolog2,代码行数:81,代码来源:live_import.py

示例2: post

# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import author [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)
开发者ID:juvenn,项目名称:microupdater,代码行数:75,代码来源:sub.py


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