浏览代码

feat: 基本程序架构

SongZihuan 3 年之前
父节点
当前提交
1c69115323
共有 11 个文件被更改,包括 64 次插入1 次删除
  1. 1 0
      app/__init__.py
  2. 10 0
      app/home.py
  3. 20 0
      app/view.py
  4. 14 0
      configure/__init__.py
  5. 0 0
      core/__init__.py
  6. 0 1
      core/db.py
  7. 1 0
      core/user.py
  8. 0 0
      core/word.py
  9. 二进制
      global-dict.db
  10. 5 0
      main.py
  11. 13 0
      templates/index.html

+ 1 - 0
app/__init__.py

@@ -0,0 +1 @@
+from . import view

+ 10 - 0
app/home.py

@@ -0,0 +1,10 @@
+import flask.blueprints
+import flask
+
+
+home = flask.blueprints.Blueprint("home", __name__)
+
+
+@home.route("/")
+def index():
+    return flask.render_template("index.html")

+ 20 - 0
app/view.py

@@ -0,0 +1,20 @@
+from flask import Flask
+import configure
+from . import home
+
+
+class HEnglishFlask(Flask):
+    def __init__(self, import_name, **kwargs):
+        super().__init__(import_name, **kwargs)
+        self.update_config()
+
+        @self.context_processor
+        def inject_base():
+            return {"title": self.config["TITLE"],
+                    "about": self.config["ABOUT"]}
+
+        self.register_blueprint(home.home, url_prefix="/")
+
+    def update_config(self):
+        self.config.update(configure.conf)
+        self.logger.info("Update config")

+ 14 - 0
configure/__init__.py

@@ -0,0 +1,14 @@
+import json
+
+conf = {
+    "SECRET_KET": "HEnglish",
+    "TITLE": "HEnglish :D",
+    "ABOUT": "An useful English learning website for personal."
+}
+
+
+def configure(file_path: str, encoding: str = "utf-8"):
+    with open(file_path, mode="r", encoding=encoding) as f:
+        json_str = f.read()
+        _conf: dict = json.loads(json_str)
+        conf.update(_conf)

+ 0 - 0
core/__init__.py


+ 0 - 1
db.py → core/db.py

@@ -1,6 +1,5 @@
 import sqlite3
 from typing import Optional, Union, List, Tuple, Dict
-import traceback
 import logging
 import pandas
 import word

+ 1 - 0
core/user.py

@@ -0,0 +1 @@
+from . import db

+ 0 - 0
word.py → core/word.py


二进制
global-dict.db


+ 5 - 0
main.py

@@ -0,0 +1,5 @@
+import configure
+import app as App
+
+app = App.view.HEnglishFlask(__name__)
+

+ 13 - 0
templates/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title> {{ title }} </title>
+</head>
+<body>
+
+<h1> Welcome to {{ title }} ! </h1>
+<p> {{ about }} </p>
+
+</body>
+</html>