Skip to content
Open

Solve #1771

Changes from 2 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
60 changes: 59 additions & 1 deletion app/create_file.py
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
# write your code here
import sys
import os
from datetime import datetime


def create_app() -> None:
args = sys.argv[1:]

dirs = []
filename = None

i = 0
while i < len(args):
if args[i] == "-d":
i += 1
while i < len(args) and not args[i].startswith("-"):
dirs.append(args[i])
i += 1
elif args[i] == "-f":
i += 1
if i < len(args):
filename = args[i]
i += 1
else:
i += 1

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

lines = []
while True:
try:
line_content = input("Enter content line: ")
if line_content.strip() == "stop":
break
lines.append(line_content)
except StopIteration:
break

current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

if os.path.exists(final_path):
with open(final_path, "a") as f:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The code uses hardcoded Chinese timestamp instead of the current_time variable defined on line 47. This doesn't match the task requirements which specify the timestamp format should be '%Y-%m-%d %H:%M:%S'.

f.write("\n")

with open(final_path, "a") as f:
f.write(f"{current_time}\n")
for num, line in enumerate(lines, start=1):
f.write(f"{num} {line}\n")


create_app()
Loading