-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·47 lines (36 loc) · 1.56 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
42
43
44
45
46
47
#!/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 HangmanGameApi
from models import User
from models import Game
class SendReminderEmail(webapp2.RequestHandler):
def get(self):
"""Send a reminder email to each User with an email about games.
Called every thursday at 17:00 using a cron job"""
app_id = app_identity.get_application_id()
users = User.query(User.email != None)
for user in users:
active_games = Game.query(Game.user == user.key).filter(
Game.game_over == False)
if active_games: # send them an email.
subject = 'This is a reminder!'
body = 'Hello {}, try out Hangman again!'.format(user.name)
# 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)
class UpdateAverageMovesRemaining(webapp2.RequestHandler):
def post(self):
"""Update game listing announcement in memcache."""
HangmanGameApi._cache_average_attempts()
self.response.set_status(204)
app = webapp2.WSGIApplication([
('/crons/send_reminder', SendReminderEmail),
('/tasks/cache_average_attempts', UpdateAverageMovesRemaining),
], debug=True)