Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement user page and working digest email and reminder email.
- Loading branch information
Showing
8 changed files
with
127 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import datetime | ||
|
||
class Eastern_tzinfo(datetime.tzinfo): | ||
"""Implementation of the Eastern timezone. | ||
Adapted from http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html | ||
""" | ||
def utcoffset(self, dt): | ||
return datetime.timedelta(hours=-5) + self.dst(dt) | ||
|
||
def _FirstSunday(self, dt): | ||
"""First Sunday on or after dt.""" | ||
return dt + datetime.timedelta(days=(6-dt.weekday())) | ||
|
||
def dst(self, dt): | ||
# 2 am on the second Sunday in March | ||
dst_start = self._FirstSunday(datetime.datetime(dt.year, 3, 8, 2)) | ||
# 1 am on the first Sunday in November | ||
dst_end = self._FirstSunday(datetime.datetime(dt.year, 11, 1, 1)) | ||
|
||
if dst_start <= dt.replace(tzinfo=None) < dst_end: | ||
return datetime.timedelta(hours=1) | ||
else: | ||
return datetime.timedelta(hours=0) | ||
|
||
def tzname(self, dt): | ||
if self.dst(dt) == datetime.timedelta(hours=0): | ||
return "EST" | ||
else: | ||
return "EDT" | ||
|
||
|
||
def date_for_new_snippet(): | ||
"""Return next Monday, unless it is Monday (0) or Tuesday (1)""" | ||
today = datetime.datetime.now(Eastern_tzinfo()).date() | ||
if (today.weekday() < 2): | ||
aligned = today - datetime.timedelta(days=today.weekday()) | ||
else: | ||
aligned = today + datetime.timedelta(days=(7 - today.weekday())) | ||
return aligned | ||
|
||
def date_for_retrieval(): | ||
"""Always return the most recent Monday.""" | ||
today = datetime.datetime.now(Eastern_tzinfo()).date() | ||
return today - datetime.timedelta(days=today.weekday()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,48 @@ | ||
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 | ||
|
||
class ReminderEmail(webapp.RequestHandler): | ||
def get(self): | ||
pass | ||
taskqueue.add(url='/onereminder', params={'user': key}) | ||
|
||
class DigestEmail(webapp.RequestHandler): | ||
def get(self): | ||
# Find all users and add to queue | ||
taskqueue.add(url='/onedigest', params={'user': key}) | ||
from dateutil import * | ||
from model import * | ||
|
||
class OneReminder(webapp.RequestHandler): | ||
def post(self): | ||
key = self.request.get('user') | ||
mail.send_mail(sender="Example.com Support <support@example.com>", | ||
to="Albert Johnson <Albert.Johnson@example.com>", | ||
subject="Your account has been approved", | ||
body=""" | ||
Dear Albert: | ||
REMINDER = """ | ||
Hey nerd, | ||
Your example.com account has been approved. You can now visit | ||
http://www.example.com/ and sign in using your Google Account to | ||
access new features. | ||
The kids want to know what you're up to. Don't leave 'em hanging. | ||
""" | ||
|
||
Please let us know if you have any questions. | ||
The example.com Team | ||
""") | ||
class ReminderEmail(webapp.RequestHandler): | ||
def __send_mail(self, recipient): | ||
mail.send_mail(sender="snippets <snippets@fssnippets.appspotmail.com>", | ||
to=recipient, | ||
subject="Snippet time!", | ||
body=REMINDER) | ||
|
||
class OneDigest(webapp.RequestHandler): | ||
def post(self): | ||
key = self.request.get('user') | ||
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. | ||
self.__send_mail(user.user.email()) | ||
|
||
class DigestEmail(webapp.RequestHandler): | ||
def __send_mail(self, recipient, body): | ||
mail.send_mail(sender="snippets <snippets@fssnippets.appspotmail.com>", | ||
to=recipient, | ||
subject="Snippet delivery!", | ||
body=body) | ||
|
||
def __snippet_to_text(self, snippet): | ||
divider = '-' * 30 | ||
return '%s\n%s\n%s' % (snippet.user.user.email(), divider, snippet.text) | ||
|
||
def get(self): | ||
all_users = User.all().filter("enabled =", True).fetch(500) | ||
d = date_for_retrieval() | ||
all_snippets = Snippet.all().filter("date =", d).fetch(500) | ||
# TODO: Build custom emails | ||
body = '\n\n\n'.join([self.__snippet_to_text(s) for s in all_snippets]) | ||
for user in all_users: | ||
self.__send_mail(user.user.email(), body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block body %} | ||
<h2>{{ user.user.email }}</h2> | ||
|
||
{% for snippet in snippets %} | ||
<b>{{ snippet.date }}</b><br/> | ||
{{ snippet.text }} | ||
<br/></br> | ||
{% endfor %} | ||
|
||
{% endblock %} |