本文整理汇总了Python中r2.models.Link._somethinged方法的典型用法代码示例。如果您正苦于以下问题:Python Link._somethinged方法的具体用法?Python Link._somethinged怎么用?Python Link._somethinged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.Link
的用法示例。
在下文中一共展示了Link._somethinged方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_realtime_email_queue
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _somethinged [as 别名]
def _run_realtime_email_queue(msgs, chan):
if time.time() - run_realtime_email_queue.last_got_accounts > 600:
#-- Pick up a fresh list of accounts, if we havenn't done so recently, in case settings change
if g.email_debug:
g.log.info('Getting accounts')
run_realtime_email_queue.accounts = Account._query(Account.c.email != None, sort = asc('_date'), data=True)
run_realtime_email_queue.last_got_accounts = time.time()
for msg in msgs:
# msg.body contains the unique name of the post, comment or message, e.g. 't1_2n'(comment #95) or 't6_q'(post #26)
fullname = str(msg.body)
fullname_type = fullname[0:2]
id36 = fullname[3:]
if g.email_debug:
g.log.info('msg: %r', fullname)
howold = (datetime.datetime.now() - msg.timestamp).total_seconds()
if howold < 110:
# Wait until this item is 2 minutes old, to allow time for corrections
if g.email_debug:
g.log.info('waiting for a moment')
time.sleep(120 - howold)
is_com = is_post = False
thing = link = comment = None
if fullname_type == 't1':
# a comment
is_com = True
comment = Comment._byID36(id36, data=True)
if g.email_debug:
g.log.info('comment: %r', comment.body)
thing = comment
author = Account._byID(comment.author_id, True)
kind = Email.Kind.REALTIME_COMMENT
template = 'email_realtime_comment.html'
link = Link._byID(comment.link_id, data=True)
subject = 'Re: %s' % link.title
sr_id = comment.sr_id
elif fullname_type == 't6':
# a post/link
is_post = True
link = Link._byID36(id36, data=True)
if g.email_debug:
g.log.info('post: %r', link.title)
thing = link
author = Account._byID(link.author_id, True)
kind = Email.Kind.REALTIME_POST
template = 'email_realtime_post.html'
subject = link.title
sr_id = link.sr_id
else:
return
sr = Subreddit._byID(sr_id, data=True)
subject = "[%s] %s" % (sr.name, subject)
for account in run_realtime_email_queue.accounts:
sub = sr.get_subscriber(account)
if is_com:
if hasattr(sub,'email_comments') and sub.email_comments:
if g.email_debug:
g.log.info(' account %r: we should send this comment, because of the space setting', account.name)
whysend = 'space'
else:
email_thread = Link._somethinged(SaveHide, account, link, 'email')[account,link,'email']
if email_thread:
if g.email_debug:
g.log.info(' account %r: we should send this comment, because of the thread setting', account.name)
whysend = 'thread'
else:
continue
elif is_post:
if hasattr(sub,'email_posts') and sub.email_posts:
if g.email_debug:
g.log.info(' account %r: we should send this post', account.name)
whysend = 'space'
else:
continue
if not ('session' in locals()):
# Open the SMTP session
if g.email_debug:
g.log.info('Opening SMTP session')
session = open_smtp_session()
# Render the template
html_email_template = g.mako_lookup.get_template(template)
html_body = html_email_template.render(link=link, comment=comment, thing=thing, account=account, sub=sub, whysend=whysend)
from_email = '"%s" <%s>' % (g.realtime_email_from_name, g.share_reply,)
send_html_email(account.email, g.share_reply, subject, html_body, from_full=from_email, session=session)
if g.email_debug:
g.log.info(' sent to %r at %r', account.name, account.email)
#.........这里部分代码省略.........