Permalink
Browse files

Initial commit before getting rid of task queue for now

  • Loading branch information...
0 parents commit f1f9d94c7e42d78096938305c3d09a0aaf5e1a7b @kushal committed Jan 9, 2011
Showing with 191 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. 0 README
  3. +15 −0 app.yaml
  4. +9 −0 cron.yaml
  5. +37 −0 emails.py
  6. +23 −0 index.html
  7. +11 −0 index.yaml
  8. +71 −0 main.py
  9. +4 −0 model.py
  10. +18 −0 receive_email.py
  11. 0 user.html
3 .gitignore
@@ -0,0 +1,3 @@
+.project
+.pydevproject
+*~
0 README
No changes.
15 app.yaml
@@ -0,0 +1,15 @@
+application: fssnippets
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: .*
+ script: main.py
+
+- url: /_ah/mail/snippet@.*app-id\.appspotmail\.com
+ script: receive_email.py
+ login: admin
+
+inbound_services:
+- mail
9 cron.yaml
@@ -0,0 +1,9 @@
+cron:
+- description: weekly reminder
+ url: /reminderemail
+ schedule: every friday 09:00
+ timezone: America/New_York
+- description: weekly digest
+ url: /digestemail
+ schedule: every monday 17:00
+ timezone: America/New_York
37 emails.py
@@ -0,0 +1,37 @@
+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})
+
+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:
+
+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.
+
+Please let us know if you have any questions.
+
+The example.com Team
+""")
+
+class OneDigest(webapp.RequestHandler):
+ def post(self):
+ key = self.request.get('user')
+
23 index.html
@@ -0,0 +1,23 @@
+<html>
+ <body>
+ Username (linked to snippets)
+
+ List of users (linked to user pages, link to follow/unfollow)
+ {% for greeting in greetings %}
+ {% if greeting.author %}
+ <b>{{ greeting.author.nickname }}</b> wrote:
+ {% else %}
+ An anonymous person wrote:
+ {% endif %}
+ <blockquote>{{ greeting.content|escape }}</blockquote>
+ {% endfor %}
+
+ <form action="/sign" method="post">
+ <div><textarea name="content" rows="3" cols="60"></textarea></div>
+ <div><input type="submit" value="Sign Guestbook"></div>
+ </form>
+
+ <a href="{{ url }}">{{ url_linktext }}</a>
+
+ </body>
+</html>
11 index.yaml
@@ -0,0 +1,11 @@
+indexes:
+
+# AUTOGENERATED
+
+# This index.yaml is automatically updated whenever the dev_appserver
+# detects that a new type of query is run. If you want to manage the
+# index.yaml file manually, remove the above marker line (the line
+# saying "# AUTOGENERATED"). If you want to manage some indexes
+# manually, move them above the marker line. The index.yaml file is
+# automatically uploaded to the admin console when you next deploy
+# your application using appcfg.py.
71 main.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+#
+# Copyright 2007 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import os
+
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import template
+from google.appengine.ext.webapp import util
+
+from emails import *
+from model import *
+
+class UserHandler(webapp.RequestHandler):
+ def get(self):
+ pass
+
+class FollowHandler(webapp.RequestHandler):
+ def post(self):
+ pass
+
+class ReceiveEmail(webapp.RequestHandler):
+ def post(self):
+ pass
+
+class MainHandler(webapp.RequestHandler):
+ def get(self):
+ user = users.get_current_user()
+
+ if user:
+ self.response.headers['Content-Type'] = 'text/plain'
+ self.response.out.write('Hello, ' + user.nickname())
+ template_values = {
+ 'greetings': greetings,
+ 'url': url,
+ 'url_linktext': url_linktext,
+ }
+
+ path = os.path.join(os.path.dirname(__file__), 'index.html')
+ self.response.out.write(template.render(path, template_values))
+ else:
+ self.redirect(users.create_login_url(self.request.uri))
+
+def main():
+ application = webapp.WSGIApplication(
+ [('/', MainHandler),
+ ('/user', UserHandler),
+ ('/follow', FollowHandler),
+ ('/reminderemail', ReminderEmail),
+ ('/digestemail', DigestEmail),
+ ('/onereminder', OneReminder),
+ ('/onedigest', OneDigest),
+ ('/_ah/mail/snippet@fssnippets.appspotmail.com', ReceiveEmail)],
+ debug=True)
+ util.run_wsgi_app(application)
+
+
+if __name__ == '__main__':
+ main()
4 model.py
@@ -0,0 +1,4 @@
+class User(db.Model):
+ user = db.UserProperty()
+ enabled = db.StringProperty(multiline=True)
+ date = db.DateTimeProperty(auto_now_add=True)
18 receive_email.py
@@ -0,0 +1,18 @@
+import logging, email
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
+from google.appengine.ext.webapp.util import run_wsgi_app
+
+class ReceiveEmail(InboundMailHandler):
+ def receive(self, message):
+ logging.info("Received a message from: " + message.sender)
+ plaintext_bodies = message.bodies('text/plain')
+
+def main():
+ application = webapp.WSGIApplication([ReceiveEmail.mapping()], debug=True)
+ util.run_wsgi_app(application)
+
+if __name__ == '__main__':
+ main()
+
+
0 user.html
No changes.

0 comments on commit f1f9d94

Please sign in to comment.