-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnepdict.py
92 lines (74 loc) · 2.66 KB
/
nepdict.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import signal
import re
# when the set time is up, it display a output and exits the programs
def handler(signum, frame):
print("\n")
print(color.BOLD + "Times UP! See you next time.")
print("Thank you for using Nepdict." + color.END)
exit(0)
# adds color to the output
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
# Install signal handler
signal.signal(signal.SIGALRM, handler)
# Set alarm for 1 minutes
signal.alarm(60)
# General Information to the end user
print("\n")
print(
color.DARKCYAN + "The information provided here doesn't claim to be complete, accurate or reliable. However, We have tried our best for correctness and completeness with our resources and capability. You will be at your own risk and liable for any direct, indirect or consequential damage cause by the use of this content." + color.END + color.RED + " If you found any error or problem with the meaning or couldnot find words looking for, please kindly email the details to '[email protected]'." + color.END)
print("\n")
def fillUpDict(nepdict):
'''
:param nepdict: is a dict for database storage
:return:
'''
s = '(.*\s),\s(.*)\s,(.*)'
prg = re.compile(s)
with open('./database/data.csv') as fp:
for line in fp:
# print(line)
m = prg.match(line)
# print(m)
# group2 is the noun/verb/adj, group3 is the meaning
s = m.group(2).strip() , m.group(3).strip()
nepdict[m.group(1).strip()]= s
def runScript():
'''
runs the script
:return:
'''
while True:
search = input("What are you looking for : ")
search = search.strip().lower()
looking = nepdict.get(search)
if looking is not None:
print(
"Meaning of" + color.BLUE + search + color.END + " is: "
+ color.PURPLE + "(" + looking[0] + ")" + looking[1] + color.END)
else:
print(
"There are no results for: " + "'" + color.RED + search + color.END + "'" + ", but we are adding new words daily.")
print(color.BOLD + color.CYAN + "\n")
cont = input("Do you want to continue? (y/n) : " + color.END)
if cont == "y":
continue
else:
print(color.BOLD + "Thank you for using Nepdict." + color.END)
break
if __name__ == '__main__':
# Word & Meaning Databases
nepdict = dict()
fillUpDict(nepdict)
runScript()