-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes-v1.py
More file actions
56 lines (46 loc) · 1.29 KB
/
notes-v1.py
File metadata and controls
56 lines (46 loc) · 1.29 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
56
#!/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 --tag=tech
...
...
"""
__version__ = "0.1.0"
import os
import sys
path = os.curdir
filepath = os.path.join(path, "notes.txt")
arguments = sys.argv[1:]
if not arguments:
print("Invalid usage")
sys.exit(1)
cmds = ("read", "new")
if arguments[0] not in cmds:
print(f'Invalid command {argument[0]}')
if arguments[0] == 'read':
# leitura das notas
searchtype, keyword = arguments[1].split("=")
searchtype = searchtype.lstrip("-").strip().lower()
keyword = keyword.strip().lower()
result = []
with open(filepath) as file:
for line in file:
if "*" in line:
content = line.split("*")
if searchtype == "tag" and keyword == content[1].lower():
print(content[2])
if arguments[0] == 'new':
# criação da nota
if not arguments[1]:
title = input("Insert note title: ")
else:
title = arguments[1]
tag = input("tag: ")
text = input("text: ")
with open(filepath, "a") as file:
#for key, value in note.items():
# file.writelines(f'{key}:{value}\n')
file.writelines(f'\n{title}*{tag}*{text}')