-
Notifications
You must be signed in to change notification settings - Fork 38
/
app.py
95 lines (72 loc) · 3.08 KB
/
app.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
93
94
95
import glob
import importlib
import inspect
class Calc:
def __init__(self):
self.operators = {}
self.functions = {}
self.options = []
self.load()
def load(self):
modules = [f.split('\\')[1] for f in glob.glob("functions/*.py")]
for mods in modules:
self.operators[mods.split(".")[0]] = importlib.import_module(
f'functions.{mods.split(".")[0]}')
for name, func in self.operators.items():
fns = inspect.getmembers(func, inspect.isfunction)
if (len(fns) == 0):
print(f"No functions in {name}.py")
exit()
found = False
for f in fns:
if f[0] == 'calc':
self.functions[name] = f[1]
found = True
if not found:
print(f"Can't find calc function in {name}.py")
# self.functions[name] = inspect.getmembers(func,
# inspect.isfunction)[0][1]
self.options.append(name)
def build_options(self):
print("\n")
for i, option in enumerate(self.options):
print(i + 1, option)
print(len(self.options)+1, "Exit")
while(True):
try:
ui = int(input("\nWhich operations to excute > "))
break
except:
print("Enter a valid Integer")
continue
if(ui == len(self.options)+1):
return 1
elif (ui > len(self.options or ui < 0)):
print("Incorrect Option")
else:
response = self.functions[self.options[ui - 1]](should_print=True)
if response is not None:
print("\n", response)
return 0
print(
r""" /$$ /$$ /$$ /$$
| $$ /$ | $$ | $$ | $$
| $$ /$$$| $$ /$$$$$$ | $$ /$$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$ /$$$$$$ /$$$$$$
| $$/$$ $$ $$ /$$__ $$| $$ /$$_____/ /$$__ $$| $$_ $$_ $$ /$$__ $$ |_ $$_/ /$$__ $$
| $$$$_ $$$$| $$$$$$$$| $$| $$ | $$ \ $$| $$ \ $$ \ $$| $$$$$$$$ | $$ | $$ \ $$
| $$$/ \ $$$| $$_____/| $$| $$ | $$ | $$| $$ | $$ | $$| $$_____/ | $$ /$$| $$ | $$
| $$/ \ $$| $$$$$$$| $$| $$$$$$$| $$$$$$/| $$ | $$ | $$| $$$$$$$ | $$$$/| $$$$$$/
|__/ \__/ \_______/|__/ \_______/ \______/ |__/ |__/ |__/ \_______/ \___/ \______/
/$$$$$$ /$$ /$$ /$$$$$$ /$$
/$$__ $$| $$| $$ /$$__ $$ | $$
| $$ \ $$| $$| $$ | $$ \__/ /$$$$$$ | $$ /$$$$$$$
| $$$$$$$$| $$| $$ /$$$$$$| $$ |____ $$| $$ /$$_____/
| $$__ $$| $$| $$|______/| $$ /$$$$$$$| $$| $$
| $$ | $$| $$| $$ | $$ $$ /$$__ $$| $$| $$
| $$ | $$| $$| $$ | $$$$$$/| $$$$$$$| $$| $$$$$$$
|__/ |__/|__/|__/ \______/ \_______/|__/ \_______/ """)
c = Calc()
while True:
choice = c.build_options()
if(choice):
break