Skip to content

Commit 5223c11

Browse files
committed
rename 'main.py' -> 'cli.py'
1 parent 9bf9e25 commit 5223c11

7 files changed

+24
-38
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The [Project Todo](TODO.md) and [JavaScript Todo](js/how_to_use.md#still-working
5151
See also a rough internal dependency graph of the project [here](assets/deps_graph.png) (the graph is not complete, but it gives a general idea of the project's structure). Generated using :
5252

5353
```bash
54-
pydeps main.py -o assets/deps_graph.png -T png --noshow --reverse --rankdir BT --exclude-exact models views controllers
54+
pydeps cli.py -o assets/deps_graph.png -T png --noshow --reverse --rankdir BT --exclude-exact models views controllers
5555
```
5656

5757
## Documentation

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ powershell -ExecutionPolicy ByPass -File .venv\Scripts\Activate.ps1
8787
With the environment set up, you can now run the script. In the terminal or command prompt, execute:
8888

8989
```bash
90-
python main.py
90+
python cli.py
9191
```
9292

9393
Now, follow the instructions on screen and choose your desired options, the script will handle the rest.

main.py cli.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Main file for testing the program."""
1+
"""Main file for running the program from the command line."""
22

33
import sys
44
from pathlib import Path
@@ -11,12 +11,12 @@
1111
update_config_file,
1212
)
1313
from controllers.file_system import (
14+
conversation_set_from_json,
15+
conversation_set_from_zip,
1416
create_n_save_all_weekwise_graphs,
1517
generate_n_save_all_wordclouds,
1618
get_bookmarklet_json_filepath,
17-
load_conversations_from_bookmarklet_json,
18-
load_conversations_from_openai_zip,
19-
save_conversation_set_to_dir,
19+
save_conversation_set,
2020
save_custom_instructions_to_file,
2121
)
2222
from models.conversation_set import ConversationSet
@@ -51,16 +51,14 @@ def main() -> None:
5151

5252
zip_filepath = Path(configs_dict["zip_file"])
5353

54-
all_conversations_set: ConversationSet = load_conversations_from_openai_zip(
54+
all_conversations_set: ConversationSet = conversation_set_from_zip(
5555
zip_filepath=zip_filepath,
5656
)
5757

5858
bookmarklet_json_filepath: Path | None = get_bookmarklet_json_filepath()
5959
if bookmarklet_json_filepath:
6060
print("Found bookmarklet download, loading 📂 ...\n")
61-
bookmarklet_conversations_set: (
62-
ConversationSet
63-
) = load_conversations_from_bookmarklet_json(
61+
bookmarklet_conversations_set: ConversationSet = conversation_set_from_json(
6462
json_filepath=bookmarklet_json_filepath,
6563
)
6664
all_conversations_set.update(conv_set=bookmarklet_conversations_set)
@@ -76,7 +74,7 @@ def main() -> None:
7674
markdown_folder: Path = output_folder / "Markdown"
7775
markdown_folder.mkdir(parents=True, exist_ok=True)
7876

79-
save_conversation_set_to_dir(
77+
save_conversation_set(
8078
conv_set=all_conversations_set,
8179
dir_path=markdown_folder,
8280
)

controllers/configuration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from models.node import Node
1111
from views.prompt_user import prompt_user
1212

13-
from .file_system import default_output_folder, get_openai_zip_filepath
13+
from .file_system import default_output_folder, most_recently_downloaded_zip
1414

1515

1616
def get_user_configs() -> dict[str, Any]:
@@ -21,7 +21,7 @@ def get_user_configs() -> dict[str, Any]:
2121
default_configs = json_load(fp=file)
2222

2323
if not default_configs["zip_file"]:
24-
default_configs["zip_file"] = get_openai_zip_filepath()
24+
default_configs["zip_file"] = most_recently_downloaded_zip()
2525

2626
if not default_configs["output_folder"]:
2727
default_configs["output_folder"] = default_output_folder()

controllers/file_system.py

+11-23
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030

3131

32-
def load_conversations_from_openai_zip(zip_filepath: Path) -> ConversationSet:
32+
def conversation_set_from_zip(zip_filepath: Path) -> ConversationSet:
3333
"""Load the conversations from the OpenAI zip export file."""
3434
with ZipFile(file=zip_filepath, mode="r") as file:
3535
file.extractall(path=zip_filepath.with_suffix(suffix=""))
@@ -44,15 +44,15 @@ def load_conversations_from_openai_zip(zip_filepath: Path) -> ConversationSet:
4444
return ConversationSet(conversations=conversations)
4545

4646

47-
def load_conversations_from_bookmarklet_json(json_filepath: Path) -> ConversationSet:
47+
def conversation_set_from_json(json_filepath: Path) -> ConversationSet:
4848
"""Load the conversations from the bookmarklet json export file."""
4949
with open(file=json_filepath, encoding="utf-8") as file:
5050
conversations = json_load(fp=file)
5151

5252
return ConversationSet(conversations=conversations)
5353

5454

55-
def save_conversation_to_file(conversation: Conversation, filepath: Path) -> None:
55+
def save_conversation(conversation: Conversation, filepath: Path) -> None:
5656
"""Save a conversation to a file, with added modification time."""
5757
base_file_name: str = filepath.stem
5858

@@ -68,14 +68,14 @@ def save_conversation_to_file(conversation: Conversation, filepath: Path) -> Non
6868
utime(path=filepath, times=(conversation.update_time, conversation.update_time))
6969

7070

71-
def save_conversation_set_to_dir(conv_set: ConversationSet, dir_path: Path) -> None:
71+
def save_conversation_set(conv_set: ConversationSet, dir_path: Path) -> None:
7272
"""Save a conversation set to a directory, one markdown file per conversation."""
7373
for conversation in tqdm(
7474
iterable=conv_set.conversation_list,
7575
desc="Writing Markdown 📄 files",
7676
):
7777
file_path: Path = dir_path / f"{conversation.sanitized_title()}.md"
78-
save_conversation_to_file(conversation=conversation, filepath=file_path)
78+
save_conversation(conversation=conversation, filepath=file_path)
7979

8080

8181
def save_weekwise_graph_from_conversation_set(
@@ -103,8 +103,6 @@ def save_weekwise_graph_from_conversation_set(
103103
fname=dir_path / file_name,
104104
dpi=300,
105105
)
106-
else:
107-
raise ValueError("Invalid time period for weekwise graph")
108106

109107

110108
def create_n_save_all_weekwise_graphs(
@@ -212,37 +210,27 @@ def save_custom_instructions_to_file(conv_set: ConversationSet, filepath: Path)
212210

213211

214212
def default_output_folder() -> str:
215-
"""Returns the default output folder path.
216-
217-
(put the function in a separate file to isolate file system operations)
218-
"""
213+
"""Returns the default output folder path : ~/Documents/ChatGPT Data"""
214+
# put the function here to isolate file system operations
219215
return str(object=Path.home() / "Documents" / "ChatGPT Data")
220216

221217

222-
def get_openai_zip_filepath() -> str:
223-
"""Returns the path to the most recent zip file in the Downloads folder,
224-
excluding those containing 'bookmarklet'.
225-
"""
218+
def most_recently_downloaded_zip() -> str:
219+
"""Path to the most recently created zip file in the Downloads folder."""
226220
downloads_folder: Path = Path.home() / "Downloads"
227221

228-
# Filter out zip files with names that contain "bookmarklet"
229-
zip_files: list[Path] = [
230-
x for x in downloads_folder.glob(pattern="*.zip") if "bookmarklet" not in x.name
231-
]
222+
zip_files: list[Path] = [x for x in downloads_folder.glob(pattern="*.zip")]
232223

233224
if not zip_files:
234225
return ""
235226

236-
# Most recent zip file in downloads folder, excluding those containing "bookmarklet"
237227
default_zip_filepath: Path = max(zip_files, key=lambda x: x.stat().st_ctime)
238228

239229
return str(object=default_zip_filepath)
240230

241231

242232
def get_bookmarklet_json_filepath() -> Path | None:
243-
"""Returns the path to the most recent json file in the Downloads folder,
244-
containing 'bookmarklet'.
245-
"""
233+
"""Path to the most recently downloaded JSON file, with "bookmarklet" in the name."""
246234
downloads_folder: Path = Path.home() / "Downloads"
247235

248236
# Filter out json files with names that do not contain "bookmarklet"

js/how_to_use.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Alternatively, you can create a bookmarklet with the code in [this file](bookmar
1111

1212
(You should refresh the page after the download finishes, to clear the UI widget and the console logs.)
1313

14-
Now, if you run the `main.py` script, it should recognize the new downloaded json file and add the conversations to the ones from the OpenAI export, that way ALL the conversations are converted to markdown files, as well as the other data visualizations stuff.
14+
Now, if you run the `cli.py` script, it should recognize the new downloaded json file and add the conversations to the ones from the OpenAI export, that way ALL the conversations are converted to markdown files, as well as the other data visualizations stuff.
1515

1616
This is a very rudimentary js script, and it needs more error handling. I've tried it on Chrome, and it works so far.
1717
Could break at anytime if OpenAI changes their data permissions or the `/backend-api/` API.

playground.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"\n",
1111
"But I get the worry of accidentally breaking things when contributing code. So, I made this notebook to help with that. It's a work in progress, aimed at letting you easily see specific outputs of interest for smoother development.\n",
1212
"\n",
13-
"Previously, my basic testing meant using a `test.py` file to generate a few markdowns and then checking them manually. Or, for a deeper look, I'd run the `main.py` and wait a while to see everything, which isn't quick on my laptop.\n",
13+
"Previously, my basic testing meant using a `test.py` file to generate a few markdowns and then checking them manually. Or, for a deeper look, I'd run the `cli.py` and wait a while to see everything, which isn't quick on my laptop.\n",
1414
"\n",
1515
"This notebook aims to streamline that process, letting you test and inspect targeted parts of the output without the fear of breaking things."
1616
]

0 commit comments

Comments
 (0)