refactor: Implement PR feedback

This commit is contained in:
TrisNol 2023-09-24 13:46:19 +02:00
parent 5a7472cd3c
commit 282d638c11
7 changed files with 20 additions and 32 deletions

View File

@ -10,7 +10,7 @@ class Auditor:
company: str | None
def to_dict(self) -> dict:
"""_summary_.
"""Transform to dict.
Returns:
dict: _description_

View File

@ -206,8 +206,6 @@ class Capital:
@dataclass
class Company:
"""_summary_."""
"""Company dataclass."""
id: CompanyID
@ -215,12 +213,12 @@ class Company:
name: str
last_update: str
relationships: list[CompanyRelationship]
# yearly_results: Optional[list[FinancialResults]]
# yearly_results: list[FinancialResults]] | None
company_type: CompanyTypeEnum | None = None
capital: Capital | None | None = None
capital: Capital | None = None
business_purpose: str | None = None
founding_date: str | None = None
def to_dict(self) -> dict:
"""_summary_."""
"""Transform class to dict."""
return asdict(self)

View File

@ -1,18 +1,16 @@
"""Unternehmensregister Scraping."""
import glob
import logging
import multiprocessing
import os
from pathlib import Path
from loguru import logger
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from tqdm import tqdm
logger = logging.getLogger()
def scrape(query: str, download_dir: list[str]) -> None:
"""Fetch results from Unternehmensregister for given query.

View File

@ -9,10 +9,10 @@ from aki_prj23_transparenzregister.utils.mongo.connector import MongoConnector
class CompanyMongoService:
"""_summary_."""
"""Wrapper for MongoDB regarding management of Company documents."""
def __init__(self, connector: MongoConnector):
"""_summary_.
"""Constructor.
Args:
connector (MongoConnector): _description_
@ -21,7 +21,7 @@ class CompanyMongoService:
self.lock = Lock() # Create a lock for synchronization
def get_all(self) -> list[Company]:
"""_summary_.
"""Get all Company documents.
Returns:
list[Company]: List of retrieved companies
@ -31,7 +31,7 @@ class CompanyMongoService:
return list(result)
def get_by_id(self, id: dict) -> dict | None:
"""_summary_.
"""Get a Company document by the given id.
Args:
id (CompanyID): CompanyID
@ -95,7 +95,7 @@ class CompanyMongoService:
return list(self.collection.find({"yearly_results": {"$gt": {}}}))
def insert(self, company: Company) -> InsertOneResult:
"""_summary_.
"""Insert a new Company document.
Args:
company (Company): _description_

View File

@ -6,7 +6,7 @@ import pymongo
@dataclass
class MongoConnection:
"""_summary_."""
"""Wrapper for MongoDB connection string."""
hostname: str
database: str
@ -36,7 +36,7 @@ class MongoConnector:
"""Wrapper for establishing a connection to a MongoDB instance."""
def __init__(self, connection: MongoConnection):
"""_summary_.
"""Wrapper for MongoDB collection.
Args:
connection (MongoConnection): Wrapper for connection string

View File

@ -6,14 +6,10 @@ from aki_prj23_transparenzregister.utils.mongo.connector import MongoConnector
class MongoNewsService:
"""_summary_.
Args:
NewsServiceInterface (_type_): _description_
"""
"""Wrapper for MongoDB regarding News documents."""
def __init__(self, connector: MongoConnector):
"""_summary_.
"""Constructor.
Args:
connector (MongoConnector): _description_
@ -21,7 +17,7 @@ class MongoNewsService:
self.collection = connector.database["news"]
def get_all(self) -> list[News]:
"""_summary_.
"""Get all News documents.
Returns:
list[News]: _description_
@ -30,7 +26,7 @@ class MongoNewsService:
return [MongoEntryTransformer.transform_outgoing(elem) for elem in result]
def get_by_id(self, id: str) -> News | None:
"""_summary_.
"""Get a News document by the given id.
Args:
id (str): _description_
@ -44,7 +40,7 @@ class MongoNewsService:
return None
def insert(self, news: News) -> InsertOneResult:
"""_summary_.
"""Insert a new News document.
Args:
news (News): _description_
@ -56,11 +52,7 @@ class MongoNewsService:
class MongoEntryTransformer:
"""_summary_.
Returns:
_type_: _description_
"""
"""Transform a dict to News entity and back."""
@staticmethod
def transform_ingoing(news: News) -> dict:

View File

@ -86,8 +86,8 @@ def test_by_id_result(mock_mongo_connector: Mock, mock_collection: Mock) -> None
"""Test CompanyMongoService get_by_id with result.
Args:
mock_mongo_connector (Mock): Mocked MongoConnector library
mock_collection (Mock): Mocked pymongo collection.
mock_mongo_connector (Mock): Mocked MongoConnector library
mock_collection (Mock): Mocked pymongo collection.
"""
mock_mongo_connector.database = {"companies": mock_collection}
service = CompanyMongoService(mock_mongo_connector)