diff --git a/app.py b/app.py index 7e97fd30d6ee191c0df87c1a9975de495b4094b8..10c2c358610bf099d046bded417c0e783f173a57 100644 --- a/app.py +++ b/app.py @@ -3,23 +3,32 @@ # File : app.py # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------ # Date : 2022/8/25 -import os +from flask_sqlalchemy import SQLAlchemy +import config + +import os from flask import Flask, jsonify, abort,request,redirect,make_response,render_template,send_from_directory from js.rules import getRules from utils import error,parser +from utils.web import * import sys import codecs -from models.cms import CMS +from classes.cms import CMS import json sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) app = Flask(__name__,static_folder='static',static_url_path='/static') -app.config["JSON_AS_ASCII"] = False # jsonify返回的中文正常显示 -from utils.web import * +# app.config["JSON_AS_ASCII"] = False # jsonify返回的中文正常显示 +app.config.from_object(config) # 单独的配置文件里写了,这里就不用弄json中文显示了 +db = SQLAlchemy(app) rule_list = getRules() print(rule_list) +from models import * + +RuleClass = rule_classes.init(db) + def getParmas(key=None,value=''): """ 获取链接参数 @@ -179,6 +188,34 @@ def plugin(name): except Exception as e: return jsonify(error.failed(f'非法猥亵\n{e}')) +def db_test(): + name = '555影视' + class_name = '电影&连续剧&福利&动漫&综艺' + class_url = '1&2&124&4&3' + # data = RuleClass.query.filter(RuleClass.name == '555影视').all() + res = db.session.query(RuleClass).filter(RuleClass.name == name).first() + print(res) + if res: + res.class_name = class_name + res.class_url = class_url + db.session.add(res) + msg = f'修改成功:{res.id}' + else: + res = RuleClass(name=name, class_name=class_name, class_url=class_url) + db.session.add(res) + res = db.session.query(RuleClass).filter(RuleClass.name == name).first() + msg = f'新增成功:{res.id}' + + try: + db.session.commit() + return jsonify(error.success(msg)) + except Exception as e: + return jsonify(error.failed(f'{e}')) + +@app.route('/db') +def database(): + return db_test() + if __name__ == '__main__': app.run(host="0.0.0.0", port=5705) diff --git a/classes/___init__.py b/classes/___init__.py new file mode 100644 index 0000000000000000000000000000000000000000..b34a12d86d872cd7892cad51b55634121890d2d8 --- /dev/null +++ b/classes/___init__.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# File : ___init__.py +# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------ +# Date : 2022/8/27 + +from .cms import * \ No newline at end of file diff --git a/models/cms.py b/classes/cms.py similarity index 100% rename from models/cms.py rename to classes/cms.py diff --git a/config.py b/config.py new file mode 100644 index 0000000000000000000000000000000000000000..dd6595dff2130815d3e999e0f6e9bee6676d6c87 --- /dev/null +++ b/config.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# File : config.py +# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------ +# Date : 2022/8/27 + +DIALECT = 'mysql' +DRIVER = 'pymysql' +USERNAME = 'gp' +PASSWORD = '123456' +HOST = '127.0.0.1' +PORT = '3306' +DATABASE = 'pira' +# DB_URI = '{}+{}://{}:{}@{}:{}/{}?charset=utf8'.format(DIALECT, DRIVER, USERNAME, PASSWORD, HOST, PORT, DATABASE) +DB_URI = 'sqlite:///models/rules.db?charset=utf8&check_same_thread=False' +SQLALCHEMY_DATABASE_URI = DB_URI +SQLALCHEMY_TRACK_MODIFICATIONS = False +SQLALCHEMY_ECHO = False # 打印sql语句 +JSON_AS_ASCII = False # jsonify返回的中文正常显示 \ No newline at end of file diff --git a/models/__init__.py b/models/__init__.py index 2daf85f0e06b8e2da02a85d084f537fd938bf26b..147bef4f25539d3c5b8a209cfb2dee710d20bbea 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -4,4 +4,4 @@ # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------ # Date : 2022/8/25 -from . import cms \ No newline at end of file +from . import rule_classes \ No newline at end of file diff --git a/models/no_use.py b/models/no_use.py new file mode 100644 index 0000000000000000000000000000000000000000..c14b457dd775b75ad4088dca2ce25f6ab7bd436e --- /dev/null +++ b/models/no_use.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# File : models.py +# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------ +# Date : 2022/8/27 + +from db_operation.db_init import * + +def get_dynamic_table_name_class(table_name): + # 定义一个内部类 + class myTable(Base): + # 给表名赋值 + __tablename__ = table_name + __table_args__ = {'extend_existing': True} + id = Column(Integer, primary_key=True, autoincrement=True) + name = Column(String(20)) + class_name = Column(String(32)) + class_url = Column(String(32)) + + def __repr__(self): + return "