Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion app/create_file.py
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
# write your code here
import os
import sys
from datetime import datetime


def parse_arguments(argv: str) -> str | None:
i = 1
dirs = []
filename = None
while i < len(sys.argv):
if sys.argv[i] == "-d":
i += 1
while (i < len(sys.argv)) and not sys.argv[i].startswith("-"):
dirs.append(sys.argv[i])
i += 1
continue
elif sys.argv[i] == "-f":
filename = sys.argv[i + 1]
i += 2
continue
i += 1
return dirs, filename


def build_path(dirs: list, filename: str) -> str | bytes:
path = os.path.join(*dirs) if dirs else ""
if path:
os.makedirs(path, exist_ok=True)

return os.path.join(path, filename)


def write_content(full_path: str) -> None:
line_number = 1
file_exists = os.path.exists(full_path)

with open(full_path, "a", encoding="utf-8") as file:
if file_exists:
file.write("\n")

timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
file.write(f"{timestamp}\n")

while True:
user_input = input("Enter content line: ")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item #1 under Code Style: 'Use one style of quotes in your code. Double quotes are preferable.' Single quotes are used here while double quotes are used elsewhere in the file.


if user_input.lower() == "stop":
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quote used here. Per checklist requirements, double quotes should be used consistently throughout the code.

break

file.write(f"{line_number}. {user_input}\n")
Comment on lines +49 to +50
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line numbers have a period after them (. ) but the requirements show format like 1 Line1 content without periods.

line_number += 1


def create_file() -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is defined but never called. Add if __name__ == "__main__": block or call create_file() to make the script executable.

dirs, filename = parse_arguments(sys.argv)
full_path = build_path(dirs, filename)
write_content(full_path)


if __name__ == "__main__":
create_file()
Loading