-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·41 lines (30 loc) · 1.28 KB
/
main.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
#!/usr/bin/env python
"""main.py - This file contains handlers that are called by taskqueue and/or
cronjobs."""
import logging
import webapp2
from google.appengine.api import mail, app_identity
from api import TicTacToeApi
from models import User, Game
class SendReminderEmail(webapp2.RequestHandler):
def get(self):
"""Send a reminder email to each User with an email about games.
Called every hour using a cron job"""
app_id = app_identity.get_application_id()
users = User.query(User.email != None)
for user in users:
games = Game.query(Game.user == user.key).filter(Game.game_over != True).fetch()
print(games)
if len(games) > 0:
print('remind me')
subject = 'This is a reminder!'
body = 'Hello {}, {} games of tictactoe are still active!'.format(user.name, len(games))
# This will send test emails, the arguments to send_mail are:
# from, to, subject, body
mail.send_mail('noreply@{}.appspotmail.com'.format(app_id),
user.email,
subject,
body)
app = webapp2.WSGIApplication([
('/crons/send_reminder', SendReminderEmail)
], debug=True)