forked from 42cs/personal-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarvis.py
64 lines (53 loc) · 1.5 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
import sys
import requests
import json
import apis
def square(n):
""" Square numbers
>>> square(2)
4
>>> square(3)
8
"""
return n**n
def dispatcher(command, arg):
""" Does things """
if command == "weather":
print("Here's the weather forcast for "+arg)
print(apis.fetch_weather(arg))
if command == "square":
print("The square of " + arg + " is " + str(square(int(arg))))
elif command == "go away":
print("It sounds like you no longer need my assistance")
print("Very well. Goodbye!")
return
elif command == "bye":
print("Goodbye! Have a good day!")
return
# Reprompt the user.
prompter()
def prompter():
""" asks for things """
command = input("How may I help you?: [weather, square, go away, bye]")
if command == "weather":
city = input("Sure thing! What city?")
dispatcher(command, city)
if command == "square":
num = input("I love math! What number?")
dispatcher(command, num)
elif command == "stocks": # TODO
pass
else:
dispatcher(command, "")
def starter(cliargs):
# TODO: Finish up command line interface
print("DEBUG: Called with ", cliargs[1:])
print("Summoning Jarvis")
print("Good evening!")
if (len(cliargs) > 1):
command = cliargs[2]
# TODO: Call dispatcher with args instead of prompting user.
else:
prompter()
if __name__ == "__main__":
starter(sys.argv)