Skip to content

Commit 314c1ee

Browse files
committed
Changing to python 3.5, fixing bugs
1 parent 05cfe97 commit 314c1ee

9 files changed

Lines changed: 55 additions & 49 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<h1>Terminal N</h1>
22

3-
<p>A really easy to use terminal application that:</p>
3+
<p>A really easy to use terminal tool that:</p>
44
<ul>
55
<li>Creates notes</li>
6-
<li>Creates encrypted notes with AES</li>
76
<li>Modifies Notes</li>
87
<li>Deletes notes</li>
8+
<li>Creates encrypted notes with AES</li>
9+
<li>Deciphers encrypted notes</li>
910
</ul>
1011

1112
<p>Requirements</p>
1213
<ul>
13-
<li>python >= 3.6</li>
14+
<li>python == 3.5.2</li>
1415
<li>pycrypto == 2.6.1</li>
1516
</ul>

src/aes_note.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ def decrypt(self, note_cod):
3333
enc = b64decode(notes_db[note_cod].text)
3434
iv = enc[:16]
3535
cipher = AES.new(self.key, AES.MODE_CBC, iv)
36-
print(pretty_string(f'''
37-
ID: {notes_db[note_cod].cod} Title: {notes_db[note_cod].title[:20]}
36+
print(pretty_string('''
37+
ID: {} Title: {}
3838
---------------------------------------------------------
39-
Text: {self.unpad(cipher.decrypt(enc[16:])).decode('UTF-8')}
40-
---------------------------------------------------------'''))
39+
Text: {}
40+
---------------------------------------------------------'''.format(notes_db[note_cod].cod,\
41+
notes_db[note_cod].title[:20],\
42+
self.unpad(cipher.decrypt(enc[16:])).decode('UTF-8'))))
4143
else:
42-
print(f"\nNo note with the id {note_cod}")
44+
print("No note with the id {}".format(note_cod))

src/data/notes

12 KB
Binary file not shown.

src/data/notes.bak

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/data/notes.dat

-5 Bytes
Binary file not shown.

src/data/notes.dir

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/mod_note.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66

77
def mod_note(value):
8-
with shelve.open('./data/notes', 'r') as notes_db:
8+
with shelve.open("./data/notes", 'r') as notes_db:
99
if value in notes_db:
1010
root = tk.Tk()
11-
root.title(f"Note {value}")
11+
root.title("Note {}".format(value))
1212
NoteModifyWindow(root, value).pack(side="top", fill="both", expand=True)
1313
root.mainloop()
1414
else:
15-
print(f"\nNo note with ID {value}")
15+
print("No note with ID {}".format(value))
1616

1717

1818
class NoteModifyWindow(tk.Frame):

src/note.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import argparse
22
from textwrap import fill as tfill
33

4-
__all__ = ['argparse', 'CreateNote', 'CreateEncryptedNote', 'DecryptNote', 'ModifyNote', 'ShowNote',
5-
'ListAll', 'RemoveNote', 'RemoveAll']
4+
__all__ = ["argparse", "CreateNote", "CreateEncryptedNote", "DecryptNote", "ModifyNote", "ShowNote",
5+
"ListAll", "RemoveNote", "RemoveAll"]
66

77

88
def pretty_string(string):
@@ -19,59 +19,62 @@ def __init__(self, cod, title, text):
1919
self.date = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
2020

2121
def __str__(self):
22-
return f'''
23-
ID: {self.cod} {self.date}
22+
return '''
23+
ID: {} {}
2424
---------------------------------------------------------
25-
Title: {self.title}
25+
Title: {}
2626
27-
{self.text}
27+
{}
2828
---------------------------------------------------------
29-
'''
29+
'''.format(self.cod, self.date, self.title, self.text)
3030

3131
def shorter_str(self):
32-
return f'''
33-
ID: {self.cod} {self.date}
32+
return '''
33+
ID: {} {}
3434
---------------------------------------------------------
35-
Title: {self.title}
35+
Title: {}
3636
37-
{self.text[:77]} ...
37+
{} ...
3838
---------------------------------------------------------
39-
'''
39+
'''.format(self.cod, self.date, self.title, self.text[:77])
4040

4141

4242
class CreateNote(argparse.Action):
4343
def __call__(self, parser, namespace, values, option_string=None):
4444
import shelve
4545
with shelve.open("./data/notes") as notes_db:
46-
notes_db['total'] += 1
47-
note_cod = f'n{notes_db["total"]}'
46+
notes_db["total"] += 1
47+
note_cod = "n{}".format(notes_db["total"])
4848
notes_db[note_cod] = Note(note_cod, values[0], values[1])
49-
print(f'\n{pretty_string(str(notes_db[note_cod]))}')
49+
print("{}".format(pretty_string(str(notes_db[note_cod]))))
5050

