Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
👌 IMPROVE: work towards more modularity
Browse files Browse the repository at this point in the history
  • Loading branch information
tallguyjenks committed May 16, 2023
1 parent 68e6c2d commit b4c508b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
log_file: logs/hooks.log
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
log_file: logs/hooks.log
# - repo: https://github.com/asottile/seed-isort-config
# rev: v2.2.0
# hooks:
# - id: seed-isort-config
# log_file: logs/hooks.log
# - repo: https://github.com/pre-commit/mirrors-isort
# rev: v5.10.1
# hooks:
# - id: isort
# log_file: logs/hooks.log
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
Expand Down
6 changes: 3 additions & 3 deletions images/interrogate_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ def collect_deltas(df: pd.DataFrame, watermark: dt.datetime) -> pd.DataFrame:
return filtered_df


def generate_db_connection() -> sessionmaker.object_session:
engine = create_engine(Settings().db_connection_string)
def generate_db_connection(connection_string) -> sessionmaker.object_session:
engine = create_engine(connection_string)
Session = sessionmaker(bind=engine)
session = Session()
return session


def get_watermark() -> dt.datetime:
query = text("SELECT MAX(date) FROM {};".format(Settings().target_table))
session = generate_db_connection()
def get_watermark(target_table, connection_string) -> dt.datetime:
query = text("SELECT MAX(date) FROM {};".format(target_table))
session = generate_db_connection(connection_string)
result = session.execute(query).scalar()
watermark = pd.Timestamp("1900-01-01") if result is None else result
return watermark
Expand Down
3 changes: 1 addition & 2 deletions src/database.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from config import Settings
from sqlalchemy import DECIMAL, Column, DateTime, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base

from config import Settings

Base = declarative_base()


Expand Down
8 changes: 5 additions & 3 deletions src/file_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from datetime import datetime as dt

import pandas as pd
from config import Settings
from database import WorkoutData
from loguru import logger as log
from watchdog.events import FileSystemEventHandler

Expand All @@ -15,8 +17,6 @@
get_watermark,
load_data_into_dataframe,
)
from config import Settings
from database import WorkoutData


class MonitorFolder(FileSystemEventHandler):
Expand Down Expand Up @@ -47,7 +47,9 @@ def process_data() -> pd.DataFrame:
try:
processed_data = collect_deltas(
load_data_into_dataframe(get_staged_file_full_path()),
get_watermark(),
get_watermark(
Settings().target_table, Settings().db_connection_string
),
)
return processed_data
except Exception as e:
Expand Down
1 change: 0 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dotenv import load_dotenv

from file_watcher import MonitorFolder

load_dotenv() # Load environment variables from .env file or docker environmental variables
Expand Down

0 comments on commit b4c508b

Please sign in to comment.