/
Jarvis.py
112 lines (98 loc) · 9.09 KB
/
Jarvis.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from JarvisYacc import parser
import JarvisTools as JT
from JarvisYacc import find_bot
from JarvisYacc import thebots
import sys
def print_message():
print("Welcome to JARVIS, where you create your own personal assistant!\n")
print(''' @(((((((((((((((((((((((((((((((((@
@(((((((((((((((((((((((((((((((((@
@(((((((((((((((((((((((((((((((((@
@(((((((((((((((((((((((((((((((((@
@(((((((((((((((((((((((((((((((((@
@(((((((((((((((((((((((((((((((((@
@(((((((((((((((((((((((((((((((((@@%
#@(((((@(((((((((((((((((((((((((((((((((@((((((((#@
@(((((((((@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,&((((((((((((@
@((((((((((@,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,@((((((((((((((
#(((((((((((((((((((((((((((((((((((((((((((((((((((((((((@
@%(((((((((((((((((((((((((((((((((((((((((((((((((((@
(((@@#(((((((((((((((((((((((((((((((((((((((@@(((&
@(((((((((((((((%@@@@@@@@@@@@@@@@@@@@&(((((((((((((((@
@((((((((((((((((((((((((((((((((((((((((((((((((((((((@
@((((((((((((((((((((((((((((((((((((((((((((((((((((((((@
@(((((((((%(((((((((((((((@.......@(((((((((((@.......@((((((((((((((@((((((((
((((((((((#((((((((((((((..%(((((...(((((((((..@((((&...((((((((((((((((((((((
(((((((((@((((((((((((((@..(((((((..@(((((((/.*(((((((..@(((((((((((((@(((((((
@..@ (((((((((@((((((((((((((%..(((((((..%(((((((..*(((((((..@(((((((((((((&((((((( @..@
@..%%%%%%%%%%%(((((((((#((((((((((((((@...#(((@...@(((((((@../((((@...#(((((((((((((((((((((%%%%%%%%%%%%..@
@..@ (((((((((((((((((((((((((&.........#(((((((((@.........#(((((((((((((((((((((( @..@
(((((((((#((((((((((((((((((@@/@@(@* @@(@ @((@%*&@(((((((((((((((((((((((((
(((((((((@((((((((((((((((((((((@ @(((((((((((((((((((((%(((((((
(((((((((@((((((((((((((((((((@ @(((((((((((((((((((@(((((((
(((((((((((((((((((((((@((((@ @@%@(((((((((((((@@@@@@@@
%((((((((((((((# @(((((((((((((((@
@((((((((((((((((@%,,%@@@@@@((@* ,@%,%@#(((((((((((((((((@
@((((((((((((((((((((((((((((((((((((((((((((((((((((((&
@((((((((((((((((((((((((((((((((((((((((((((((((((((@
#((((((((((@.....@.....@.....%.....@.....((((((((((@
@((((((((@.....@.....@.....%.....@.....((((((((&
&((((((@.....@.....@.....%.....@.....(((((((
@((((@.....@.....@.....%.....@.....((((@
*&(@.....@.....@.....%.....@.....(#&
@....@.....@.....%.....@...@
,, @@....@.....%...&@ %@@%%,
&((((((((((((((@ @(((((((((((((((
%(((((((((((((((((@ @(((((((((((((((((@
@((((((((((((((((((@(((((((((((@(((((((((((((((((((
(((((((((((((((((@(@(((((((((((@%((((((((((((((((((@
%(((((((((((((((((((@(((((((((((@(((((((((((((((((((@
.(((((((((((((((((((@(((((((((((@(((((((((((((((((((@
#((((((((((((((((((@(((((((((((@(((((((((((((((((((
@(((((((((((((((((#*,,,,,,,,,,, @(((((((((((((((((@
((((((((((((((@ &@(((((((((((((
''')
print("To run a command, please specify the bot you want to call followed by a comma")
print("and then type the command you want to run.\n")
print("If you want to see the available commands that each bot has, just type the bot's")
print("name without a comma.")
print("The system's current available bots are:\n")
for bot in thebots:
print("-" + bot.name)
print("\n")
def run_program(name):
code = ""
try:
with open(name + '.jvs', 'r') as test:
for l in test:
code = code + l
# print(code)
parser.parse(code)
except FileNotFoundError:
print("File "+name+".jvs doesn't exist")
sys.exit()
except:
sys.exit()
print_message()
l=""
while not(l.lower() == "quit"):
l = str(input(">> "))
if l != "quit":
name_until = l.find(',')
if name_until != -1:
bot_name = l[:name_until]
bot = find_bot(bot_name)
if not bot:
print("Bot " + bot_name + " was not created.")
else:
r = bot.handleInput(l[name_until+2:])
else:
bot = find_bot(l)
if not bot:
print("Bot " + l + " was not created.")
else:
for rule in bot.rules.keys():
print (rule)
if __name__ == "__main__":
name = sys.argv[1]
run_program(name)