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


Python Log.item_fullname方法代码示例

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


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

示例1: execute_actions

# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import item_fullname [as 别名]
    def execute_actions(self, item, match):
        """Performs the action(s) for the condition.
        
        Also sends any comment/messages (if set) and creates a log entry.
        """
        if self.action or self.comment or self.modmail or self.message:
            log_actions = [self.action]
        else:
            log_actions = []

        # perform the action
        if self.action == 'remove':
            item.remove(False)
        elif self.action == 'spam':
            item.remove(True)
        elif self.action == 'approve':
            item.approve()
        elif self.action == 'report':
            item.report()

        # set flairs
        if (isinstance(item, praw.objects.Submission) and 
                (self.link_flair_text or self.link_flair_class)):
            text = replace_placeholders(self.link_flair_text, item, match)
            css_class = replace_placeholders(self.link_flair_class, item, match)
            item.set_flair(text, css_class.lower())
            item.link_flair_text = text
            item.link_flair_css_class = css_class.lower()
            log_actions.append('link_flair')
        if (self.user_flair_text or self.user_flair_class):
            text = replace_placeholders(self.user_flair_text, item, match)
            css_class = replace_placeholders(self.user_flair_class, item, match)
            item.subreddit.set_flair(item.author, text, css_class.lower())
            item.author_flair_text = text
            item.author_flair_css_class = css_class.lower()
            log_actions.append('user_flair')

        if self.comment:
            comment = self.build_message(self.comment, item, match,
                                         disclaimer=True)
            if isinstance(item, praw.objects.Submission):
                response = item.add_comment(comment)
            elif isinstance(item, praw.objects.Comment):
                response = item.reply(comment)
            response.distinguish()

        if self.modmail:
            message = self.build_message(self.modmail, item, match,
                                         permalink=True)
            subject = replace_placeholders(self.modmail_subject, item, match)
            r.send_message('/r/'+item.subreddit.display_name, subject, message)

        if self.message and item.author:
            message = self.build_message(self.message, item, match,
                                         disclaimer=True, permalink=True)
            subject = replace_placeholders(self.message_subject, item, match)
            r.send_message(item.author.name, subject, message)

        log_entry = Log()
        log_entry.item_fullname = item.name
        log_entry.condition_yaml = self.yaml
        log_entry.datetime = datetime.utcnow()

        for entry in log_actions:
            log_entry.action = entry
            session.add(log_entry)

        session.commit()

        item_time = datetime.utcfromtimestamp(item.created_utc)
        logging.info('Matched {0}, actions: {1} (age: {2})'
                     .format(get_permalink(item).encode('ascii', 'ignore'),
                             log_actions,
                             datetime.utcnow() - item_time))
开发者ID:goldguy81,项目名称:AutoModerator,代码行数:76,代码来源:automoderator.py


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