migration

This commit is contained in:
2026-05-26 21:39:05 -06:00
parent 30691e90ce
commit d45a05dce3
25 changed files with 2115 additions and 2115 deletions
+80 -80
View File
@@ -1,80 +1,80 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Simple REST Server
import os
import sys
import json
import datetime
import argparse
from flask import Flask, request, render_template
app = Flask(__name__)
database = []
@app.route("/")
def root():
global database
items = []
for data in database:
#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))
return render_template("index.html", lines=app.config['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
@app.route("/post", methods=["POST"])
def post():
function = sys._getframe().f_code.co_name
#print("{}: request={}".format(function, request))
#print("{}: request.data={}".format(function, request.data))
dict = json.loads(request.data)
print("{} dict={}".format(function, dict))
items = []
now = datetime.datetime.now()
items.append(now.strftime("%Y/%m/%d %H:%M:%S"))
if ("canid" in dict):
print("{} canid=0x{:x}".format(function, dict['canid']))
items.append(dict['canid'])
if ("frame" in dict):
print("{} frame={}".format(function, dict['frame']))
items.append(dict['frame'])
if ("data" in dict):
print("{} data length={}".format(function, len(dict['data'])))
print("{} data={}".format(function, dict['data']))
items.append(dict['data'])
global database
#print("{} {} {}".format(type(database), len(database), database))
print("lines={}".format(app.config['lines']))
#if(len(database) >= 20):
if(len(database) >= app.config['lines']):
database.pop(0)
database.append(items)
data = json.dumps(['result', 'ok'])
return data
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-port', type=int, default=8000)
parser.add_argument('-lines', type=int, default=20)
args = parser.parse_args()
print("port={}".format(args.port))
print("lines={}".format(args.lines))
app.config['lines'] = args.lines
#app.run()
app.run(host='127.0.0.1', port=args.port, debug=True)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Simple REST Server
import os
import sys
import json
import datetime
import argparse
from flask import Flask, request, render_template
app = Flask(__name__)
database = []
@app.route("/")
def root():
global database
items = []
for data in database:
#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))
return render_template("index.html", lines=app.config['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
@app.route("/post", methods=["POST"])
def post():
function = sys._getframe().f_code.co_name
#print("{}: request={}".format(function, request))
#print("{}: request.data={}".format(function, request.data))
dict = json.loads(request.data)
print("{} dict={}".format(function, dict))
items = []
now = datetime.datetime.now()
items.append(now.strftime("%Y/%m/%d %H:%M:%S"))
if ("canid" in dict):
print("{} canid=0x{:x}".format(function, dict['canid']))
items.append(dict['canid'])
if ("frame" in dict):
print("{} frame={}".format(function, dict['frame']))
items.append(dict['frame'])
if ("data" in dict):
print("{} data length={}".format(function, len(dict['data'])))
print("{} data={}".format(function, dict['data']))
items.append(dict['data'])
global database
#print("{} {} {}".format(type(database), len(database), database))
print("lines={}".format(app.config['lines']))
#if(len(database) >= 20):
if(len(database) >= app.config['lines']):
database.pop(0)
database.append(items)
data = json.dumps(['result', 'ok'])
return data
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-port', type=int, default=8000)
parser.add_argument('-lines', type=int, default=20)
args = parser.parse_args()
print("port={}".format(args.port))
print("lines={}".format(args.lines))
app.config['lines'] = args.lines
#app.run()
app.run(host='127.0.0.1', port=args.port, debug=True)
+35 -35
View File
@@ -1,35 +1,35 @@
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="5;url="/">
<title>CAN DATA</title>
</head>
<body>
Display the latest {{ lines }} records.<br>
If you want to see more, specify the number of lines at startup.<br>
<table border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr style="color:#ffffff;" bgcolor="#800000">
<th valign="top">Date</th>
<th valign="top">Time</th>
<th valign="top">ID</th>
<th valign="top">Frame</th>
<th valign="top">Value</th>
</tr>
{% for i in items %}
<tr>
<td>{{ i.date }}</td>
<td>{{ i.time }}</td>
<td>{{ i.id }}</td>
<td>{{ i.frame }}</td>
<td>{{ i.value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="5;url="/">
<title>CAN DATA</title>
</head>
<body>
Display the latest {{ lines }} records.<br>
If you want to see more, specify the number of lines at startup.<br>
<table border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr style="color:#ffffff;" bgcolor="#800000">
<th valign="top">Date</th>
<th valign="top">Time</th>
<th valign="top">ID</th>
<th valign="top">Frame</th>
<th valign="top">Value</th>
</tr>
{% for i in items %}
<tr>
<td>{{ i.date }}</td>
<td>{{ i.time }}</td>
<td>{{ i.id }}</td>
<td>{{ i.frame }}</td>
<td>{{ i.value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>