-
Notifications
You must be signed in to change notification settings - Fork 54
/
jarvis.py
80 lines (67 loc) · 1.93 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
import sys
import requests
import json
import apis
def square(n):
""" Square numbers
>>> square(2)
4
>>> square(3)
9
"""
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, dance]")).lower()
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)
if command == "stocks": # TODO
pass
elif command == "dance":
dance()
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[1]
arg = cliargs[2]
# TODO: Call dispatcher with args instead of prompting user.
dispatcher(command, arg)
else:
prompter()
#this is a comment
def dance():
"""Every personal assistant should know how to dance!
TODO: Add more dances
>>> dance()
left right chachacha left right chacha
left left right right dip up chachacha
"""
print("left right chachacha left right chacha\nleft left right right dip up chachacha")
return
if __name__ == "__main__":
starter(sys.argv)