Added auto refresh
This commit is contained in:
+26
-8
@@ -2,9 +2,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Simple REST Server
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import datetime
|
||||
import werkzeug
|
||||
import tornado.httpserver
|
||||
import tornado.ioloop
|
||||
import tornado.options
|
||||
@@ -12,18 +14,28 @@ import tornado.web
|
||||
|
||||
from tornado.options import define, options
|
||||
define("port", default=8000, help="run on the given port", type=int)
|
||||
define("lines", default=20, help="number of lines displayed", type=int)
|
||||
|
||||
database = []
|
||||
|
||||
class IndexHandler(tornado.web.RequestHandler):
|
||||
def get(self):
|
||||
global database
|
||||
res = ""
|
||||
items = []
|
||||
for data in database:
|
||||
print("{}".format(data))
|
||||
#print("{}".format(len(data[2])))
|
||||
res = res + "{} {:x} {} {}".format(data[0],data[1],data[2],data[3]) + "<br>"
|
||||
self.write(res)
|
||||
#print("{}".format(data))
|
||||
datetime = data[0].split()
|
||||
#print("data={} datetime={}".format(data[0], datetime))
|
||||
|
||||
items.append({
|
||||
"date": datetime[0],
|
||||
"time": datetime[1],
|
||||
"id": data[1],
|
||||
"frame": data[2],
|
||||
"value": data[3]
|
||||
})
|
||||
#print("items={}".format(items))
|
||||
self.render("index.html", lines=options.lines, items=items)
|
||||
|
||||
#curl -X POST -H "Content-Type: application/json" -d '{"canid":101, "frame":"standard" , "data": [1,2,3,4,5,6,7,8]}' http://192.168.10.43:8000/post
|
||||
class PostHandler(tornado.web.RequestHandler):
|
||||
@@ -51,7 +63,9 @@ class PostHandler(tornado.web.RequestHandler):
|
||||
|
||||
global database
|
||||
#print("{} {} {}".format(type(database), len(database), database))
|
||||
if(len(database) >= 20):
|
||||
print("lines={}".format(options.lines))
|
||||
#if(len(database) >= 20):
|
||||
if(len(database) >= options.lines):
|
||||
database.pop(0)
|
||||
database.append(items)
|
||||
|
||||
@@ -59,11 +73,15 @@ class PostHandler(tornado.web.RequestHandler):
|
||||
|
||||
if __name__ == "__main__":
|
||||
tornado.options.parse_command_line()
|
||||
print("port={}".format(options.port))
|
||||
print("lines={}".format(options.lines))
|
||||
app = tornado.web.Application(
|
||||
handlers=[
|
||||
(r"/", IndexHandler),
|
||||
(r"/post", PostHandler),
|
||||
],debug=True
|
||||
],
|
||||
template_path=os.path.join(os.getcwd(), "templates"),
|
||||
debug=True
|
||||
)
|
||||
http_server = tornado.httpserver.HTTPServer(app)
|
||||
http_server.listen(options.port)
|
||||
|
||||
Reference in New Issue
Block a user