def send_today_in_history(user_id): u = User.get(user_id) if not u: return setting = u.get_profile_item("email_remind_today_in_history") if setting == 'N': print '---user %s does not like to receive remind mail' % u.id return email = u.get_email() if not email: print '---- user %s no email' % u.id return yesterday_ids = get_status_ids_yesterday(u.id, day=(datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")) status_of_yesterday = Status.gets(yesterday_ids) history_ids = get_status_ids_today_in_history(u.id, day=datetime.datetime.now().strftime("%Y-%m-%d")) status_of_today_in_history = Status.gets(history_ids) intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()] intros = filter(None, intros) history_ids = get_status_ids_today_in_history(u.id, day=datetime.datetime.now().strftime("%Y-%m-%d")) d = {} for s in Status.gets(history_ids): t = s.create_time.strftime("%Y-%m-%d") if d.has_key(t): d[t].append(s) else: d[t] = [s] status_of_today_in_history = d from past.consts import YESTERDAY if not (status_of_yesterday or status_of_today_in_history): print '--- user %s has no status in history' % u.id return from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader('past', 'templates')) env.filters['wrap_long_line'] = wrap_long_line env.filters['nl2br'] = filters.nl2br env.filters['clear_html_element'] = clear_html_element t = env.get_template('mail.html') m = t.module html = m.status_in_past(status_of_yesterday, status_of_today_in_history, YESTERDAY, config, intros) html = html.encode("utf8") subject = '''来自thepast.me的提醒 %s''' % datetime.datetime.now().strftime("%Y-%m-%d") text = '' print '--- send reminding to %s %s' %(user_id, email) send_mail(["%s" % email], "Today of The Past<*****@*****.**>", subject, text, html, files=[], server="localhost")
def send_yesterday(user_id, now=None): if not now: now = datetime.datetime.now() u = User.get(user_id) if not u: return setting = u.get_profile_item("email_remind_today_in_history") if setting == 'N': print '---user %s does not like to receive remind mail' % u.id return email = u.get_email() if not email: print '---- user %s no email' % u.id return yesterday_ids = get_status_ids_yesterday(u.id, now) status_of_yesterday = Status.gets(yesterday_ids) intros = [ u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values() ] intros = filter(None, intros) from past.consts import YESTERDAY if not status_of_yesterday: print '--- user %s has no status in yesterday' % u.id return from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader('past', 'templates')) env.filters['wrap_long_line'] = wrap_long_line env.filters['nl2br'] = filters.nl2br env.filters['stream_time'] = filters.stream_time env.filters['clear_html_element'] = clear_html_element t = env.get_template('mail.html') m = t.module if now: y = (now - datetime.timedelta(days=1)).strftime("%Y-%m-%d") else: y = YESTERDAY html = m.status_in_past(status_of_yesterday, None, y, config, intros) html = html.encode("utf8") subject = '''thepast.me|整理自己的故事 %s''' % now.strftime("%Y-%m-%d") text = '' print '--- send reminding to %s %s' % (user_id, email) send_mail(["%s" % email], "thepast<*****@*****.**>", subject, text, html)
def send_yesterday(user_id, now=None): if not now: now = datetime.datetime.now() u = User.get(user_id) if not u: return setting = u.get_profile_item("email_remind_today_in_history") if setting == "N": print "---user %s does not like to receive remind mail" % u.id return email = u.get_email() if not email: print "---- user %s no email" % u.id return yesterday_ids = get_status_ids_yesterday(u.id, now) status_of_yesterday = Status.gets(yesterday_ids) intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()] intros = filter(None, intros) from past.consts import YESTERDAY if not status_of_yesterday: print "--- user %s has no status in yesterday" % u.id return from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader("past", "templates")) env.filters["wrap_long_line"] = wrap_long_line env.filters["nl2br"] = filters.nl2br env.filters["stream_time"] = filters.stream_time env.filters["clear_html_element"] = clear_html_element t = env.get_template("mail.html") m = t.module if now: y = (now - datetime.timedelta(days=1)).strftime("%Y-%m-%d") else: y = YESTERDAY html = m.status_in_past(status_of_yesterday, None, y, config, intros) html = html.encode("utf8") subject = """thepast.me|整理自己的故事 %s""" % now.strftime("%Y-%m-%d") text = "" print "--- send reminding to %s %s" % (user_id, email) send_mail(["%s" % email], "thepast<*****@*****.**>", subject, text, html)
def past(): intros = [g.user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()] intros = filter(None, intros) yesterday_ids = get_status_ids_yesterday(g.user.id) status_of_yesterday = Status.gets(yesterday_ids) history_ids = get_status_ids_today_in_history(g.user.id) d = {} for s in Status.gets(history_ids): t = s.create_time.strftime("%Y-%m-%d") if d.has_key(t): d[t].append(s) else: d[t] = [s] status_of_today_in_history = d from past.consts import YESTERDAY return render_template("past.html", **locals())
def past(): intros = [ g.user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values() ] intros = filter(None, intros) now = datetime.datetime.now() yesterday_ids = get_status_ids_yesterday(g.user.id, now) status_of_yesterday = Status.gets(yesterday_ids) history_ids = get_status_ids_today_in_history(g.user.id, now) d = {} for s in Status.gets(history_ids): t = s.create_time.strftime("%Y-%m-%d") if d.has_key(t): d[t].append(s) else: d[t] = [s] status_of_today_in_history = d from past.consts import YESTERDAY return render_template("past.html", **locals())
def send_today_in_history(user_id, now=None, include_yestorday=False): if not now: now = datetime.datetime.now() u = User.get(user_id) if not u: return setting = u.get_profile_item("email_remind_today_in_history") if setting == 'N': print '---user %s does not like to receive remind mail' % u.id return email = u.get_email() if not email: print '---- user %s no email' % u.id return history_ids = get_status_ids_today_in_history(u.id, now) status_of_today_in_history = Status.gets(history_ids) if include_yestorday: yesterday_ids = get_status_ids_yesterday(u.id, now) status_of_yesterday = Status.gets(yesterday_ids) else: status_of_yesterday = None intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()] intros = filter(None, intros) d = {} for s in Status.gets(history_ids): t = s.create_time.strftime("%Y-%m-%d") if d.has_key(t): d[t].append(s) else: d[t] = [s] status_of_today_in_history = d from past.consts import YESTERDAY if not (status_of_today_in_history or (include_yestorday and status_of_yesterday)): print '--- user %s has no status in history' % u.id return from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader('past', 'templates')) env.filters['wrap_long_line'] = wrap_long_line env.filters['nl2br'] = filters.nl2br env.filters['clear_html_element'] = clear_html_element env.filters['isstr'] = lambda x: isinstance(x, basestring) t = env.get_template('mail.html') m = t.module if now: y = (now - datetime.timedelta(days=1)).strftime("%Y-%m-%d") else: y = YESTERDAY html = m.status_in_past(status_of_yesterday, status_of_today_in_history, y, config, intros) html = html.encode("utf8") subject = '''thepast.me|整理自己的故事 %s''' % now.strftime("%Y-%m-%d") text = '' print '--- send reminding to %s %s' %(user_id, email) send_mail(["%s" % email], "thepast<*****@*****.**>", subject, text, html)