first commit
This commit is contained in:
commit
2e4edfeb42
4 files changed
+232
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user