From c5d0f1b9b4d08138b707fc51ac72c0c7fb2997af Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Sun, 28 Apr 2024 14:26:38 +1000 Subject: [PATCH] initial --- .gitignore | 2 ++ README.md | 0 requirements.txt | 1 + src/config.py | 8 ++++++++ src/db.py | 13 +++++++++++++ src/flask_app.py | 17 +++++++++++++++++ src/mangalpy.py | 13 +++++++++++++ src/routes/__init__.py | 1 + src/routes/root.py | 23 +++++++++++++++++++++++ 9 files changed, 78 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 requirements.txt create mode 100644 src/config.py create mode 100644 src/db.py create mode 100644 src/flask_app.py create mode 100644 src/mangalpy.py create mode 100644 src/routes/__init__.py create mode 100644 src/routes/root.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01d7f95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +venv \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8ab6294 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask \ No newline at end of file diff --git a/src/config.py b/src/config.py new file mode 100644 index 0000000..d2848a7 --- /dev/null +++ b/src/config.py @@ -0,0 +1,8 @@ +import configparser +from os.path import expanduser + + +def load(): + config = configparser.ConfigParser() + config.read(expanduser("~/.config/mangalpy/config.ini")) + return config diff --git a/src/db.py b/src/db.py new file mode 100644 index 0000000..352df20 --- /dev/null +++ b/src/db.py @@ -0,0 +1,13 @@ +import sqlite3 + + +class DB: + def __init__(self, path): + self.path = path + + def _connect(self): + return sqlite3.connect(self.path) + + +def connect(path): + return sqlite3.connect(path) diff --git a/src/flask_app.py b/src/flask_app.py new file mode 100644 index 0000000..31cf991 --- /dev/null +++ b/src/flask_app.py @@ -0,0 +1,17 @@ +from routes import root +from flask import Flask +from os.path import expanduser + +from db import DB +import config + + +class App(Flask): + def __init__(self): + self.app_config = config.load() + db_location = expanduser(self.app_config.get("General", "db_location")) + self.db = DB(db_location) + super().__init__(__name__) + + def register_blueprints(self): + self.register_blueprint(root.bp) diff --git a/src/mangalpy.py b/src/mangalpy.py new file mode 100644 index 0000000..60ff119 --- /dev/null +++ b/src/mangalpy.py @@ -0,0 +1,13 @@ +import flask_app +from os.path import realpath, dirname +import sys + +import_dir = dirname(f"{realpath(__file__)}") +sys.path.append(import_dir) + +app = flask_app.App() +app.register_blueprints() + +# Entry point bby +if __name__ == "__main__": + app.run(debug=True) diff --git a/src/routes/__init__.py b/src/routes/__init__.py new file mode 100644 index 0000000..6ae7c3c --- /dev/null +++ b/src/routes/__init__.py @@ -0,0 +1 @@ +from . import root diff --git a/src/routes/root.py b/src/routes/root.py new file mode 100644 index 0000000..27585b1 --- /dev/null +++ b/src/routes/root.py @@ -0,0 +1,23 @@ +from flask import Blueprint +from flask import current_app + +bp = Blueprint("root", __name__, url_prefix="/") + + +@bp.route("/") +def root(): + current_app.db._connect() + return { + "manga": { + "somehashofsomething": { + "title": "Some lewd shit", + "author": "Some weeb", + "chapters_downloaded": [0, 1, 2, 3, 4, 5, 6, 7], + }, + "someotherthing": { + "title": "Other lewd shit", + "author": "Other weeb", + "chapters_downloaded": [x for x in range(15)], + }, + } + }