From 158d83341bcd9b4d4838532e6e01ea38f99a0691 Mon Sep 17 00:00:00 2001 From: Kian <105409698+knejadshamsi@users.noreply.github.com> Date: Thu, 8 Aug 2024 10:53:32 -0400 Subject: [PATCH] Initial setup --- .gitignore | 4 ++++ .idea/.gitignore | 3 +++ .../inspectionProfiles/profiles_settings.xml | 6 +++++ .idea/misc.xml | 10 ++++++++ .idea/modules.xml | 8 +++++++ .idea/vcs.xml | 6 +++++ .idea/zl-back.iml | 8 +++++++ main.py | 17 ++++++++++++++ models.py | 0 routes.py | 23 +++++++++++++++++++ 10 files changed, 85 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/zl-back.iml create mode 100644 main.py create mode 100644 models.py create mode 100644 routes.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a248d74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Default ignored files +/shelf/ +/workspace.xml +.env diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..802d6ba --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..897361e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/zl-back.iml b/.idea/zl-back.iml new file mode 100644 index 0000000..cae4758 --- /dev/null +++ b/.idea/zl-back.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..a0713f9 --- /dev/null +++ b/main.py @@ -0,0 +1,17 @@ +import os +from dotenv import load_dotenv +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from routes import register_route + +load_dotenv() + +db = SQLAlchemy() +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("SQLALCHEMY_DATABASE_URI") +db.init_app(app) + +register_route(app, db) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/models.py b/models.py new file mode 100644 index 0000000..e69de29 diff --git a/routes.py b/routes.py new file mode 100644 index 0000000..bad5347 --- /dev/null +++ b/routes.py @@ -0,0 +1,23 @@ +import os +from flask import jsonify +from sqlalchemy import inspect + + +def register_route(app,db): + @app.route("/") + def hello_world(): + return "

Hello, World!

" + + @app.route('/user/') + @app.route('/user/') + def show_user_profile(username=None): + test = os.getenv("MY_KEY") + if username: + return f"

Hello, Mr {username}! You are the man.

{test}" + return "

Hello, user!

" + + @app.route('/table') + def list_table(): + inspector = inspect(db.engine) + tables = inspector.get_table_names() + return jsonify(tables)