mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-22 04:43:54 +02:00
style: Refactoring imports, adapting MongoConnector to different connection_strings
This commit is contained in:
@ -4199,6 +4199,102 @@
|
||||
" ) as export_file:\n",
|
||||
" json.dump(dataclasses.asdict(company), export_file, ensure_ascii=False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"module_path = os.path.abspath(os.path.join(\"..\"))\n",
|
||||
"if module_path not in sys.path:\n",
|
||||
" sys.path.append(module_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"mongodb://root:pR0R0v2e2@trisnol.tech:27017\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from News.utils.mongodb.mongo import MongoConnector\n",
|
||||
"from Unternehmensregister.utils.CompanyMongoService import CompanyMongoService\n",
|
||||
"\n",
|
||||
"connector = MongoConnector(\n",
|
||||
" hostname=\"trisnol.tech\",\n",
|
||||
" database=\"transparenzregister\",\n",
|
||||
" username=\"root\",\n",
|
||||
" password=\"pR0R0v2e2\",\n",
|
||||
" port=27017,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"service = CompanyMongoService(connector)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 0%| | 0/3147 [00:00<?, ?it/s]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"100%|██████████| 3147/3147 [00:30<00:00, 102.30it/s]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Inserted documents: 0\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from tqdm import tqdm\n",
|
||||
"import glob\n",
|
||||
"import json\n",
|
||||
"from Unternehmensregister.models.Company import Company\n",
|
||||
"\n",
|
||||
"num_inserted = 0\n",
|
||||
"for file in tqdm(glob.glob1(\"./data/Unternehmensregister/transformed\", \"*.json\")):\n",
|
||||
" path = os.path.join(\"./data/Unternehmensregister/transformed\", file)\n",
|
||||
" with open(path, \"r\", encoding=\"utf-8\") as file_object:\n",
|
||||
" data = json.loads(file_object.read())\n",
|
||||
" company: Company = Company(**data)\n",
|
||||
"\n",
|
||||
" company_db = service.get_by_id(company.id)\n",
|
||||
" if company_db is None:\n",
|
||||
" service.insert(company)\n",
|
||||
" num_inserted += 1\n",
|
||||
"print(f\"Inserted documents: {num_inserted}\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
Reference in New Issue
Block a user