Skip to content
Open

done #1760

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


args = sys.argv[1:]


def create_file() -> None:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

path = ""

if "-d" in args:
file_path = args[args.index("-d") + 1:]
if "-f" in file_path:
file_path = file_path[:file_path.index("-f")]
path = os.path.join(*file_path)
os.makedirs(path, exist_ok=True)

if "-f" in args:
name = args[args.index("-f") + 1]

full_path = os.path.join(path, name) if path else name

content = []

while True:
line = input("Enter content line: ")
if line == "stop":
break

content.append(f"{len(content) + 1} {line}\n")

mode = "a" if os.path.exists(full_path) else "w"

with open(full_path, mode) as f:
if mode == "a":
f.write("\n")

f.write(timestamp + "\n")
f.writelines(content)


create_file()
Loading