-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewer.py
53 lines (46 loc) · 1.62 KB
/
viewer.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from scanner import Doc
from scanner import KeywordsToDocMapping
from colorama import init, Fore, Back
def search_doc(arg):
arg = arg.lower()
matches = []
# for k in KeywordsToDocMapping.keys():
# if k.lower().startswith(arg):
# matches.append(KeywordsToDocMapping[k])
if len(matches) == 0:
for k in KeywordsToDocMapping.keys():
if arg in k.lower():
matches.append(KeywordsToDocMapping[k])
if len(matches) == 1:
return matches[0]
if len(matches) > 1:
print('Found multiple matches:\n')
for i in range(len(matches)):
print(Fore.GREEN + str(i) + Fore.RESET, end='')
print(": ", end='')
words = matches[i].key.split(",")
filtered_words = filter(lambda x: arg in x.lower(), words)
list_str = ', '.join(filtered_words)
print((Fore.RED + list_str + Fore.RESET).ljust(60), end=' ')
print(matches[i].desc)
choice = input('\nPlease select one: ')
return matches[int(choice)]
return None
def show_doc(arg):
init()
doc = search_doc(arg)
if doc is not None:
print(Fore.GREEN + 'Opening ' + doc.file + Fore.RESET)
os.system('open ' + doc.file)
else:
print("No doc found for: " + arg)
def list_all():
sorted_keys = sorted(KeywordsToDocMapping.keys())
i = 0
for k in sorted_keys:
i += 1
print(Fore.GREEN + str(i).rjust(2, '0') + Fore.RESET, end='')
print(": ", end='')
print((Fore.RED + k + Fore.RESET).ljust(40), end=' ')
print(KeywordsToDocMapping[k].desc)