Skip to content
Open
Changes from 1 commit
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
43 changes: 42 additions & 1 deletion app/create_file.py
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# write your code here
import os
import sys
from datetime import datetime


def create_file() -> 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

path = os.path.join(*dirs) if dirs else ""
if path:
os.makedirs(path, exist_ok=True)

full_path = os.path.join(path, filename)

line_number = 1
file_exists = os.path.exists(full_path)
with open(full_path, "a", encoding="utf-8") as file:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if file_exists:
file.write("\n")
file.write(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
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 the 'Don't Repeat Yourself' section: 'Create separate functions in order not to have repeating blocks of code.' The code has all logic in one function without separating concerns (argument parsing, directory creation, file writing). Consider creating separate functions for these distinct operations.

Loading