-
Notifications
You must be signed in to change notification settings - Fork 79
/
emails.py
67 lines (53 loc) · 2.25 KB
/
emails.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
import logging
from google.appengine.api import mail
from google.appengine.api import taskqueue
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from dateutil import *
from model import *
REMINDER = """
Hey nerd,
The kids want to know what you're up to. Don't leave 'em hanging.
"""
class ReminderEmail(webapp.RequestHandler):
def get(self):
all_users = User.all().filter("enabled =", True).fetch(500)
for user in all_users:
# TODO: Check if one has already been submitted for this period.
taskqueue.add(url='/onereminder', params={'email': user.email})
class OneReminderEmail(webapp.RequestHandler):
def post(self):
mail.send_mail(sender="snippets <[email protected]>",
to=self.request.get('email'),
subject="Snippet time!",
body=REMINDER)
def get(self):
post(self)
class DigestEmail(webapp.RequestHandler):
def get(self):
all_users = User.all().filter("enabled =", True).fetch(500)
for user in all_users:
taskqueue.add(url='/onedigest', params={'email': user.email})
class OneDigestEmail(webapp.RequestHandler):
def __send_mail(self, recipient, body):
mail.send_mail(sender="snippets <[email protected]>",
to=recipient,
subject="Snippet delivery!",
body=body)
def __snippet_to_text(self, snippet):
divider = '-' * 30
return '%s\n%s\n%s' % (snippet.user.pretty_name(), divider, snippet.text)
def get(self):
post(self)
def post(self):
user = user_from_email(self.request.get('email'))
d = date_for_retrieval()
all_snippets = Snippet.all().filter("date =", d).fetch(500)
all_users = User.all().fetch(500)
following = compute_following(user, all_users)
logging.info(all_snippets)
body = '\n\n\n'.join([self.__snippet_to_text(s) for s in all_snippets if s.user.email in following])
if body:
self.__send_mail(user.email, 'https://fssnippets.appspot.com\n\n' + body)
else:
logging.info(user.email + ' not following anybody.')