本文整理汇总了Python中models.Log.datetime方法的典型用法代码示例。如果您正苦于以下问题:Python Log.datetime方法的具体用法?Python Log.datetime怎么用?Python Log.datetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Log
的用法示例。
在下文中一共展示了Log.datetime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_actions
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import datetime [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))