From 6e3ee40113bd1979f9a15520bb5cc0ca8fde6c97 Mon Sep 17 00:00:00 2001 From: Scott <38087336+mergemaven11@users.noreply.github.com> Date: Sun, 19 May 2024 10:21:46 -0400 Subject: [PATCH] black config --- cli/handlers.py | 40 +++++++++++++---------- cli/utils.py | 25 ++++++++------- journal.py | 15 ++++----- poetry.lock | 84 ++++++++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 20 ++++++++++++ 5 files changed, 148 insertions(+), 36 deletions(-) diff --git a/cli/handlers.py b/cli/handlers.py index 5324bc5..d548ad1 100644 --- a/cli/handlers.py +++ b/cli/handlers.py @@ -24,24 +24,26 @@ def add_entry_to_file(entry_obj: t.Dict[str, t.Any], entries_file: str) -> None: None """ # Load existing entries from the file - with open(entries_file, 'r') as f: + with open(entries_file, "r") as f: entries_data: list = json.load(f) # Generate a unique ID and timestamp for the new entry - entry_obj['id'] = str(uuid.uuid4()) - entry_obj['timestamp'] = utils.current_datetime() + entry_obj["id"] = str(uuid.uuid4()) + entry_obj["timestamp"] = utils.current_datetime() # Append the new entry object to the existing list entries_data.append(entry_obj) # Write the updated entry data back to the file - with open(entries_file, 'w') as f: + with open(entries_file, "w") as f: json.dump(entries_data, f, indent=4) # indent for pretty printing + # Searching an entry + def search_entries(keyword: str): - """ Search Entries by title, dropdown selection for multiple finds. + """Search Entries by title, dropdown selection for multiple finds. View all vs view one @@ -61,18 +63,25 @@ def search_entries(keyword: str): # Use InquirerPy to present a dropdown selection questions = [ { - 'type': 'list', - 'name': 'selected_entry', - 'message': "Select an entry to view:", - 'choices': choices + "type": "list", + "name": "selected_entry", + "message": "Select an entry to view:", + "choices": choices, } ] - + answers = prompt(questions) - + # Find the selected entry - selected_entry = next((item for item in search_items if f"{item['title']} - {item['timestamp']}" == answers['selected_entry']), None) - + selected_entry = next( + ( + item + for item in search_items + if f"{item['title']} - {item['timestamp']}" == answers["selected_entry"] + ), + None, + ) + if selected_entry: # Pretty-print the selected entry using rich console.print("[bold green]Selected Entry:[/bold green]") @@ -81,11 +90,10 @@ def search_entries(keyword: str): console.print("[bold red]No entry selected.[/bold red]") - -# Viewing an entry +# Viewing an entry # Delete Entries # Edit Entries -# Export Entries \ No newline at end of file +# Export Entries diff --git a/cli/utils.py b/cli/utils.py index 02fac5a..ae859b4 100644 --- a/cli/utils.py +++ b/cli/utils.py @@ -5,8 +5,9 @@ from datetime import datetime, timezone -ENTRIES_DIR = './entries' -ENTRIES_FILE = './entries/entries.json' +ENTRIES_DIR = "./entries" +ENTRIES_FILE = "./entries/entries.json" + def check_entries_dir(): """ @@ -14,20 +15,19 @@ def check_entries_dir(): """ if not os.path.exists(ENTRIES_DIR): os.makedirs(ENTRIES_DIR) - with open(ENTRIES_FILE, 'w') as f: + with open(ENTRIES_FILE, "w") as f: # Create an empty array to store entries initially json.dump([], f) return ENTRIES_FILE - def current_datetime(): """ Get the current UTC datetime and format it to a more human-readable format. """ # Get the current datetime in UTC timezone - utc_datetime = datetime.now(timezone.utc) # TODO handle tz + utc_datetime = datetime.now(timezone.utc) # TODO handle tz # Format the datetime object to a more human-readable format formatted_datetime = utc_datetime.strftime("%m/%d/%Y @ %I:%M:%S %p") @@ -40,24 +40,25 @@ def search(keyword: str) -> t.List[t.Dict[str, str]]: Args: keyword (str): Keyword used to query JSON file. - + Returns: search_data (List): List of entries matching the keyword. TODO: - Fix permissions issue """ search_data = [] - + if os.path.exists(ENTRIES_DIR): - with open(ENTRIES_DIR, 'r') as file: + with open(ENTRIES_DIR, "r") as file: entries = json.load(file) - + for entry in entries: - if re.search(keyword, entry['title'], re.IGNORECASE) or re.search(keyword, entry['content'], re.IGNORECASE): + if re.search(keyword, entry["title"], re.IGNORECASE) or re.search( + keyword, entry["content"], re.IGNORECASE + ): search_data.append(entry) if not search_data: print(f"There are no entries with keyword: {keyword}") - - return search_data + return search_data diff --git a/journal.py b/journal.py index 40f79b8..da6d25c 100644 --- a/journal.py +++ b/journal.py @@ -8,6 +8,7 @@ # def main(): # print("Hello World") + # Add imported commands to the main Typer application instance @app.command() def add(): @@ -15,8 +16,8 @@ def add(): entry = typer.prompt("Please enter your journal entry") # Send data to add handler handler.add_entry_to_file({"Title": title, "Entry": entry}) - - + + @app.command() def view(name: str): typer.echo(f"Hello {name}") @@ -26,12 +27,12 @@ def view(name: str): def export(name: str): typer.echo(f"Hello {name}") + @app.command() -def search(keyword: str): +def search(keyword: str): handler.search_entries(keyword) - @app.command() def delete(name: str): typer.echo(f"Hello {name}") @@ -43,6 +44,6 @@ def edit(name: str): if __name__ == "__main__": - # Check if first entry, if so create the dir and file. - util.check_entries_dir() - app() \ No newline at end of file + # Check if first entry, if so create the dir and file. + util.check_entries_dir() + app() diff --git a/poetry.lock b/poetry.lock index 04dd445..5bbc08d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,49 @@ # This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +[[package]] +name = "black" +version = "24.4.2" +description = "The uncompromising code formatter." +optional = false +python-versions = ">=3.8" +files = [ + {file = "black-24.4.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dd1b5a14e417189db4c7b64a6540f31730713d173f0b63e55fabd52d61d8fdce"}, + {file = "black-24.4.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8e537d281831ad0e71007dcdcbe50a71470b978c453fa41ce77186bbe0ed6021"}, + {file = "black-24.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eaea3008c281f1038edb473c1aa8ed8143a5535ff18f978a318f10302b254063"}, + {file = "black-24.4.2-cp310-cp310-win_amd64.whl", hash = "sha256:7768a0dbf16a39aa5e9a3ded568bb545c8c2727396d063bbaf847df05b08cd96"}, + {file = "black-24.4.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:257d724c2c9b1660f353b36c802ccece186a30accc7742c176d29c146df6e474"}, + {file = "black-24.4.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bdde6f877a18f24844e381d45e9947a49e97933573ac9d4345399be37621e26c"}, + {file = "black-24.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e151054aa00bad1f4e1f04919542885f89f5f7d086b8a59e5000e6c616896ffb"}, + {file = "black-24.4.2-cp311-cp311-win_amd64.whl", hash = "sha256:7e122b1c4fb252fd85df3ca93578732b4749d9be076593076ef4d07a0233c3e1"}, + {file = "black-24.4.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:accf49e151c8ed2c0cdc528691838afd217c50412534e876a19270fea1e28e2d"}, + {file = "black-24.4.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:88c57dc656038f1ab9f92b3eb5335ee9b021412feaa46330d5eba4e51fe49b04"}, + {file = "black-24.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be8bef99eb46d5021bf053114442914baeb3649a89dc5f3a555c88737e5e98fc"}, + {file = "black-24.4.2-cp312-cp312-win_amd64.whl", hash = "sha256:415e686e87dbbe6f4cd5ef0fbf764af7b89f9057b97c908742b6008cc554b9c0"}, + {file = "black-24.4.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bf10f7310db693bb62692609b397e8d67257c55f949abde4c67f9cc574492cc7"}, + {file = "black-24.4.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:98e123f1d5cfd42f886624d84464f7756f60ff6eab89ae845210631714f6db94"}, + {file = "black-24.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:48a85f2cb5e6799a9ef05347b476cce6c182d6c71ee36925a6c194d074336ef8"}, + {file = "black-24.4.2-cp38-cp38-win_amd64.whl", hash = "sha256:b1530ae42e9d6d5b670a34db49a94115a64596bc77710b1d05e9801e62ca0a7c"}, + {file = "black-24.4.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:37aae07b029fa0174d39daf02748b379399b909652a806e5708199bd93899da1"}, + {file = "black-24.4.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:da33a1a5e49c4122ccdfd56cd021ff1ebc4a1ec4e2d01594fef9b6f267a9e741"}, + {file = "black-24.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ef703f83fc32e131e9bcc0a5094cfe85599e7109f896fe8bc96cc402f3eb4b6e"}, + {file = "black-24.4.2-cp39-cp39-win_amd64.whl", hash = "sha256:b9176b9832e84308818a99a561e90aa479e73c523b3f77afd07913380ae2eab7"}, + {file = "black-24.4.2-py3-none-any.whl", hash = "sha256:d36ed1124bb81b32f8614555b34cc4259c3fbc7eec17870e8ff8ded335b58d8c"}, + {file = "black-24.4.2.tar.gz", hash = "sha256:c872b53057f000085da66a19c55d68f6f8ddcac2642392ad3a355878406fbd4d"}, +] + +[package.dependencies] +click = ">=8.0.0" +mypy-extensions = ">=0.4.3" +packaging = ">=22.0" +pathspec = ">=0.9.0" +platformdirs = ">=2" + +[package.extras] +colorama = ["colorama (>=0.4.3)"] +d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"] +jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] +uvloop = ["uvloop (>=0.15.2)"] + [[package]] name = "click" version = "8.1.7" @@ -103,6 +147,17 @@ files = [ {file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"}, ] +[[package]] +name = "mypy-extensions" +version = "1.0.0" +description = "Type system extensions for programs checked with the mypy type checker." +optional = false +python-versions = ">=3.5" +files = [ + {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, + {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, +] + [[package]] name = "packaging" version = "24.0" @@ -114,6 +169,17 @@ files = [ {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"}, ] +[[package]] +name = "pathspec" +version = "0.12.1" +description = "Utility library for gitignore style pattern matching of file paths." +optional = false +python-versions = ">=3.8" +files = [ + {file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"}, + {file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"}, +] + [[package]] name = "pfzy" version = "0.3.4" @@ -128,6 +194,22 @@ files = [ [package.extras] docs = ["Sphinx (>=4.1.2,<5.0.0)", "furo (>=2021.8.17-beta.43,<2022.0.0)", "myst-parser (>=0.15.1,<0.16.0)", "sphinx-autobuild (>=2021.3.14,<2022.0.0)", "sphinx-copybutton (>=0.4.0,<0.5.0)"] +[[package]] +name = "platformdirs" +version = "4.2.2" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`." +optional = false +python-versions = ">=3.8" +files = [ + {file = "platformdirs-4.2.2-py3-none-any.whl", hash = "sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee"}, + {file = "platformdirs-4.2.2.tar.gz", hash = "sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3"}, +] + +[package.extras] +docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] +type = ["mypy (>=1.8)"] + [[package]] name = "pluggy" version = "1.5.0" @@ -287,4 +369,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "c9ab25e0dce9a3bb2f0ae17bbf64437d1b16006a0e311637c5bb84465ddbcf56" +content-hash = "636f64a8dc0e2ac5601d2e4c420595677f48e0c96420e33d4f8bcb477ccc3d57" diff --git a/pyproject.toml b/pyproject.toml index 4ec972c..997c4ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,26 @@ freezegun = "^1.5.1" inquirerpy = "^0.3.4" rich = "^13.7.1" +[tool.poetry.group.dev.dependencies] +black = "^24.4.2" + +[tool.black] +line-length = 88 +target-version = ['py38', 'py39', 'py312'] +exclude = ''' +/( + \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist + | (?!cli|journal\.py$).* # Exclude everything except cli directory and journal.py +)/ +''' [build-system] requires = ["poetry-core"]