Skip to content

Commit

Permalink
feat: add utils amd main module
Browse files Browse the repository at this point in the history
  • Loading branch information
alimghmi committed Oct 21, 2023
1 parent d35738a commit e6ef1a7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from config import logger
from scraper.engine import Engine
from config import logger, settings
from scraper import Engine
from transformer import Agent
from utils import create_inserter_objects


def main():
logger.info("Initializing Application")
engine = Engine()
df = engine.fetch()
print(df)
df_transformed = Agent(df).transform()
inserter = create_inserter_objects()
result = inserter.insert(df_transformed, settings.OUTPUT_TABLE)
print(result)
return


Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ pandas==2.0.3
python-decouple==3.8
requests==2.31.0
lxml==4.9.3
SQLAlchemy==2.0.22
pyodbc==5.0.1
1 change: 1 addition & 0 deletions utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .db_helper import create_inserter_objects
17 changes: 17 additions & 0 deletions utils/db_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from config import settings
from database.mssql import MSSQLDatabaseConnection, PandasSQLDataInserter


def create_inserter_objects() -> PandasSQLDataInserter:
db_connection = MSSQLDatabaseConnection(
settings.MSSQL_SERVER,
settings.MSSQL_DATABASE,
settings.MSSQL_USERNAME,
settings.MSSQL_PASSWORD,
)

data_inserter = PandasSQLDataInserter(
db_connection, max_retries=settings.INSERTER_MAX_RETRIES
)

return data_inserter

0 comments on commit e6ef1a7

Please sign in to comment.