-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.py
executable file
·75 lines (63 loc) · 1.75 KB
/
cron.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python2.4
#
# Copyright 2010 Steve Carlson
#
import os
import cgi
import operator
import sys
import re
import datetime, time
import wsgiref.handlers
from models.Message import Message
from google.appengine.ext import webapp, db
from google.appengine.ext.webapp.util import run_wsgi_app
def addDict(basedict, sourcedict):
for k, v in sourcedict.iteritems():
basedict[k]=v
return basedict
def HalfHourAgo():
now = datetime.datetime.now()
if now.minute > 30:
return now.replace(minute=now.minute-30)
else:
return now.replace(hour=now.hour-1,minute=now.minute+30)
def GCMessages():
STORED = db.GqlQuery("SELECT * FROM Message WHERE date <= :1", HalfHourAgo())
#STORED = db.GqlQuery("SELECT * FROM Message")
for M in STORED:
M.delete()
class BaseHandler(webapp.RequestHandler):
'''
Render: BUILD AND DISPLAY PAGE, ACCEPTS TEMPLATE AND ARGUMENTS
'''
def Render(self, templ=None, dict=None):
path = os.path.join(os.path.dirname(__file__), 'templates', templ)
self.response.out.write(template.render(path, dict))
class GarbageCollector(BaseHandler):
'''
GET: CLEARS TWITTER AND BLOG DATA FROM DB,
'''
def get(self):
try:
GCMessages()
except:
pass
'''
application = DEFINE WSGI HANDLERS
'''
application = webapp.WSGIApplication(
[
('/crongc', GarbageCollector)
],
debug=True)
def main():
'''
RUN SOME WSGI APPS
'''
run_wsgi_app(application)
if __name__ == "__main__":
'''
SOME SILLY BOILERPLATE, I BLAME GUIDO
'''
main()