From 98f18fc66651b224a6b9c39869da0ccb075fd414 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 12 Sep 2019 15:21:06 +0800 Subject: [PATCH] add app.py timer.py --- f7/__init__.py | 10 ++++++++++ f7/app.py | 41 +++++++++++++++++++++++++++++++++++++++++ f7/timer.py | 22 ++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 f7/app.py create mode 100644 f7/timer.py diff --git a/f7/__init__.py b/f7/__init__.py index e69de29..04574a7 100644 --- a/f7/__init__.py +++ b/f7/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/python + +from .app import instance as i_app +from .timer import instance as i_timer +from .udplog import instance as i_udplog + +app = i_app() +udplog = i_udplog() +timer = i_timer() diff --git a/f7/app.py b/f7/app.py new file mode 100644 index 0000000..4941bd8 --- /dev/null +++ b/f7/app.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/python + +import tornado.web +import tornado.ioloop + +class _mainHandler(tornado.web.RequestHandler): + + def get(self): + self.write(json.dumps({ + 'errcode': 0, + 'errmsg': '', + 'healthy': 1, + 'max_rundelay': 10 + })) + +class _App: + _instance = None + + @classmethod + def instance(cls): + if not cls._instance: + cls._instance = _App() + return cls._instance + + def __init__(self): + self._app = tornado.web.Application([ + (r"/webapp/index[\.]php", _mainHandler), + ]) + + def start(self): + tornado.ioloop.IOLoop.current().start() + + def listen(self, port): + self._app.listen(port) + + def callAt(self, when, callback): + tornado.ioloop.IOLoop.current().call_at(when, callback) + +def instance(): + return _App.instance() diff --git a/f7/timer.py b/f7/timer.py new file mode 100644 index 0000000..01f4646 --- /dev/null +++ b/f7/timer.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/python + +import f7 + +class _Timer: + _instance = None + + @classmethod + def instance(cls): + if not cls._instance: + cls._instance = _Timer() + return cls._instance + + def __init__(self): + pass + + def callAt(self, when, callback): + f7.app.callAt(when, callback) + +def instance(): + return _Timer.instance()