-
Notifications
You must be signed in to change notification settings - Fork 78
/
cron.py
42 lines (36 loc) · 1.36 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
import webapp2, jinja2, os, hashlib, logging, urllib
import json
import datetime
from model import Document
from google.appengine.api import mail
from secrets import ADMIN_EMAIL
from blockchain import auto_consolidate
class ConsolidationCron(webapp2.RequestHandler):
def get(self):
archiveable = Document.get_archiveable()
processed = False
for d in archiveable:
res = d.archive()
self.response.write("%s %s<br />" % (d.digest, res))
processed = True
if processed:
self.response.write("Running autoconsolidate<br />")
auto_consolidate()
else:
self.response.write("Finished without operation<br />")
class ConfirmationCron(webapp2.RequestHandler):
def get(self):
actionable = Document.get_actionable()
for d in actionable:
ret = d.blockchain_certify()
sender_address = "manuelaraoz@gmail.com"
subject = "Document certified: %s %s" % (ret['success'], d.digest)
body = subject + "\n\nmesage: %s" % (ret['message'])
mail.send_mail(sender_address, ADMIN_EMAIL, subject, body)
class PaymentCheckerCron(webapp2.RequestHandler):
def get(self):
digest = self.request.get('d')
d = Document.get_doc(digest)
if d and d.pending and d.has_balance():
d.received_payment()
self.response.write("%s %s<br />" % (d.digest, d.payment_address))