-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (31 loc) · 815 Bytes
/
main.py
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
#!/bin/python3
from pprint import pprint
from termcolor import cprint
from os import chdir, listdir, rename, system
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
def modify():
chdir('stories')
for x in listdir():
rename(x, x.title()[:-4] + '.txt')
def show(title):
system('clear')
with open(title + '.txt') as file:
cprint(title, 'red', attrs=['bold'])
print(file.read())
file.close()
def main():
chdir('stories')
arr = sorted([x[:-4] for x in listdir()])
comp = WordCompleter(arr, ignore_case=True, match_middle=True)
while True:
try:
s = prompt('>> ', completer=comp)
try:
show(s)
except FileNotFoundError:
cprint('История Не Найдена', 'red')
except KeyboardInterrupt:
break
if __name__ == '__main__':
main()