Skip to content

Commit

Permalink
remove old database code
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswebb09 committed Oct 13, 2023
1 parent 77d463f commit e027271
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 52 deletions.
1 change: 0 additions & 1 deletion DirectReport/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from .database import *
from .commandline import *
from .browserview import *
from .models import *
Expand Down
16 changes: 1 addition & 15 deletions DirectReport/commandline/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,38 @@
package_root_directory = file.parents[1]
sys.path.append(str(package_root_directory))


@click.group()
def cli():
"""Main Click group for the command line interface."""
pass


@cli.group()
def list_items():
"""Click group for list items related commands."""
pass


@cli.group()
def item():
"""Click group for item related commands."""
pass


@cli.group()
def web_browser():
"""Click group for web browser related commands."""
pass


@click.command()
@click.option('--day', 'transformation', flag_value='day')
@click.option('--all', 'transformation', flag_value='all')
def list(transformation):
"""
Lists items based on the selected transformation flag.
:param transformation: The selected transformation flag (week, day, or all).
"""
if transformation == "day":
today = ListBuilder.list_today()
if today is not None:
print("today - " + str(today) + "\n")

elif transformation == "all":
all_list = ListBuilder.list_all()
if all_list is not None:
Expand All @@ -62,7 +55,6 @@ def list(transformation):
def new(transformation):
"""
Adds a new entry to the list.
:param transformation: The entry text to add.
"""
if transformation == "entry":
Expand All @@ -77,12 +69,10 @@ def new(transformation):
def delete(uid):
"""
Deletes an item with the specified ID.
:param uid: The ID of the item to delete.
"""
ListBuilder.delete(uid)


@click.command()
@click.option("--url", default="http://127.0.0.1:5000", help="URL to open in the web browser")
def launch(url):
Expand All @@ -93,20 +83,16 @@ def launch(url):
click.launch(url)
app.run()


@click.command()
def mail():
"""
Sends an email with the week's work items.
"""
recipient = "[email protected]"
subject = "work for week"

body = ""

webbrowser.open('mailto:?to=' + recipient + '&subject=' + subject + '&body=' + body, new=1)


list_items.add_command(list)
item.add_command(new)
item.add_command(delete)
Expand All @@ -116,4 +102,4 @@ def mail():
cli = click.CommandCollection(sources=[list_items, item, web_browser])

if __name__ == '__main__':
cli()
cli()
5 changes: 0 additions & 5 deletions DirectReport/database/__init__.py

This file was deleted.

7 changes: 2 additions & 5 deletions DirectReport/models/daily_builder.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#!/usr/bin/env python3

import datetime
from DirectReport.database.daily_storage import DailyUUIDTable
from DirectReport.models.daily_storage import DailyUUIDTable
import uuid


class DailyBuilder:

def __init__(self):
pass

@staticmethod
def get_daily_id():
"""
Retrieves the daily ID for the current day.
:return: The daily ID.
"""
today = datetime.date.today()
Expand All @@ -30,7 +29,6 @@ def get_daily_id():
def add_new_daily() -> object:
"""
Adds a new daily ID.
:return: The newly created daily ID.
"""
today = datetime.date.today().strftime("%m/%d/%Y")
Expand All @@ -49,7 +47,6 @@ def add_new_daily() -> object:
def list_all_daily_ids():
"""
Lists all daily IDs.
:return: A list of all daily IDs.
"""
storage = DailyUUIDTable('SQLite_Python.db')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sqlite3
import uuid


class DailyUUIDTable:
"""
A class to interact with SQLite database for managing daily date-UUID mappings.
Expand All @@ -12,7 +11,6 @@ class DailyUUIDTable:
def __init__(self, db_path, conn=None):
"""
Initializes the DailyUUIDTable object with the given SQLite database file path.
:param db_path: The SQLite database file path.
"""
self.db_path = db_path
Expand Down Expand Up @@ -41,11 +39,11 @@ def create_table(self):
def add_uuid(self, date, week_uuid_str, uuid_str=None):
"""
Adds a UUID for the specified date to the SQLite database.
:param date: The date to associate with the UUID.
:param week_uuid_str: The week UUID string.
:param uuid_str: The day UUID string (optional). If not provided, a new UUID will be generated.
"""

if uuid_str is None:
uuid_str = str(uuid.uuid4())
cursor = self.conn.cursor()
Expand Down
3 changes: 0 additions & 3 deletions DirectReport/models/entry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3

import datetime


class Entry:

"""
Expand All @@ -12,7 +10,6 @@ class Entry:
def __init__(self, uuid, topic, message, created_at, modified_on, week_uuid):
"""
Initialize the Entry object.
:param uuid: A unique identifier for the entry.
:type uuid: str
:param topic: The topic of the entry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sqlite3
from DirectReport.models.entry import Entry


class EntryStorage:
"""
A class to interact with SQLite database for storing and retrieving `Entry` objects.
Expand Down Expand Up @@ -31,7 +30,6 @@ def create_table(self):
def add_entry(self, entry):
"""
Adds an `Entry` object to the SQLite database.
:param entry: The `Entry` object to add.
"""

