|
|
|
@ -4,10 +4,12 @@ import urllib.parse
|
|
|
|
from pathlib import Path
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Dict
|
|
|
|
from typing import Dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import pymongo
|
|
|
|
|
|
|
|
|
|
|
|
from kedro.framework.session import KedroSession
|
|
|
|
from kedro.framework.session import KedroSession
|
|
|
|
from actesdataset import JSONDataSetCollection
|
|
|
|
from kedro.extras.datasets.yaml import YAMLDataSet
|
|
|
|
|
|
|
|
|
|
|
|
import pymongo
|
|
|
|
from actesdataset import JSONDataSetCollection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
@ -21,7 +23,6 @@ def populate_mongo(jsondoc: JSONDataSetCollection, storage_ip: str, db_name: str
|
|
|
|
jsondatasets = jsondoc.datasets
|
|
|
|
jsondatasets = jsondoc.datasets
|
|
|
|
housename = jsondoc._housename
|
|
|
|
housename = jsondoc._housename
|
|
|
|
#mongodb://%s:%s@149.202.41.75:27017' % (username, password)
|
|
|
|
#mongodb://%s:%s@149.202.41.75:27017' % (username, password)
|
|
|
|
# FIXME passer en parametres
|
|
|
|
|
|
|
|
username = urllib.parse.quote_plus(mongodb_admin)
|
|
|
|
username = urllib.parse.quote_plus(mongodb_admin)
|
|
|
|
password = urllib.parse.quote_plus(mongodb_password)
|
|
|
|
password = urllib.parse.quote_plus(mongodb_password)
|
|
|
|
mongodb_url = f"mongodb://{username}:{password}@{storage_ip}:27017/"
|
|
|
|
mongodb_url = f"mongodb://{username}:{password}@{storage_ip}:27017/"
|
|
|
|
@ -44,4 +45,31 @@ def populate_mongo(jsondoc: JSONDataSetCollection, storage_ip: str, db_name: str
|
|
|
|
#logger.info(str(document))
|
|
|
|
#logger.info(str(document))
|
|
|
|
res = actes_collection.insert_one(document)
|
|
|
|
res = actes_collection.insert_one(document)
|
|
|
|
logger.info(res.inserted_id)
|
|
|
|
logger.info(res.inserted_id)
|
|
|
|
|
|
|
|
# properly closes the db connection
|
|
|
|
|
|
|
|
# FIXME with MongoClient() as client
|
|
|
|
|
|
|
|
myclient.close()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_houses(yamldoc: YAMLDataSet, storage_ip: str, db_name: str, mongodb_admin: str, mongodb_password: str) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
username = urllib.parse.quote_plus(mongodb_admin)
|
|
|
|
|
|
|
|
password = urllib.parse.quote_plus(mongodb_password)
|
|
|
|
|
|
|
|
mongodb_url = f"mongodb://{username}:{password}@{storage_ip}:27017/"
|
|
|
|
|
|
|
|
logger.info("connection to the mongodb server: " + mongodb_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pymongo settings
|
|
|
|
|
|
|
|
myclient = pymongo.MongoClient(mongodb_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
actesdb = myclient[db_name]
|
|
|
|
|
|
|
|
houses_col = actesdb['houses']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for house in yamldoc['houses'].values():
|
|
|
|
|
|
|
|
logger.info(str(house))
|
|
|
|
|
|
|
|
houses_col.insert_one(house)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# properly closes the db connection
|
|
|
|
|
|
|
|
# FIXME with MongoClient() as client
|
|
|
|
|
|
|
|
myclient.close()
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|