-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.py
More file actions
executable file
·49 lines (40 loc) · 1.09 KB
/
notes.py
File metadata and controls
executable file
·49 lines (40 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
"""Bloco de notas
$ notes.py new "Minha Nota"
tag: tech
text:
Anotação 01 em tecnologia
$ notes.py read --tag=tech
...
"""
__version__ = "0.1.0"
import os
import sys
cmds = ("read", "new")
path = os.curdir
filepath = os.path.join(path, "notes.txt")
arguments = sys.argv[1:]
if not arguments:
print("Invalid arguments")
print(f"You must specify subcommand {cmds}")
sys.exit(1)
if arguments[0] not in cmds:
print(f"Invalid command {arguments[0]}")
if arguments[0] == "read":
for line in open(filepath):
title, tag, text = line.split("\t")
if tag == arguments[1].lower():
print(f"Título: {title}")
print(f"Texto: {text}")
print("-" * 30)
if arguments[0] == "new":
with open(filepath, "a") as file_:
title = arguments[1] # TODO: tratar exception
text = [
f"{title}",
input("tag:").strip(),
input("text:\n").strip(),
]
# \t - tsb tab separete value
with open(filepath, "a") as file_:
file_.write("\t".join(text) + "\n")