Expand All @@ -52,7 +50,6 @@ def add_entry(self, entry):
def get_entry(self, uuid):
"""
Retrieves an `Entry` object from the SQLite database by its UUID.
:param uuid: The UUID of the entry to retrieve.
:return: The `Entry` object if found, otherwise `None`.
"""
Expand All @@ -70,7 +67,6 @@ def get_entry(self, uuid):
def update_entry(self, entry):
"""
Updates an existing `Entry` object in the SQLite database.
:param entry: The `Entry` object to update.
"""

Expand All @@ -81,7 +77,6 @@ def update_entry(self, entry):
def delete_entry(self, uuid):
"""
Deletes an `Entry` object from the SQLite database by its UUID.
:param uuid: The UUID of the entry to delete.
"""

Expand All @@ -91,7 +86,6 @@ def delete_entry(self, uuid):
def get_entries_by_week(self, week_uuid):
"""
Retrieves all entries for a given week.
:param week_uuid: The UUID of the week for which to retrieve entries.
:return: A list of dictionaries containing the entries' data for the specified week.
"""
Expand All @@ -108,6 +102,7 @@ def get_uuid(self, date):
:param date: The date to get the associated UUID for.
:return: The UUID string if found, otherwise `None`.
"""

result = self.conn.execute(
"SELECT uuid, topic, message, created_at, modified_on, week_uuid FROM entries WHERE modified_on = ?",
(str(date),),
Expand All @@ -120,7 +115,6 @@ def get_uuid(self, date):
def delete_all_entries(self):
"""
Deletes all entries from the database.
:return: None
"""

Expand All @@ -130,7 +124,6 @@ def delete_all_entries(self):
def list_all_entries(self):
"""
Lists all date-UUID mappings from the SQLite database.
:return: A list of tuples containing (date, week_uuid, day_uuid).
"""
cursor = self.conn.cursor()
Expand Down
10 changes: 1 addition & 9 deletions DirectReport/models/list_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import datetime
import uuid

from DirectReport.models.entry import Entry
from DirectReport.database.entry_storage import EntryStorage
from DirectReport.models.entry_storage import EntryStorage
from DirectReport.models.daily_builder import DailyBuilder


class ListBuilder:

"""
Expand All @@ -21,7 +18,6 @@ def __init__(self):
def new(entry_text, topic_text=None):
"""
Creates a new entry with the given entry text and topic.
:param entry_text: The entry text.
:param topic_text: The topic for the entry (optional).
"""
Expand All @@ -41,7 +37,6 @@ def new(entry_text, topic_text=None):
def update(uid, entry_text, topic_text, created_at, weekly_id):
"""
Updates an entry with the given entry text and topic.
:param uid: The entry id.
:param entry_text: The entry text.
:param topic_text: The topic for the entry
Expand All @@ -59,7 +54,6 @@ def update(uid, entry_text, topic_text, created_at, weekly_id):
def delete(entry_id):
"""
Deletes an entry with the specified ID.
:param entry_id: The ID of the entry to delete.
"""
storage = EntryStorage('SQLite_Python.db')
Expand All @@ -69,7 +63,6 @@ def delete(entry_id):
def list_today():
"""
Lists all entries for today.
:return: A list of entries for today.
"""
storage = EntryStorage('SQLite_Python.db')
Expand All @@ -81,7 +74,6 @@ def list_today():
def list_all():
"""
Lists all entries.
:return: A list of all entries.
"""
storage = EntryStorage('SQLite_Python.db')
Expand Down
1 change: 1 addition & 0 deletions DirectReport/models/user_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask_login import UserMixin

class User(UserMixin):

def __init__(self, id, username, email, password):
self.id = email
self.uid = id
Expand Down
2 changes: 1 addition & 1 deletion DirectReport/tests/test_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from DirectReport.commandline.commandline import list
from DirectReport.commandline.commandline import mail
from DirectReport.commandline.commandline import delete
from DirectReport.database.entry_storage import EntryStorage
from DirectReport.models.entry_storage import EntryStorage
from DirectReport.models.entry import Entry
from click.testing import CliRunner
from datetime import datetime
Expand Down
2 changes: 1 addition & 1 deletion DirectReport/tests/test_db.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

from DirectReport.models.entry import Entry
from DirectReport.database.entry_storage import EntryStorage
from DirectReport.models.entry_storage import EntryStorage
from datetime import datetime
from pathlib import Path
import tempfile
Expand Down
2 changes: 1 addition & 1 deletion DirectReport/tests/test_list_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

from DirectReport.models.entry import Entry
from DirectReport.database.entry_storage import EntryStorage
from DirectReport.models.entry_storage import EntryStorage
from DirectReport.models.weekly_builder import WeeklyBuilder
import tempfile
import uuid
Expand Down

0 comments on commit e027271

Please sign in to comment.