-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.py
More file actions
55 lines (43 loc) · 1.1 KB
/
notes.py
File metadata and controls
55 lines (43 loc) · 1.1 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
49
50
51
52
53
54
55
#!/usr/bin/env python3
""" Bloco de Notas
$ notes.py new "Minha Nota"
tag: tech
text:
Anotação geral sobre carreira de tecnologia
$ notes.py read 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 usage")
print(f"You must specify subcommand {cmds}")
sys.exit(1)
if arguments[0] not in cmds:
print(f'Invalid command {argument[0]}')
if arguments[0] == 'read':
# leitura das notas
for line in open(filepath):
title, tag, text = line.split("\t")
if tag.lower() == arguments[1].lower():
print(f'title: {title}')
print(f'text: {text}')
print("-" * 30)
print()
if arguments[0] == 'new':
# criação da nota
title = arguments[1] # TODO: tratar exception
text = [
f'{title}',
input("tag:").strip(),
input("text:\n").strip(),
]
# \t - tsv
with open(filepath, "a") as file_:
file_.write("\t".join(text) + "\n")