diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..23d4fbc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,31 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "structables" +version = "0.2.0" +authors = [ + { name="Private.coffee Team", email="support@private.coffee" }, +] +description = "A simple frontend for Instructables" +readme = "README.md" +license = { file="LICENSE" } +requires-python = ">=3.10" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", +] +dependencies = [ + "flask", + "bs4", +] + +[project.scripts] +structables = "structables.main:main" + +[project.urls] +"Homepage" = "https://git.private.coffee/privatecoffee/structables" +"Bug Tracker" = "https://git.private.coffee/privatecoffee/structables/issues" +"Source Code" = "https://git.private.coffee/privatecoffee/structables" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 29a1f88..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -bs4 -flask diff --git a/src/structables/__init__.py b/src/structables/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/src/structables/main.py similarity index 98% rename from main.py rename to src/structables/main.py index 7068fb5..53537c9 100644 --- a/main.py +++ b/src/structables/main.py @@ -54,6 +54,10 @@ def get_typesense_api_key(): TYPESENSE_API_KEY = get_typesense_api_key() +debugmode = False +invidious = None +unsafe = False + def projects_search( query="*", @@ -156,64 +160,8 @@ def update_data(): ) -debugmode = os.environ.get("FLASK_DEBUG", os.environ.get("STRUCTABLES_DEBUG", False)) -invidious = os.environ.get("STRUCTABLES_INVIDIOUS") -unsafe = os.environ.get("STRUCTABLES_UNSAFE", False) - -if __name__ == "__main__": - parser = ArgumentParser() - parser.add_argument( - "-p", - "--port", - default=8002, - type=int, - help="Port to listen on", - ) - parser.add_argument( - "-d", - "--debug", - action="store_true", - help="Enable debug mode", - ) - parser.add_argument( - "-l", - "--listen-host", - default="127.0.0.1", - help="Host to listen on", - ) - parser.add_argument( - "-I", - "--invidious", - help="URL to Invidious instance, e.g. https://invidious.private.coffee/", - ) - parser.add_argument( - "-u", - "--unsafe", - action="store_true", - help="Display iframes regardless of origin", - ) - args = parser.parse_args() - - if args.debug: - debugmode = True - - if args.invidious: - invidious = args.invidious - - if args.unsafe: - unsafe = True - -print("Loading initial data...") - -update_data() - -print("Started!") - app = Flask(__name__, template_folder="templates", static_folder="static") -if debugmode: - app.logger.setLevel(logging.DEBUG) - @app.route("/cron/") def cron(): @@ -1187,8 +1135,9 @@ def route_proxy(): if url.startswith("https://cdn.instructables.com/") or url.startswith( "https://content.instructables.com/" ): + def generate(): - # Subfunction to allow streaming the data instead of + # Subfunction to allow streaming the data instead of # downloading all of it at once try: with urlopen(unquote(url)) as data: @@ -1199,6 +1148,7 @@ def route_proxy(): yield chunk except HTTPError as e: abort(e.code) + try: with urlopen(unquote(url)) as data: content_type = data.headers["content-type"] @@ -1259,5 +1209,74 @@ def internal_server_error(e): return render_template("500.html") -if __name__ == "__main__": +def main(): + global debugmode, invidious, unsafe + + parser = ArgumentParser() + parser.add_argument( + "-p", + "--port", + default=8002, + type=int, + help="Port to listen on", + ) + parser.add_argument( + "-d", + "--debug", + action="store_true", + help="Enable debug mode", + ) + parser.add_argument( + "-l", + "--listen-host", + default="127.0.0.1", + help="Host to listen on", + ) + parser.add_argument( + "-I", + "--invidious", + help="URL to Invidious instance, e.g. https://invidious.private.coffee/", + ) + parser.add_argument( + "-u", + "--unsafe", + action="store_true", + help="Display iframes regardless of origin", + ) + parser.add_argument( + "-P", + "--privacy-file", + default="privacy.txt", + help="File to read privacy policy from", + ) + args = parser.parse_args() + + debugmode = os.environ.get( + "FLASK_DEBUG", os.environ.get("STRUCTABLES_DEBUG", False) + ) + invidious = os.environ.get("STRUCTABLES_INVIDIOUS") + unsafe = os.environ.get("STRUCTABLES_UNSAFE", False) + + if args.debug: + debugmode = True + + if args.invidious: + invidious = args.invidious + + if args.unsafe: + unsafe = True + + print("Loading initial data...") + + update_data() + + print("Started!") + + if debugmode: + app.logger.setLevel(logging.DEBUG) + app.run(port=args.port, host=args.listen_host, debug=debugmode) + + +if __name__ == "__main__": + main() diff --git a/static/css/style.css b/src/structables/static/css/style.css similarity index 100% rename from static/css/style.css rename to src/structables/static/css/style.css diff --git a/static/dist/css/bootstrap.min.css b/src/structables/static/dist/css/bootstrap.min.css similarity index 100% rename from static/dist/css/bootstrap.min.css rename to src/structables/static/dist/css/bootstrap.min.css diff --git a/static/dist/css/bootstrap.min.css.map b/src/structables/static/dist/css/bootstrap.min.css.map similarity index 100% rename from static/dist/css/bootstrap.min.css.map rename to src/structables/static/dist/css/bootstrap.min.css.map diff --git a/static/dist/js/bootstrap.bundle.min.js b/src/structables/static/dist/js/bootstrap.bundle.min.js similarity index 100% rename from static/dist/js/bootstrap.bundle.min.js rename to src/structables/static/dist/js/bootstrap.bundle.min.js diff --git a/static/dist/js/bootstrap.bundle.min.js.map b/src/structables/static/dist/js/bootstrap.bundle.min.js.map similarity index 100% rename from static/dist/js/bootstrap.bundle.min.js.map rename to src/structables/static/dist/js/bootstrap.bundle.min.js.map diff --git a/static/img/logo.png b/src/structables/static/img/logo.png similarity index 100% rename from static/img/logo.png rename to src/structables/static/img/logo.png diff --git a/static/img/logo_lg.png b/src/structables/static/img/logo_lg.png similarity index 100% rename from static/img/logo_lg.png rename to src/structables/static/img/logo_lg.png diff --git a/static/img/magnifying-glass-solid.svg b/src/structables/static/img/magnifying-glass-solid.svg similarity index 100% rename from static/img/magnifying-glass-solid.svg rename to src/structables/static/img/magnifying-glass-solid.svg diff --git a/templates/400.html b/src/structables/templates/400.html similarity index 100% rename from templates/400.html rename to src/structables/templates/400.html diff --git a/templates/404.html b/src/structables/templates/404.html similarity index 100% rename from templates/404.html rename to src/structables/templates/404.html diff --git a/templates/429.html b/src/structables/templates/429.html similarity index 100% rename from templates/429.html rename to src/structables/templates/429.html diff --git a/templates/500.html b/src/structables/templates/500.html similarity index 100% rename from templates/500.html rename to src/structables/templates/500.html diff --git a/templates/archives.html b/src/structables/templates/archives.html similarity index 100% rename from templates/archives.html rename to src/structables/templates/archives.html diff --git a/templates/article-review.html b/src/structables/templates/article-review.html similarity index 100% rename from templates/article-review.html rename to src/structables/templates/article-review.html diff --git a/templates/article.html b/src/structables/templates/article.html similarity index 100% rename from templates/article.html rename to src/structables/templates/article.html diff --git a/templates/base.html b/src/structables/templates/base.html similarity index 100% rename from templates/base.html rename to src/structables/templates/base.html diff --git a/templates/category.html b/src/structables/templates/category.html similarity index 100% rename from templates/category.html rename to src/structables/templates/category.html diff --git a/templates/collection.html b/src/structables/templates/collection.html similarity index 100% rename from templates/collection.html rename to src/structables/templates/collection.html diff --git a/templates/contest.html b/src/structables/templates/contest.html similarity index 100% rename from templates/contest.html rename to src/structables/templates/contest.html diff --git a/templates/contests.html b/src/structables/templates/contests.html similarity index 100% rename from templates/contests.html rename to src/structables/templates/contests.html diff --git a/templates/footer.html b/src/structables/templates/footer.html similarity index 100% rename from templates/footer.html rename to src/structables/templates/footer.html diff --git a/templates/header.html b/src/structables/templates/header.html similarity index 100% rename from templates/header.html rename to src/structables/templates/header.html diff --git a/templates/iframe.html b/src/structables/templates/iframe.html similarity index 100% rename from templates/iframe.html rename to src/structables/templates/iframe.html diff --git a/templates/index.html b/src/structables/templates/index.html similarity index 100% rename from templates/index.html rename to src/structables/templates/index.html diff --git a/templates/member-instructables.html b/src/structables/templates/member-instructables.html similarity index 100% rename from templates/member-instructables.html rename to src/structables/templates/member-instructables.html diff --git a/templates/member.html b/src/structables/templates/member.html similarity index 100% rename from templates/member.html rename to src/structables/templates/member.html diff --git a/templates/privacypolicy.html b/src/structables/templates/privacypolicy.html similarity index 100% rename from templates/privacypolicy.html rename to src/structables/templates/privacypolicy.html diff --git a/templates/projects.html b/src/structables/templates/projects.html similarity index 100% rename from templates/projects.html rename to src/structables/templates/projects.html diff --git a/templates/sitemap.html b/src/structables/templates/sitemap.html similarity index 100% rename from templates/sitemap.html rename to src/structables/templates/sitemap.html diff --git a/templates/style.html b/src/structables/templates/style.html similarity index 100% rename from templates/style.html rename to src/structables/templates/style.html