basic setting file
This commit is contained in:
parent
a03711a43c
commit
161b7c582b
7 changed files with 73 additions and 45 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
conf/*.json
|
||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules/
|
node_modules/
|
||||||
storage/
|
storage/
|
||||||
|
|
0
conf/.gitkeep
Normal file
0
conf/.gitkeep
Normal file
55
diffido.py
55
diffido.py
|
@ -2,6 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
|
@ -19,6 +20,7 @@ from tornado import gen, escape
|
||||||
CONF_DIR = ''
|
CONF_DIR = ''
|
||||||
JOBS_STORE = 'sqlite:///storage/jobs.db'
|
JOBS_STORE = 'sqlite:///storage/jobs.db'
|
||||||
API_VERSION = '1.0'
|
API_VERSION = '1.0'
|
||||||
|
SCHEDULES_FILE = 'conf/schedules.json'
|
||||||
|
|
||||||
|
|
||||||
class DiffidoBaseException(Exception):
|
class DiffidoBaseException(Exception):
|
||||||
|
@ -86,6 +88,23 @@ class BaseHandler(tornado.web.RequestHandler):
|
||||||
self.write({'error': True, 'message': message})
|
self.write({'error': True, 'message': message})
|
||||||
|
|
||||||
|
|
||||||
|
class SchedulesHandler(BaseHandler):
|
||||||
|
def read_schedules(self):
|
||||||
|
if not os.path.isfile(SCHEDULES_FILE):
|
||||||
|
return {}
|
||||||
|
with open(SCHEDULES_FILE, 'r') as fd:
|
||||||
|
return json.loads(fd.read())
|
||||||
|
|
||||||
|
def write_schedules(self, schedules):
|
||||||
|
with open(SCHEDULES_FILE, 'w') as fd:
|
||||||
|
fd.write(json.dumps(schedules, indent=2))
|
||||||
|
|
||||||
|
@gen.coroutine
|
||||||
|
def get(self, id_=None, *args, **kwargs):
|
||||||
|
schedules = self.read_schedules()
|
||||||
|
self.write(schedules)
|
||||||
|
|
||||||
|
|
||||||
class TemplateHandler(BaseHandler):
|
class TemplateHandler(BaseHandler):
|
||||||
"""Handler for the / path."""
|
"""Handler for the / path."""
|
||||||
app_path = os.path.join(os.path.dirname(__file__), "dist")
|
app_path = os.path.join(os.path.dirname(__file__), "dist")
|
||||||
|
@ -96,13 +115,6 @@ class TemplateHandler(BaseHandler):
|
||||||
if args and args[0]:
|
if args and args[0]:
|
||||||
page = args[0].strip('/')
|
page = args[0].strip('/')
|
||||||
arguments = self.arguments
|
arguments = self.arguments
|
||||||
arguments['schedules'] = [{
|
|
||||||
'id': 1,
|
|
||||||
'title': 'wikipedia',
|
|
||||||
'url': 'https://it.wikipedia.org/wiki/Pagina_principale',
|
|
||||||
'scheduling': {'interval': 5, 'unit': 'minutes'},
|
|
||||||
'enabled': True
|
|
||||||
}]
|
|
||||||
self.render(page, **arguments)
|
self.render(page, **arguments)
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,14 +131,14 @@ def serve():
|
||||||
#scheduler.remove_job('run')
|
#scheduler.remove_job('run')
|
||||||
#scheduler.add_job(run, 'interval', minutes=1)
|
#scheduler.add_job(run, 'interval', minutes=1)
|
||||||
|
|
||||||
define("port", default=3210, help="run on the given port", type=int)
|
define('port', default=3210, help='run on the given port', type=int)
|
||||||
define("address", default='', help="bind the server at the given address", type=str)
|
define('address', default='', help='bind the server at the given address', type=str)
|
||||||
define("ssl_cert", default=os.path.join(os.path.dirname(__file__), 'ssl', 'diffido_cert.pem'),
|
define('ssl_cert', default=os.path.join(os.path.dirname(__file__), 'ssl', 'diffido_cert.pem'),
|
||||||
help="specify the SSL certificate to use for secure connections")
|
help='specify the SSL certificate to use for secure connections')
|
||||||
define("ssl_key", default=os.path.join(os.path.dirname(__file__), 'ssl', 'diffido_key.pem'),
|
define('ssl_key', default=os.path.join(os.path.dirname(__file__), 'ssl', 'diffido_key.pem'),
|
||||||
help="specify the SSL private key to use for secure connections")
|
help='specify the SSL private key to use for secure connections')
|
||||||
define("debug", default=False, help="run in debug mode")
|
define('debug', default=False, help='run in debug mode')
|
||||||
define("config", help="read configuration file",
|
define('config', help='read configuration file',
|
||||||
callback=lambda path: tornado.options.parse_config_file(path, final=False))
|
callback=lambda path: tornado.options.parse_config_file(path, final=False))
|
||||||
tornado.options.parse_command_line()
|
tornado.options.parse_command_line()
|
||||||
|
|
||||||
|
@ -139,15 +151,16 @@ def serve():
|
||||||
if os.path.isfile(options.ssl_key) and os.path.isfile(options.ssl_cert):
|
if os.path.isfile(options.ssl_key) and os.path.isfile(options.ssl_cert):
|
||||||
ssl_options = dict(certfile=options.ssl_cert, keyfile=options.ssl_key)
|
ssl_options = dict(certfile=options.ssl_cert, keyfile=options.ssl_key)
|
||||||
|
|
||||||
init_params = dict(listen_port=options.port, logger=logger, ssl_options=ssl_options)
|
init_params = dict(listen_port=options.port, logger=logger, ssl_options=ssl_options,
|
||||||
|
scheduler=scheduler)
|
||||||
|
|
||||||
# _days_path = r"/days/?(?P<day>[\d_-]+)?"
|
_schedules_path = r'schedules/?(?P<id_>\d+)?'
|
||||||
application = tornado.web.Application([
|
application = tornado.web.Application([
|
||||||
# (_days_path, DaysHandler, init_params),
|
('/api/%s' % _schedules_path, SchedulesHandler, init_params),
|
||||||
# (r'/v%s%s' % (API_VERSION, _days_path), DaysHandler, init_params),
|
(r'/api/v%s/%s' % (API_VERSION, _schedules_path), SchedulesHandler, init_params),
|
||||||
(r"/?(.*)", TemplateHandler, init_params),
|
(r'/?(.*)', TemplateHandler, init_params),
|
||||||
],
|
],
|
||||||
static_path=os.path.join(os.path.dirname(__file__), "dist/static"),
|
static_path=os.path.join(os.path.dirname(__file__), 'dist/static'),
|
||||||
template_path=os.path.join(os.path.dirname(__file__), 'dist/'),
|
template_path=os.path.join(os.path.dirname(__file__), 'dist/'),
|
||||||
debug=options.debug)
|
debug=options.debug)
|
||||||
http_server = tornado.httpserver.HTTPServer(application, ssl_options=ssl_options or None)
|
http_server = tornado.httpserver.HTTPServer(application, ssl_options=ssl_options or None)
|
||||||
|
|
1
dist/base.html
vendored
1
dist/base.html
vendored
|
@ -8,6 +8,7 @@
|
||||||
<link rel="stylesheet" href="/static/css/themes/default.css">
|
<link rel="stylesheet" href="/static/css/themes/default.css">
|
||||||
<script src="/static/js/vue.js"></script>
|
<script src="/static/js/vue.js"></script>
|
||||||
<script src="/static/js/vue-material.min.js"></script>
|
<script src="/static/js/vue-material.min.js"></script>
|
||||||
|
<script src="/static/js/axios.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% block body %}{% end %}
|
{% block body %}{% end %}
|
||||||
|
|
51
dist/index.html
vendored
51
dist/index.html
vendored
|
@ -1,29 +1,18 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
Index
|
|
||||||
<a href="/page.html/?id=3">setting 3</a>; <a href="/diff.html?id=3">diff 3</a>
|
|
||||||
|
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="md-layout">
|
<div class="md-layout">
|
||||||
<div class="md-layout-item">
|
<div class="md-layout-item" md-card>
|
||||||
<md-table>
|
<md-table id="schedules-table" v-model="schedules">
|
||||||
<md-table-row>
|
<md-table-toolbar>
|
||||||
<md-table-head md-numeric>#</md-table-head>
|
<h1 class="md-title">Schedules <a href="schedule.html">add new</a></h1>
|
||||||
<md-table-head>title</md-table-head>
|
</md-table-toolbar>
|
||||||
<md-table-head>url</md-table-head>
|
<md-table-row slot="md-table-row" slot-scope="{item}">
|
||||||
<md-table-head>schedule</md-table-head>
|
<md-table-cell md-label="#" md-sort-by="id" md-numeric>${ item.id }</md-table-cell>
|
||||||
</md-table-row>
|
<md-table-cell md-label="title" md-sort-by="title">${ item.title }</md-table-cell>
|
||||||
|
<md-table-cell md-label="url" md-sort-by="email">${ item.url }</md-table-cell>
|
||||||
{% for schedule in schedules %}
|
</md-table-row>
|
||||||
<md-table-row>
|
|
||||||
<md-table-cell md-numeric>{{ schedule['id'] }}</md-table-cell>
|
|
||||||
<md-table-cell>{{ schedule['title'] }}</md-table-cell>
|
|
||||||
<md-table-cell>{{ schedule['url'] }}</md-table-cell>
|
|
||||||
<md-table-cell>meh</md-table-cell>
|
|
||||||
</md-table-row>
|
|
||||||
{% end %}
|
|
||||||
|
|
||||||
</md-table>
|
</md-table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,7 +23,23 @@ Index
|
||||||
Vue.use(VueMaterial.default);
|
Vue.use(VueMaterial.default);
|
||||||
|
|
||||||
var app = new Vue({
|
var app = new Vue({
|
||||||
el: '#app'
|
el: '#app',
|
||||||
|
delimiters: ['${', '}'],
|
||||||
|
data: {
|
||||||
|
schedules: []
|
||||||
|
},
|
||||||
|
mounted: function() {
|
||||||
|
this.getSchedules();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getSchedules: function() {
|
||||||
|
self = this;
|
||||||
|
var data = axios.get('/api/schedules').then(function(response) {
|
||||||
|
console.log(response);
|
||||||
|
self.schedules = response.data.schedules || [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -47,7 +52,7 @@ body {
|
||||||
.md-table {
|
.md-table {
|
||||||
width: 60%;
|
width: 60%;
|
||||||
min-height: 200px;
|
min-height: 200px;
|
||||||
max-height: 600px;
|
max-height: 600px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
0
dist/page.html → dist/schedule.html
vendored
0
dist/page.html → dist/schedule.html
vendored
10
dist/static/js/axios.min.js
vendored
10
dist/static/js/axios.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue