import sys import time import json import traceback from dock import AppEnv from dock.common import log app = AppEnv("") from dock_ebbinghauscalendar.model.scheduler import Scheduler from dock_ebbinghauscalendar.lib.notify import Notifier logger = log.get_logger('dock_ebbinghauscalendar.tasklet.notify') def main(): args = json.loads(sys.argv[1]) model = Scheduler() while True: tasks = model.get_due_tasks() for task in tasks: post = task.get_post() try: if Notifier(**args).notify(post): model.archive(task) except: logger.error(traceback.format_exc()) time.sleep(60) if __name__ == '__main__': main()
import time import redis from dock.common import log from .post import Post logger = log.get_logger('ebbinghaus_calendar.model.user') server = redis.Redis() ts_list = [ 1 * 60 * 60 * 1000, 6 * 60 * 60 * 1000, 24 * 60 * 60 * 1000, 3 * 24 * 60 * 60 * 1000, 7 * 24 * 60 * 60 * 1000, 14 * 24 * 60 * 60 * 1000, 30 * 24 * 60 * 60 * 1000, 60 * 24 * 60 * 60 * 1000, ] class Scheduler(object): def __init__(self): self.key = "ebbinghaus:schedule:zset" def schedule(self, post): ts = int(post.ts) for i, t in enumerate(ts_list): value = '{}::{}'.format(i, post.id) server.zadd(self.key, value, ts + t)
from flask import Blueprint from flask import g from flask import flash from flask import abort from flask import request from flask import session from flask import render_template from flask import url_for from flask import redirect from dock.common import log from ..model.user import User from ..model.post import Post from ..model.scheduler import Scheduler logger = log.get_logger('ebbinghaus_calendar.view') blueprint = Blueprint('ebbinghaus_calendar', __name__) @blueprint.before_request def before_request(): g.user = None if 'email' in session: g.user = User.from_email(session['email']) @blueprint.route('/register', methods=['GET', 'POST']) def register(): if request.method == 'GET': return render_template('register.html') else: