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 | Original file line | 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,37 +1,48 @@ | |||
import logging | |||
|
|||
from google.appengine.api import mail | from google.appengine.api import mail | ||
from google.appengine.api import taskqueue | from google.appengine.api import taskqueue | ||
from google.appengine.ext import webapp | from google.appengine.ext import webapp | ||
from google.appengine.ext.webapp import util | from google.appengine.ext.webapp import util | ||
|
|
||
class ReminderEmail(webapp.RequestHandler): | from dateutil import * | ||
def get(self): | from model import * | ||
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}) | |||
|
|
||
class OneReminder(webapp.RequestHandler): | REMINDER = """ | ||
def post(self): | Hey nerd, | ||
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: | |||
Your example.com account has been approved. You can now visit | The kids want to know what you're up to. Don't leave 'em hanging. | ||
http://www.example.com/ and sign in using your Google Account to | """ | ||
access new features. | |||
|
|
||
Please let us know if you have any questions. | class ReminderEmail(webapp.RequestHandler): | ||
def __send_mail(self, recipient): | |||
The example.com Team | mail.send_mail(sender="snippets <snippets@fssnippets.appspotmail.com>", | ||
""") | to=recipient, | ||
subject="Snippet time!", | |||
body=REMINDER) | |||
|
|
||
class OneDigest(webapp.RequestHandler): | def get(self): | ||
def post(self): | all_users = User.all().filter("enabled =", True).fetch(500) | ||
key = self.request.get('user') | 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 | Original file line | 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 %} |