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


data = sys.argv


def write_file(filepath: str) -> 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.

Code structure issue: The write_file() function should handle appending to existing files separately from creating new files. Consider passing additional parameters or checking file existence before deciding write mode.

with open(filepath, "a") as file:
file.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When appending to an existing file, a blank line separator should be added between the new timestamp and existing content. The requirements show: blank line before 2022-02-01 14:46:01 when appending new content to an existing file.

+ "\n")
while True:
text = input("Enter content line:")
if text == "stop":
break
file.write(text + "\n")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Task requirement violation: Line numbering is missing. The content should be numbered starting from 1 (format: 1 Line1 content\n2 Line2 content).

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 numbering is missing. Requirements specify content lines should be numbered starting from 1 with format 1 Line1 content, 2 Line2 content. Currently the code writes text directly without numbers.



if "-d" in data:
analyzed_data = []
for item in data:
if item == "-f":
break
analyzed_data.append(item)
if "-f" in data:
path = os.path.join(*analyzed_data[2:])
os.makedirs(path)
current_filepath = os.path.join(path, data[-1] + ".txt")
write_file(str(current_filepath))
else:
os.makedirs(os.path.join(*analyzed_data[2:]), exist_ok=True)

if "-f" in data and "-d" not in data:
write_file(data[-1] + ".txt")
Loading