From ad0f2e7dda742c266364619a2bb972aa99e06c89 Mon Sep 17 00:00:00 2001 From: luff Date: Mon, 24 Feb 2025 21:25:58 +0800 Subject: [PATCH] clear --- README.md | 7 ++ inventory_check/1.py | 170 -------------------------------------- inventory_check/app.py | 92 --------------------- inventory_check/forms.py | 33 -------- inventory_check/test.html | 143 -------------------------------- inventory_check/test.py | 60 -------------- 6 files changed, 7 insertions(+), 498 deletions(-) delete mode 100644 inventory_check/1.py delete mode 100644 inventory_check/app.py delete mode 100644 inventory_check/forms.py delete mode 100644 inventory_check/test.html delete mode 100644 inventory_check/test.py diff --git a/README.md b/README.md index b779b27..538d9db 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # inventory_check + +click 8.1.8 +Flask 3.1.0 +Flask-Moment 1.0.6 +Flask-SQLAlchemy 3.1.1 +gunicorn 23.0.0 +openpyxl 3.1.5 diff --git a/inventory_check/1.py b/inventory_check/1.py deleted file mode 100644 index 69e4934..0000000 --- a/inventory_check/1.py +++ /dev/null @@ -1,170 +0,0 @@ - - -from flask import * -#from client import Client -import time -import json -import os -import csv -import sqlite3 -import hashlib - -app = Flask(__name__) - -DB = 'inventory.db' - -def getmd5(data): - s = '' - for i in data: - s += str(i).strip() - r = hashlib.md5(s.encode(encoding='UTF-8')).hexdigest() - return r - -def formatted_time(): - return time.strftime("%Y/%m/%d", time.localtime()) - -def dbsetup(data): - """ - '{ - "25":{"location": 28, "tag": "7.61/8.10", "amount": 3 }, - "26":{"location": 29, "tag": "7.59/8.10", "amount": 3 } - }' - """ - conn = sqlite3.connect(DB) - c = conn.cursor() - c.execute("DROP TABLE IF EXISTS inventory") - conn.commit() - c.execute('''CREATE TABLE IF NOT EXISTS inventory - (ID INTEGER PRIMARY KEY AUTOINCREMENT, - SORT INT, - LOCATION INT, - TAG TEXT, - AMOUNT INT, - NAME TEXT, - DATE TEXT);''') - conn.commit() - for e in data.keys(): - v = (int(e), data[e]["location"], data[e]["tag"], data[e]["amount"]) - c.execute('''INSERT INTO inventory - (SORT,LOCATION,TAG,AMOUNT) \ - VALUES {v}'''.format(v=v)) - - conn.commit() - conn.close() - -def dbinsert(tb='inventory', v=()): - conn = sqlite3.connect(DB) - c = conn.cursor() - #c.execute('''INSERT INTO {tb} - # (ID,NU,MOULD,SPEC,AMOUNT,OUTDATE,RECEIVRE,MANAGER,\ - # FAC,SERIAL,STATE,INDATE,COLLECTOR,COMMET,MD5) \ - # VALUES {v}'''.format(tb=tb, v=v)) - c.execute("INSERT INTO {tb} VALUES {v};".format(tb=tb, v=v)) - #(2, 'Allen', 25, 'Texas', 15000.00 ) - conn.commit() - conn.close() - -def dbselect(tb='inventory'): - conn = sqlite3.connect(DB) - c = conn.cursor() - # c.execute("SELECT ID,NU,MOULD,SPEC,AMOUNT,OUTDATE,RECEIVRE,\ - # MANAGER,FAC,SERIAL,STATE,INDATE,COLLECTOR,COMMET,MD5 from {tb};".format(tb=tb)) - c.execute("SELECT * FROM {tb};".format(tb=tb)) - return c.fetchall() - -def dbupdate(tb='inventory', d={'ID':123123,'MD5':'asdasdasdasd'}): - conn = sqlite3.connect(DB) - c = conn.cursor() - for e in d: - if isinstance(d[e], str): - c.execute("UPDATE {tb} SET {h} = '{r}' WHERE ID={id};".format(tb=tb, h=e, r=d[e], id=d['ID'])) - else: - c.execute("UPDATE {tb} SET {h} = {r} WHERE ID={id};".format(tb=tb, h=e, r=d[e], id=d['ID'])) - conn.commit() - conn.close() - -def dbdelete(tb='inventory', i=123123): - conn = sqlite3.connect(DB) - c = conn.cursor() - try: - c.execute("DELETE FROM {tb} WHERE ID={i};".format(tb=tb, i=i)) - LOG('已删除该条目……') - except: - LOG('没有该条目……') - conn.commit() - conn.close() - LOG('已删除……') - -def dbsearchhead(tb='inventory', h='NU', s='3'): - conn = sqlite3.connect(DB) - c = conn.cursor() - #c.execute("SELECT ID,NU,MOULD,SPEC,AMOUNT,OUTDATE,RECEIVRE,MANAGER,\ - #FAC,SERIAL,STATE,INDATE,COLLECTOR,COMMET,MD5 from {tb};".format(tb=tb)) - c.execute("SELECT * FROM {tb} WHERE {h} GLOB '*{s}*';".format(tb=tb, h=h, s=s)) - return c.fetchall() - -def dbsearchtime(tb='inventory', t=(111111,222222)): - conn = sqlite3.connect(DB) - c = conn.cursor() - c.execute("SELECT * FROM {tb} WHERE ID >= {a} AND ID >= {b} ;".format(tb=tb, a=t[0], b=t[1])) - return c.fetchall() - -def dbadd(tb='inventory', d={'ID':123123,'MD5':'asdasdasdasd'}): - conn = sqlite3.connect(DB) - c = conn.cursor() - v = (d['ID'],' ',' ',' ',1,'','','','','','','','','','',0,'') - try: - c.execute("INSERT INTO {tb} VALUES {v};".format(tb=tb, v=v)) - except: - pass - conn.commit() - conn.close() - #(2, 'Allen', 25, 'Texas', 15000.00 ) - dbupdate(tb=tb, d=d) - -def dbnothave(tb='inventory', md5='md5'): - conn = sqlite3.connect(DB) - c = conn.cursor() - c.execute("SELECT * FROM {tb} WHERE MD5 = '{md5}';".format(tb=tb, md5=md5)) - if c.fetchall() == []: - return True - else: - return False - -@app.route('/inventory', methods=['POST','GET']) - -# from flask import Flask, request, jsonify -def inventory(): - if request.method == 'POST': - # 接收JSON数据 - data = request.get_json() # '{"sort": 25, "location": 28, "tag": "7.61/8.10", "name": "Bob"}' - print("Received data:", data) - # 处理数据(示例:简单地返回接收到的数据) - return jsonify({"message": "JSON data received", "yourData": data}) - else: - # 发送JSON数据 - response_data = { - "name": "Alice", - "age": 25, - "city": "Los Angeles" - } - return jsonify(response_data) - -@app.route('/inventory/init', methods=['POST','GET']) -def inventory_init(): - if request.method == 'POST': - # 接收JSON数据 - data = request.get_json() # '{25:{"location": 28, "tag": "7.61/8.10", "amount": 3 }, 26:{"location": 29, "tag": "7.59/8.10", "amount": 3 }}' - try: - dbsetup(data) - return "请求成功", 200 - except: - return "无法理解", 400 - else: - # 发送JSON数据 - response_data = { - "name": "Alice", - "age": 25, - "city": "Los Angeles" - } - return jsonify(response_data) \ No newline at end of file diff --git a/inventory_check/app.py b/inventory_check/app.py deleted file mode 100644 index 37815ef..0000000 --- a/inventory_check/app.py +++ /dev/null @@ -1,92 +0,0 @@ - - -from flask import Flask, redirect, render_template, request, url_for -from flask_sqlalchemy import SQLAlchemy -from openpyxl import load_workbook -from wtforms import Form, IntegerField, StringField, SubmitField -from wtforms.validators import NumberRange - -app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///foo.db' -app.secret_key = 'qweqweqwe' - -db = SQLAlchemy(app) - -class Inventory(db.Model): - id = db.Column(db.Integer, primary_key=True) - sort = db.Column(db.Integer) - location = db.Column(db.Integer) - tag = db.Column(db.Text) - amount = db.Column(db.Integer) - name = db.Column(db.Text) - mtime = db.Column(db.Date) - -with app.app_context(): - db.create_all() - -class CheckForm(Form): - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.sort = IntegerField('sort') - self.location = IntegerField('location') - self.tag = StringField('tag') - self.amount = IntegerField('amount', validators=[NumberRange(min=0)]) - self.name = StringField('name') - self.mtime = StringField('mtime') - tag = StringField('tag') - minusbuton = SubmitField('minus') - amount = IntegerField('amount', validators=[NumberRange(min=0)]) - plusbuton = SubmitField('plus') - goback = SubmitField('back') - confim = SubmitField('right') - goahead = SubmitField('ahead') -def import_from_xlsx(file_path): - with app.app_context(): - db.drop_all() - db.create_all() - # 加载Excel工作簿 - wb = load_workbook(filename=file_path, data_only=True) - # 加载工作簿,设置 data_only=True - ws = wb.active - - # 遍历工作表中的每一行 - for row in ws.iter_rows(min_row=3, values_only=True): # 假设第一行是标题行 - new_inventory = Inventory( - sort=row[0], - location=row[1], - tag=row[2], - amount=row[3], - - ) - db.session.add(new_inventory) - - # 提交事务 - db.session.commit() - -def db_to_turple(): - with app.app_context(): - inventory = Inventory.query.all() - for e in inventory: - print(e.sort, e.location, e.tag, e.amount, e.name, e.mtime) - -@app.route('/upload', methods=['GET', 'POST']) -def upload_form(): - if request.method == 'POST': - # 文件上传逻辑 - pass - return render_template('upload.html') - -@app.route('/import', methods=['POST']) -def import_file(): - if request.method == 'POST': - file = request.files['file'] - if file: - file_path = 'data.xlsx' - file.save(file_path) - import_from_xlsx(file_path) - db_to_turple() - return '文件导入成功!' - - return redirect(url_for('upload_form')) - diff --git a/inventory_check/forms.py b/inventory_check/forms.py deleted file mode 100644 index 6dfa846..0000000 --- a/inventory_check/forms.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -""" - :author: luffmims - :url: http://yum2.cc - :copyright: © 2025 luffmims - :license: MIT, see LICENSE for more details. -""" -from flask_wtf import FlaskForm -from wtforms import IntegerField, StringField, SubmitField -from wtforms.validators import NumberRange - -# class HelloForm(FlaskForm): -# name = StringField('Name', validators=[DataRequired(), Length(1, 20)]) -# body = TextAreaField('Message', validators=[DataRequired(), Length(1, 200)]) -# submit = SubmitField() - -class CheckForm(FlaskForm): - tag = '' - amount = 0 - id = 0 - def __init__(self, Inventory): - super().__init__(Inventory) - self.id = Inventory.id - self.tag = Inventory.tag - self.amount = Inventory.amount - - showtag = StringField(tag) - minusbuton = SubmitField('-') - amount = IntegerField('amount', validators=[NumberRange(min=0)]) - plusbuton = SubmitField('+') - goback = SubmitField('back') - confim = SubmitField('right') - goahead = SubmitField('ahead') \ No newline at end of file diff --git a/inventory_check/test.html b/inventory_check/test.html deleted file mode 100644 index 17268e5..0000000 --- a/inventory_check/test.html +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - Check! - - - - -
-
-

