commit 2e4edfeb42f7d5eb239f2485417dc4263ab8d8e3 Author: woni <320753691@qq.com> Date: Thu Mar 28 09:04:24 2024 +0800 first commit diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc new file mode 100644 index 0000000..b9ac065 Binary files /dev/null and b/__pycache__/app.cpython-310.pyc differ diff --git a/app.py b/app.py new file mode 100644 index 0000000..abd00e4 --- /dev/null +++ b/app.py @@ -0,0 +1,36 @@ +import os +import sqlite3 + +from flask import Flask, request, jsonify, render_template +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy import PickleType + + +basedir = os.path.abspath(os.path.dirname(__file__)) +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'database.db') # 使用 SQLite 数据库 +db = SQLAlchemy(app) + + +class Tracker(db.Model): + id = db.Column(db.Integer, primary_key=True) + distance = db.Column(db.Integer, nullable=False) + data = db.Column(PickleType(), nullable=False) + + +@app.route('/', methods=['GET']) +def index(): + db.create_all() + return render_template('index.html') + + +@app.route("/", methods=["POST"]) +def upload_data(): + data = request.json + print(data) + record = Tracker(distance=data["distance"], data=data["data"]) + + print(sum(item[0] for item in data["data"])) + db.session.add(record) + db.session.commit() + return jsonify({"message": "Data recorded"}), 200 diff --git a/database.db b/database.db new file mode 100644 index 0000000..5c1bcec Binary files /dev/null and b/database.db differ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..7d39303 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,196 @@ + + + +
+ +