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

Commit

Permalink
Remove dotenv; cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
thought-tobi committed Apr 2, 2024
1 parent a313aa7 commit 6439bbb
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ graphs/
package/

.terraform*
requirements.txt
16 changes: 1 addition & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pillow = "^10.2.0"
pymongo = "^4.6.2"
python-telegram-bot = {extras = ["job-queue"], version = "^21.0.1"}
pydantic = "^2.6.4"
python-dotenv = "^1.0.1"
emoji = "^2.10.1"
expiringdict = "^1.2.2"
pandas = "^2.2.1"
Expand Down
15 changes: 4 additions & 11 deletions src/handlers/record_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,20 @@ async def offset_handler(update: Update, context) -> None:
await send(update, text=incorrect_state_message)


@autowire("record_repository", "user_repository")
async def baseline_handler(
update: Update,
_,
record_repository: RecordRepository,
user_repository: UserRepository,
):
"""
Handler for the /baseline command.
If the user has defined baselines for every metric,
this command will create a record consisting of those values.
:return:
"""
user_repository, record_repository = get_user_repository(), get_record_repository()
# user_repository, record_repository = get_user_repository(), get_record_repository()
user = user_repository.find_user(update.effective_user.id)
if user.has_baselines_defined():
record = {metric.name: metric.baseline for metric in user.metrics}
Expand Down Expand Up @@ -265,15 +268,5 @@ def create_baseline_success_message(record: dict) -> str:
return f"Baseline record successfully created: {bullet_point_list}."


@autowire("user_repository")
def get_user_repository(user_repository: UserRepository):
return user_repository


@autowire("record_repository")
def get_record_repository(record_repository: RecordRepository):
return record_repository


def modify_timestamp(timestamp: datetime.datetime, offset: int) -> datetime.datetime:
return timestamp - datetime.timedelta(days=offset)
10 changes: 3 additions & 7 deletions src/handlers/user_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
from src.repository.user_repository import UserRepository


async def create_user(update: Update, _) -> None:
@autowire("user_repository")
async def create_user(update: Update, _, user_repository: UserRepository) -> None:
"""
Handles /start command.
Creates user based on the user_id included in the update object.
:param user_repository: autowired.
:param update: Update from the Telegram bot.
:param _: CallbackContext: is irrelevant
:return:
"""
# Handle registration
user_id = update.effective_user.id
user_repository = get_user_repository()
if not user_repository.find_user(user_id):
logging.info(f"Creating user {user_id}")
user_repository.create_user(user_id)
Expand All @@ -35,11 +36,6 @@ async def create_user(update: Update, _) -> None:
)


@autowire("user_repository")
def get_user_repository(user_repository: UserRepository):
return user_repository


@autowire("configuration", "notifier")
def setup_notifications(
user_id: int, configuration: Configuration, notifier: Notifier
Expand Down
3 changes: 1 addition & 2 deletions src/repository/record_repository.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import datetime

import pymongo
from dotenv import load_dotenv
from pymongo import MongoClient

from src.autowiring.injectable import Injectable
from src.model.record import Record, RecordData, DatabaseRecord
from src.model.record import Record, DatabaseRecord


class RecordRepository(Injectable):
Expand Down
3 changes: 0 additions & 3 deletions src/repository/user_repository.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pymongo
from injector import inject
from pymongo import MongoClient

from src.autowiring.inject import autowire
Expand All @@ -11,7 +9,6 @@


class UserRepository(Injectable):
@inject
def __init__(self, mongo_client: MongoClient):
mood_tracker = mongo_client["mood_tracker"]
self.user = mood_tracker["user"]
Expand Down
5 changes: 1 addition & 4 deletions src/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
import pandas as pd
from pymongo import MongoClient

from dotenv import load_dotenv


def visualize_monthly_data(user_id: int, month: Tuple[int, int] = None):
load_dotenv()
# Connect to MongoDB (replace with your connection details)
client = MongoClient(f"mongodb://{os.environ.get('MONGO_CONNECTION_STRING')}/")
client = MongoClient(f"mongodb://{os.environ.get('MONGO_HOST')}/")
db = client.mood_tracker
collection = db.records

Expand Down

0 comments on commit 6439bbb

Please sign in to comment.