multithreading and parsing1

This commit is contained in:
2023-09-27 13:02:30 +02:00
parent 00d7456f89
commit e453cc2c6c
7 changed files with 127 additions and 14 deletions

View File

@@ -11,5 +11,9 @@ if path.exists((cfg_pth := path.join(config_path, "../config.cfg"))):
config.read(cfg_pth)
settings = {
"mongodb_uri": config.get("DB","MONGODB_URI")
}
"mongodb_uri": config.get("DB","MONGODB_URI"),
"mongodb_db": config.get("DB","MONGODB_DB"),
"mongodb_collection": config.get("DB","MONGODB_COLLECTION"),
"orsr_url": config.get("WEB", "ORSR_URL"),
"threads": int(config.get("APP", "THREADS"))
}

View File

@@ -1,18 +1,30 @@
from flask import current_app, g
from flask import g
from werkzeug.local import LocalProxy
from flask_pymongo import PyMongo
from pymongo import MongoClient
from .config import settings
def connect_db():
client = MongoClient(settings["mongodb_uri"])
db = client[settings["mongodb_db"]]
collection = db[settings["mongodb_collection"]]
return collection
def disconnect_db(conn):
conn.database.client.close()
def get_db():
"""
Configuration method to return db instance
"""
db = getattr(g, "_database", None)
collection = getattr(g, "_database", None)
if db is None:
db = g._database = PyMongo(current_app).db
if collection is None:
collection = g._database = connect_db()
return db
return collection
# Use LocalProxy to read the global db instance with just `db`

View File

@@ -5,10 +5,10 @@ from .db import db
@app.route("/detail", methods=["GET"])
def detail():
if "ico" not in request.args:
ico = request.args.get("ico")
if "ico" is None:
return "missing ico"
else:
ico = request.args["ico"]
return f"ICO je {ico}"