diff --git a/mflix/custom_json.py b/mflix/custom_json.py new file mode 100644 index 0000000..b0da0d6 --- /dev/null +++ b/mflix/custom_json.py @@ -0,0 +1,11 @@ +from flask.json.provider import DefaultJSONProvider +from bson import ObjectId +from datetime import datetime + +class MongoJsonProvider(DefaultJSONProvider): + def default(self, obj): + if isinstance(obj, datetime): + return obj.strftime("%Y-%m-%d %H:%M:%S") + if isinstance(obj, ObjectId): + return str(obj) + return super().default(obj) \ No newline at end of file diff --git a/run.py b/run.py index ef21639..2a1e8ef 100644 --- a/run.py +++ b/run.py @@ -1,16 +1,22 @@ - from mflix.factory import create_app +from configparser import ConfigParser +from mflix.db import init_app as init_db -import os -import configparser - +# Load MongoDB URI from sample.ini +config = ConfigParser() +config.read("sample.ini") -config = configparser.ConfigParser() -config.read(os.path.abspath(os.path.join(".ini"))) +mongo_uri = config["APP"]["DB_URI"] # Make sure your [APP] section exists if __name__ == "__main__": - app = create_app() - app.config['DEBUG'] = True - app.config['MONGO_URI'] = config['PROD']['DB_URI'] + # Create the app with injected config + app = create_app({ + "DEBUG": True, + "MONGO_URI": mongo_uri + }) + + # Initialize DB connection + init_db(app) - app.run() + # Run the app + app.run() \ No newline at end of file