I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!
\
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
import datetime | |
from google.appengine.ext import ndb | |
# eventually import custom User class here and adjust paths below | |
# parameter in timedelta() assumes that tokens expire ~3 months after creation: | |
expiredTokens = User.token_model.query(User.token_model.created <= (datetime.datetime.utcnow() - datetime.timedelta(3*365/12))) | |
# delete the tokens in bulks of 100: | |
while expiredTokens.count() > 0: | |
keys = expiredTokens.fetch(100, keys_only=True) |