forked from CNBorn/checknerds
/
cronmail.py
95 lines (67 loc) · 2.41 KB
/
cronmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
# ****************************************************************
# CheckNerds - www.checknerds.com
# version 1.0, codename Nevada->California
# - cronmail.py
# Copyright (C) CNBorn, 2008-2009
# http://cnborn.net, http://twitter.com/CNBorn
#
# ****************************************************************
import os
import urllib
import cgi
import wsgiref.handlers
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext import db
import time
import datetime
import string
from google.appengine.ext.webapp import template
from google.appengine.api import images
import memcache
import tarsusaCore
from modules import *
from base import *
import logging
from google.appengine.api import mail
class DailyBriefReport(tarsusaRequestHandler):
def get(self):
user_address = "cnborn@gmail.com"
if not mail.is_email_valid(user_address):
# prompt user to enter a valid address
#print 'error'
pass
else:
if self.chk_login():
CurrentUser = self.get_user_db()
tarsusaItemCollection = tarsusaCore.get_dailyroutine(CurrentUser.key().id())
tarsusaItem_DueToday = tarsusaCore.get_ItemsDueToday(CurrentUser.key().id())
ItemsInMail = ''
for eachItem in tarsusaItem_DueToday:
ItemsInMail += "<li><a href=/item/" + eachItem['id'] + ">" + eachItem['name'] + "</a></li>"
DueTodayTotal = len(tarsusaItemCollection) + len(tarsusaItem_DueToday)
message = mail.EmailMessage()
message.sender = "cnborn@gmail.com"
message.to = user_address
message.subject = "CheckNerds每日提醒 - " + str(datetime.date.today()) + " - " + str(DueTodayTotal) + "项事项"
template_values = {
'PrefixCSSdir': "/",
'UserNickName': "访客",
'AnonymousVisitor': "Yes",
'Today': str(datetime.date.today()),
'EmailTitle': message.subject,
'CountItemsDueToday': str(DueTodayTotal),
'ItemsDueToday':tarsusaItemCollection + tarsusaItem_DueToday,
}
path = os.path.join(os.path.dirname(__file__), 'pages/mail/dailybriefing.html')
final_body = template.render(path, template_values)
message.html = final_body
message.send()
#mail.send_mail(sender_address, user_address, subject, final_body)
def main():
application = webapp.WSGIApplication([('/cronmail', DailyBriefReport)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == "__main__":
main()