5151

5252
class CreateEncryptedNote(argparse.Action):
5353
def __call__(self, parser, namespace, values, option_string=None):
5454
from aes_note import AESCipher, shelve
5555
cipher = AESCipher(values[2])
5656
with shelve.open("./data/notes") as notes_db:
57-
notes_db['total'] += 1
58-
note_cod = f'e{notes_db["total"]}'
59-
notes_db[note_cod] = Note(note_cod, values[0], cipher.encrypt(values[1]).decode('UTF-8'))
60-
print(f'\n{pretty_string(str(notes_db[note_cod]))}')
57+
notes_db["total"] += 1
58+
note_cod = "e{}".format(notes_db["total"])
59+
notes_db[note_cod] = Note(note_cod, values[0], cipher.encrypt(values[1]).decode("UTF-8"))
60+
print("{}".format(pretty_string(str(notes_db[note_cod]))))
6161

6262

6363
class DecryptNote(argparse.Action):
6464
def __call__(self, parser, namespace, values, option_string=None):
6565
from aes_note import AESCipher
66-
cipher = AESCipher(values[1])
67-
cipher.decrypt(values[0])
66+
if values[0][0] == 'e':
67+
cipher = AESCipher(values[1])
68+
cipher.decrypt(values[0])
69+
else:
70+
print("Encrypted notes start with 'e'")
6871

6972

7073
class ModifyNote(argparse.Action):
7174
""" Modifies an available note selected by ID """
7275
def __call__(self, parser, namespace, value, option_string=None):
7376
from mod_note import mod_note
74-
if value[0] != 'e':
77+
if value[0] != "e":
7578
mod_note(value)
7679
else:
7780
print("You can't edit an encrypted note")
@@ -85,45 +88,45 @@ def __call__(self, parser, namespace, values, option_string=None):
8588
if len(notes_db) > 1:
8689
for note_cod in values:
8790
if notes_db.pop(note_cod, -1) == -1:
88-
print(f"\nNo note with ID: {note_cod}")
91+
print("No note with ID: {}".format(note_cod))
8992
else:
90-
print(f"\nNote {note_cod} removed")
93+
print("Note {} removed".format(note_cod))
9194
else:
92-
print("\nThere are no notes available")
95+
print("There are no notes available")
9396

9497

9598
class RemoveAll(argparse.Action):
9699
""" Deletes every note created """
97100
def __call__(self, parser, namespace, values, option_string=None):
98101
import shelve
99-
with shelve.open("./data/notes", 'n') as notes_db:
100-
notes_db['total'] = 0
101-
print("\nAll notes removed")
102+
with shelve.open("./data/notes", "n") as notes_db:
103+
notes_db["total"] = 0
104+
print("All notes removed")
102105

103106

104107
class ShowNote(argparse.Action):
105108
""" Searches for a note in the database by ID, Title and string in text """
106109
def __call__(self, parser, namespace, value, option_string=None):
107110
import shelve
108-
with shelve.open('./data/notes', 'r') as notes_db:
111+
with shelve.open("./data/notes", "r") as notes_db:
109112
if len(notes_db) > 1:
110113
if value in notes_db:
111-
print(f'\n{pretty_string(str(notes_db[value]))}')
114+
print("{}".format(pretty_string(str(notes_db[value]))))
112115
else:
113-
print(f"\nThere is no note with ID {value}")
116+
print("There is no note with ID {}".format(value))
114117
else:
115-
print("\nThere are no notes available")
118+
print("There are no notes available")
116119

117120

118121
class ListAll(argparse.Action):
119122
""" Shows every available note """
120123
def __call__(self, parser, namespace, values, option_string=None):
121124
import shelve
122-
with shelve.open('./data/notes', 'r') as notes_db:
125+
with shelve.open("./data/notes", "r") as notes_db:
123126
if len(notes_db) > 1:
124-
print("\n\tPress <Enter> to show the next note")
127+
print("\tPress <Enter> to show the next note")
125128
for i in list(notes_db.values())[1:]:
126-
print(f'\n{pretty_string(i.shorter_str())}')
129+
print("{}".format(pretty_string(i.shorter_str())))
127130
input()
128131
else:
129-
print("\nThere are no notes available")
132+
print("There are no notes available")

src/nterm.py

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
from note import *
24

35

0 commit comments

Comments
 (0)