- CHECK - it -

- -
- -
-
- inventory.tag -
- -
- - - -
- -
- - -
- - - - \ No newline at end of file diff --git a/inventory_check/test.py b/inventory_check/test.py deleted file mode 100644 index fa573b2..0000000 --- a/inventory_check/test.py +++ /dev/null @@ -1,60 +0,0 @@ -from flask import Flask, redirect, render_template, request, url_for -from flask_sqlalchemy import SQLAlchemy -from sqlalchemy.orm import DeclarativeBase - -class Base(DeclarativeBase): - pass - -db = SQLAlchemy(model_class=Base) - -# create the app -app = Flask(__name__) -# configure the SQLite database, relative to the app instance folder -app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db" -# initialize the app with the extension -db.init_app(app) - -from sqlalchemy import Integer, String -from sqlalchemy.orm import Mapped, mapped_column - -class User(db.Model): - id: Mapped[int] = mapped_column(primary_key=True) - username: Mapped[str] = mapped_column(unique=True) - email: Mapped[str] - -with app.app_context(): - db.create_all() - -@app.route("/users") -def user_list(): - users = db.session.execute(db.select(User).order_by(User.username)).scalars() - return render_template("user/list.html", users=users) - -@app.route("/users/create", methods=["GET", "POST"]) -def user_create(): - if request.method == "POST": - user = User( - username=request.form["username"], - email=request.form["email"], - ) - db.session.add(user) - db.session.commit() - return redirect(url_for("user_detail", id=user.id)) - - return render_template("user/create.html") - -@app.route("/user/") -def user_detail(id): - user = db.get_or_404(User, id) - return render_template("user/detail.html", user=user) - -@app.route("/user//delete", methods=["GET", "POST"]) -def user_delete(id): - user = db.get_or_404(User, id) - - if request.method == "POST": - db.session.delete(user) - db.session.commit() - return redirect(url_for("user_list")) - - return render_template("user/delete.html", user=user) \ No newline at end of file