class CmdInterpreter(Cmd): # We use this variable at Breakpoint #1. # We use this in order to allow Jarvis say "Hi", only at the first # interaction. # This can be used to store user specific data def __init__(self, first_reaction_text, prompt, directories=[], first_reaction=True, enable_voice=False): """ This constructor contains a dictionary with Jarvis Actions (what Jarvis can do). In alphabetically order. """ Cmd.__init__(self) self.first_reaction = first_reaction self.first_reaction_text = first_reaction_text self.prompt = prompt self.enable_voice = enable_voice # Register do_quit() function to SIGINT signal (Ctrl-C) signal.signal(signal.SIGINT, self.interrupt_handler) self.memory = Memory() self.scheduler = schedule.Scheduler() self.speech = create_voice() self.fixed_responses = { "what time is it": "clock", "where am i": "pinpoint", } self._api = JarvisAPI(self) self._plugin_manager = PluginManager() for directory in directories: self._plugin_manager.add_directory(directory) self._activate_plugins() self._init_plugin_info() def _init_plugin_info(self): plugin_status_formatter = { "disabled": len(self._plugin_manager.get_disabled()), "enabled": self._plugin_manager.get_number_plugins_loaded(), "red": Fore.RED, "blue": Fore.BLUE, "reset": Fore.RESET } plugin_status = "{red}{enabled} {blue}plugins loaded" if plugin_status_formatter['disabled'] > 0: plugin_status += " {red}{disabled} {blue}plugins disabled. More information: {red}status\n" plugin_status += Fore.RESET self.first_reaction_text += plugin_status.format( **plugin_status_formatter) def _activate_plugins(self): """Generate do_XXX, help_XXX and (optionally) complete_XXX functions""" for (plugin_name, plugin) in self._plugin_manager.get_plugins().items(): self._plugin_update_completion(plugin, plugin_name) run_catch = catch_all_exceptions(plugin.run) setattr(CmdInterpreter, "do_" + plugin_name, partial(run_catch, self)) setattr(CmdInterpreter, "help_" + plugin_name, partial(self._api.say, plugin.get_doc())) plugin.init(self._api) def _plugin_update_completion(self, plugin, plugin_name): """Return True if completion is available""" completions = [i for i in plugin.complete()] if len(completions) > 0: def complete(completions): def _complete_impl(self, text, line, begidx, endidx): return [i for i in completions if i.startswith(text)] return _complete_impl setattr(CmdInterpreter, "complete_" + plugin_name, complete(completions)) def get_api(self): return self._api def close(self): """Closing Jarvis.""" print_say("Goodbye, see you later!", self, Fore.RED) self.scheduler.stop_all() exit() def completedefault(self, text, line, begidx, endidx): """Default completion""" return [i for i in self.actions if i.startswith(text)] def error(self): """Jarvis let you know if an error has occurred.""" print_say("I could not identify your command...", self, Fore.RED) def get_completions(self, command, text): """Returns a list with the completions of a command.""" dict_target = [ item for item in self.actions if type(item) == dict and command in item ][0] completions_list = dict_target[command] return [i for i in completions_list if i.startswith(text) and i != ''] def interrupt_handler(self, signal, frame): """Closes Jarvis on SIGINT signal. (Ctrl-C)""" self.close() def do_status(self, s): """Prints plugin status status""" count_enabled = self._plugin_manager.get_number_plugins_loaded() count_disabled = len(self._plugin_manager.get_disabled()) print_say( "{} Plugins enabled, {} Plugins disabled.".format( count_enabled, count_disabled), self) if "short" not in s and count_disabled > 0: print_say("", self) for disabled, reason in self._plugin_manager.get_disabled().items( ): print_say("{:<20}: {}".format(disabled, "OR ".join(reason)), self) def help_status(self): print_say("Prints info about enabled or disabled plugins", self) print_say("Use \"status short\" to omit detailed information.", self)
class CmdInterpreter(Cmd): # We use this variable at Breakpoint #1. # We use this in order to allow Jarvis say "Hi", only at the first # interaction. # This can be used to store user specific data def __init__( self, first_reaction_text, prompt, directories=[], first_reaction=True): """ This constructor contains a dictionary with Jarvis Actions (what Jarvis can do). In alphabetically order. """ Cmd.__init__(self) command = " ".join(sys.argv[1:]).strip() self.first_reaction = first_reaction self.first_reaction_text = first_reaction_text self.prompt = prompt if (command): self.first_reaction = False self.first_reaction_text = "" self.prompt = "" # Register do_quit() function to SIGINT signal (Ctrl-C) signal.signal(signal.SIGINT, self.interrupt_handler) self.memory = Memory() self.scheduler = schedule.Scheduler() self._api = JarvisAPI(self) self.say = self._api.say # Remember voice settings self.enable_voice = self._api.get_data('enable_voice') self.speech_rate = self._api.get_data('speech_rate') if not self.speech_rate: self.speech_rate = 120 # what if the platform does not have any engines, travis doesn't have sapi5 acc to me try: gtts_status = self._api.get_data('gtts_status') self.speech = create_voice( self, gtts_status, rate=self.speech_rate) except Exception as e: self.say("Voice not supported", Fore.RED) self.say(str(e), Fore.RED) self.fixed_responses = {"what time is it": "clock", "where am i": "pinpoint", } self._plugin_manager = PluginManager() for directory in directories: self._plugin_manager.add_directory(directory) if (not command): self._init_plugin_info() self._activate_plugins() self._api.say(self.first_reaction_text) def _init_plugin_info(self): plugin_status_formatter = { "disabled": len(self._plugin_manager.get_disabled()), "enabled": self._plugin_manager.get_number_plugins_loaded(), "red": Fore.RED, "blue": Fore.BLUE, "reset": Fore.RESET } plugin_status = "{red}{enabled} {blue}plugins loaded" if plugin_status_formatter['disabled'] > 0: plugin_status += " {red}{disabled} {blue}plugins disabled. More information: {red}status\n" plugin_status += Fore.RESET self.first_reaction_text += plugin_status.format( **plugin_status_formatter) def _activate_plugins(self): """Generate do_XXX, help_XXX and (optionally) complete_XXX functions""" for (plugin_name, plugin) in self._plugin_manager.get_plugins().items(): self._plugin_update_completion(plugin, plugin_name) run_catch = catch_all_exceptions(plugin.run) setattr( CmdInterpreter, "do_" + plugin_name, partial( run_catch, self)) setattr( CmdInterpreter, "help_" + plugin_name, partial( self._api.say, plugin.get_doc())) plugin.init(self._api) def _plugin_update_completion(self, plugin, plugin_name): """Return True if completion is available""" completions = [i for i in plugin.complete()] if len(completions) > 0: def complete(completions): def _complete_impl(self, text, line, begidx, endidx): return [i for i in completions if i.startswith(text)] return _complete_impl setattr( CmdInterpreter, "complete_" + plugin_name, complete(completions)) def get_api(self): return self._api def close(self): """Closing Jarvis.""" '''Stop the spinner if it is already running''' if self._api.is_spinner_running(): self._api.spinner_stop('Some error has occured') quotes = ['As always sir, a great pleasure watching you work', 'Test complete. Preparing to power down and begin diagnostics...'] self.say(random.choice(quotes), Fore.RED) self.scheduler.stop_all() sys.exit() def execute_once(self, command): self.get_api().eval(command) sys.exit() def error(self): """Jarvis let you know if an error has occurred.""" self.say("I could not identify your command...", Fore.RED) def interrupt_handler(self, signal, frame): """Closes Jarvis on SIGINT signal. (Ctrl-C)""" self.close() def do_status(self, s): """Prints plugin status status""" count_enabled = self._plugin_manager.get_number_plugins_loaded() count_disabled = len(self._plugin_manager.get_disabled()) self.say( "{} Plugins enabled, {} Plugins disabled.".format( count_enabled, count_disabled)) if "short" not in s and count_disabled > 0: self.say("") for disabled, reason in self._plugin_manager.get_disabled().items(): self.say( "{:<20}: {}".format( disabled, " OR ".join(reason))) def do_help(self, arg): if arg: Cmd.do_help(self, arg) else: self.say("") headerString = "These are valid commands for Jarvis" formatString = "Format: command ([aliases for command])" self.say(headerString) self.say(formatString, Fore.BLUE) pluginDict = self._plugin_manager.get_plugins() uniquePlugins = {} for key in pluginDict.keys(): plugin = pluginDict[key] if(plugin not in uniquePlugins.keys()): uniquePlugins[plugin.get_name()] = plugin helpOutput = [] for name in sorted(uniquePlugins.keys()): if (name == "help"): continue try: aliasString = ", ".join(uniquePlugins[name].alias()) if (aliasString != ""): pluginOutput = "* " + name + " (" + aliasString + ")" helpOutput.append(pluginOutput) else: helpOutput.append("* " + name) except AttributeError: helpOutput.append("* " + name) Cmd.columnize(self, helpOutput) def help_status(self): self.say("Prints info about enabled or disabled plugins") self.say("Use \"status short\" to omit detailed information.")
class CmdInterpreter(Cmd): # We use this variable at Breakpoint #1. # We use this in order to allow Jarvis say "Hi", only at the first # interaction. # This can be used to store user specific data def __init__(self, first_reaction_text, prompt, directories=[], first_reaction=True): """ This constructor contains a dictionary with Jarvis Actions (what Jarvis can do). In alphabetically order. """ Cmd.__init__(self) self.first_reaction = first_reaction self.first_reaction_text = first_reaction_text self.prompt = prompt # Register do_quit() function to SIGINT signal (Ctrl-C) signal.signal(signal.SIGINT, self.interrupt_handler) self.memory = Memory() self.scheduler = schedule.Scheduler() self._api = JarvisAPI(self) # Remember voice settings self.enable_voice = self._api.get_data('enable_voice') self.speech_rate = self._api.get_data('speech_rate') if not self.speech_rate: self.speech_rate = 120 # what if the platform does not have any engines, travis doesn't have sapi5 acc to me try: gtts_status = self._api.get_data('gtts_status') self.speech = create_voice(self, gtts_status, rate=self.speech_rate) except Exception as e: print_say("Voice not supported", self, Fore.RED) print_say(str(e), self, Fore.RED) self.fixed_responses = { "what time is it": "clock", "where am i": "pinpoint", } self._plugin_manager = PluginManager() for directory in directories: self._plugin_manager.add_directory(directory) self._activate_plugins() self._init_plugin_info() self._api.say(self.first_reaction_text) def _init_plugin_info(self): plugin_status_formatter = { "disabled": len(self._plugin_manager.get_disabled()), "enabled": self._plugin_manager.get_number_plugins_loaded(), "red": Fore.RED, "blue": Fore.BLUE, "reset": Fore.RESET } plugin_status = "{red}{enabled} {blue}plugins loaded" if plugin_status_formatter['disabled'] > 0: plugin_status += " {red}{disabled} {blue}plugins disabled. More information: {red}status\n" plugin_status += Fore.RESET self.first_reaction_text += plugin_status.format( **plugin_status_formatter) def _activate_plugins(self): """Generate do_XXX, help_XXX and (optionally) complete_XXX functions""" for (plugin_name, plugin) in self._plugin_manager.get_plugins().items(): self._plugin_update_completion(plugin, plugin_name) run_catch = catch_all_exceptions(plugin.run) setattr(CmdInterpreter, "do_" + plugin_name, partial(run_catch, self)) setattr(CmdInterpreter, "help_" + plugin_name, partial(self._api.say, plugin.get_doc())) plugin.init(self._api) def _plugin_update_completion(self, plugin, plugin_name): """Return True if completion is available""" completions = [i for i in plugin.complete()] if len(completions) > 0: def complete(completions): def _complete_impl(self, text, line, begidx, endidx): return [i for i in completions if i.startswith(text)] return _complete_impl setattr(CmdInterpreter, "complete_" + plugin_name, complete(completions)) def get_api(self): return self._api def close(self): """Closing Jarvis.""" '''Stop the spinner if it is already running''' if self._api.is_spinner_running(): self._api.spinner_stop('Some error has occured') print_say("Goodbye, see you later!", self, Fore.RED) self.scheduler.stop_all() sys.exit() def execute_once(self, command): self.get_api().eval(command) self.close() def error(self): """Jarvis let you know if an error has occurred.""" print_say("I could not identify your command...", self, Fore.RED) def interrupt_handler(self, signal, frame): """Closes Jarvis on SIGINT signal. (Ctrl-C)""" self.close() def do_status(self, s): """Prints plugin status status""" count_enabled = self._plugin_manager.get_number_plugins_loaded() count_disabled = len(self._plugin_manager.get_disabled()) print_say( "{} Plugins enabled, {} Plugins disabled.".format( count_enabled, count_disabled), self) if "short" not in s and count_disabled > 0: print_say("", self) for disabled, reason in self._plugin_manager.get_disabled().items( ): print_say("{:<20}: {}".format(disabled, " OR ".join(reason)), self) def help_status(self): print_say("Prints info about enabled or disabled plugins", self) print_say("Use \"status short\" to omit detailed information.", self)
class CmdInterpreter(Cmd): # We use this variable at Breakpoint #1. # We use this in order to allow Jarvis say "Hi", only at the first # interaction. # This can be used to store user specific data def __init__(self, first_reaction_text, prompt, directories=[], first_reaction=True, enable_voice=False): """ This constructor contains a dictionary with Jarvis Actions (what Jarvis can do). In alphabetically order. """ Cmd.__init__(self) self.first_reaction = first_reaction self.first_reaction_text = first_reaction_text self.prompt = prompt self.enable_voice = enable_voice # Register do_quit() function to SIGINT signal (Ctrl-C) signal.signal(signal.SIGINT, self.interrupt_handler) self.memory = Memory() self.scheduler = schedule.Scheduler() self.speech = create_voice() self.actions = [ { "check": ("ram", "weather", "time", "forecast") }, "directions", "help", "how_are_you", "near", "pinpoint", "umbrella", { "update": ("location", "system") }, "weather", ] self.fixed_responses = { "what time is it": "clock", "where am i": "pinpoint", "how are you": "how_are_you" } self._api = JarvisAPI(self) self._plugin_manager = PluginManager() for directory in directories: self._plugin_manager.add_directory(directory) self._activate_plugins() def _activate_plugins(self): """Generate do_XXX, help_XXX and (optionally) complete_XXX functions""" for (plugin_name, plugin) in self._plugin_manager.get_all().items(): completions = self._plugin_update_action(plugin, plugin_name) if completions is not None: def complete(completions): def _complete_impl(self, text, line, begidx, endidx): return [i for i in completions if i.startswith(text)] return _complete_impl setattr(CmdInterpreter, "complete_" + plugin_name, complete(completions)) setattr(CmdInterpreter, "do_" + plugin_name, partial(plugin.run, self._api)) setattr(CmdInterpreter, "help_" + plugin_name, partial(self._api.say, plugin.get_doc())) if hasattr(plugin.__class__, "init") and callable( getattr(plugin.__class__, "init")): plugin.init(self._api) def _plugin_update_action(self, plugin, plugin_name): """Return True if completion is available""" complete = plugin.complete() if complete is not None: # add plugin with completion # Dictionary: # { plugin_name : list of completions } complete = [x for x in complete] self.actions.append({plugin_name: complete}) return complete else: # add plugin without completion # plugin name only self.actions.append(plugin_name) return None def close(self): """Closing Jarvis.""" print_say("Goodbye, see you later!", self, Fore.RED) self.scheduler.stop_all() exit() def completedefault(self, text, line, begidx, endidx): """Default completion""" return [i for i in self.actions if i.startswith(text)] def error(self): """Jarvis let you know if an error has occurred.""" print_say("I could not identify your command...", self, Fore.RED) def get_completions(self, command, text): """Returns a list with the completions of a command.""" dict_target = [ item for item in self.actions if type(item) == dict and command in item ][0] completions_list = dict_target[command] return [i for i in completions_list if i.startswith(text) and i != ''] def interrupt_handler(self, signal, frame): """Closes Jarvis on SIGINT signal. (Ctrl-C)""" self.close() def do_calculate(self, s): """Jarvis will get your calculations done!""" tempt = s.replace(" ", "") if len(tempt) > 1: evaluator.calc(tempt, self) else: print_say("Error: Not in correct format", self, Fore.RED) def help_calculate(self): """Print help about calculate command.""" print_say("Jarvis will get your calculations done!", self) print_say("-- Example:", self) print_say("\tcalculate 3 + 5", self) def do_check(self, s): """Checks your system's RAM stats.""" # if s == "ram": if "ram" in s: system("free -lm") # if s == "time" elif "time" in s: timeIn.main(self, s) elif "forecast" in s: forecast.main(self, s) # if s == "weather" elif "weather" in s: try: weatherIn.main(self, s) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_check(self): """Prints check command help.""" print_say("ram: checks your system's RAM stats.", self) print_say("time: checks the current time in any part of the globe.", self) print_say( "weather in *: checks the current weather in any part of the globe.", self) print_say("forecast: checks the weather forecast for the next 7 days.", self) print_say("-- Examples:", self) print_say("\tcheck ram", self) print_say("\tcheck time in Manchester (UK)", self) print_say("\tcheck weather in Canada", self) print_say("\tcheck forecast", self) print_say("\tcheck forecast in Madrid", self) # add here more prints def complete_check(self, text, line, begidx, endidx): """Completions for check command""" return self.get_completions("check", text) def do_directions(self, data): """Get directions about a destination you are interested to.""" try: directions_to.main(data) except ValueError: print("Please enter destination") except ConnectionError: print(CONNECTION_ERROR_MSG) def help_directions(self): """Prints help about directions command""" print_say("Get directions about a destination you are interested to.", self) print_say("-- Example:", self) print_say("\tdirections to the Eiffel Tower", self) def do_how_are_you(self, s): """Jarvis will inform you about his status.""" print_say("I am fine, How about you?", self, Fore.BLUE) def help_how_are_you(self): """Print info about how_are_you command""" print_say("Jarvis will inform you about his status.", self) def do_near(self, data): """Jarvis can find what is near you!""" near_me.main(data) def help_near(self): """Print help about near command.""" print_say("Jarvis can find what is near you!", self) print_say("-- Examples:", self) print_say("\trestaurants near me", self) print_say("\tmuseums near the eiffel tower", self) def do_pinpoint(self, s): """Jarvis will pinpoint your location.""" try: mapps.locate_me() except ConnectionError: print(CONNECTION_ERROR_MSG) def help_pinpoint(self): """Print help about pinpoint command.""" print_say("Jarvis will pinpoint your location.", self) def do_umbrella(self, s): """If you're leaving your place, Jarvis will inform you if you might need an umbrella or not""" s = 'umbrella' try: weather_pinpoint.main(self.memory, self, s) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_umbrella(self): """Print info about umbrella command.""" print_say( "If you're leaving your place, Jarvis will inform you if you might need an umbrella or not.", self, Fore.BLUE) def do_update(self, s): """Updates location or system.""" if "location" in s: location = self.memory.get_data('city') loc_str = str(location) print_say("Your current location is set to " + loc_str, self) print_say("What is your new location?", self) i = input() self.memory.update_data('city', i) self.memory.save() elif "system" in s: update_system() def help_update(self): """Prints help about update command""" print_say("location: Updates location.", self) print_say("system: Updates system.", self) def complete_update(self, text, line, begidx, endidx): """Completions for update command""" return self.get_completions("update", text) def do_weather(self, s): """Get information about today's weather.""" try: word = s.strip() if (len(word) > 1): weatherIn.main(self, s) else: weather_pinpoint.main(self.memory, self, s) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_weather(self): """Prints help about weather command.""" print_say( "Get information about today's weather in your current location.", self)
class CmdInterpreter(Cmd): # We use this variable at Breakpoint #1. # We use this in order to allow Jarvis say "Hi", only at the first # interaction. # This can be used to store user specific data def __init__(self, first_reaction_text, prompt, directories=[], first_reaction=True, enable_voice=False): """ This constructor contains a dictionary with Jarvis Actions (what Jarvis can do). In alphabetically order. """ Cmd.__init__(self) self.first_reaction = first_reaction self.first_reaction_text = first_reaction_text self.prompt = prompt self.enable_voice = enable_voice # Register do_quit() function to SIGINT signal (Ctrl-C) signal.signal(signal.SIGINT, self.interrupt_handler) self.actions = [ "ask", { "check": ("ram", "weather", "time", "forecast") }, "clear", "cricket", { "decrease": ("volume", ) }, "dictionary", "directions", { "disable": ("sound", ) }, { "display": ("pics", ) }, { "enable": ("sound", ) }, "file_organise", "fb", "hackathon", "help", { "hotspot": ("start", "stop") }, "how_are_you", "imgur", "lyrics", "match", { "movie": ( "cast", "director", "plot", "producer", "rating", "year", ) }, "movies", "music", "near", "news", { "open": ("camera", ) }, "pinpoint", "play", "quote", "currencyconv", "remind", "say", "tempconv", "todo", "translate", { "twitter": ("login", "tweet") }, "umbrella", { "update": ("location", "system") }, "weather", ] self.fixed_responses = { "what time is it": "clock", "where am i": "pinpoint", "how are you": "how_are_you" } self.speech = voice.Voice() self._api = JarvisAPI(self) self._plugin_manager = PluginManager() for directory in directories: self._plugin_manager.add_directory(directory) self._activate_plugins() def _activate_plugins(self): """Generate do_XXX, help_XXX and (optionally) complete_XXX functions""" for (plugin_name, plugin) in self._plugin_manager.get_all().items(): if self._plugin_update_action(plugin, plugin_name): setattr(CmdInterpreter, "complete_" + plugin_name, partial(self.get_completions, plugin_name)) setattr(CmdInterpreter, "do_" + plugin_name, partial(plugin.run, self._api)) setattr(CmdInterpreter, "help_" + plugin_name, partial(self._api.say, plugin.get_doc())) def _plugin_update_action(self, plugin, plugin_name): """Return True if completion is available""" complete = plugin.complete() if complete is not None: # add plugin with completion # Dictionary: # { plugin_name : list of completions } complete = [x for x in complete] self.actions.append({plugin_name: complete}) return True else: # add plugin without completion # plugin name only self.actions.append(plugin_name) return False def close(self): """Closing Jarvis.""" reminder_quit() print_say("Goodbye, see you later!", self, Fore.RED) exit() def completedefault(self, text, line, begidx, endidx): """Default completion""" return [i for i in self.actions if i.startswith(text)] def error(self): """Jarvis let you know if an error has occurred.""" print_say("I could not identify your command...", self, Fore.RED) def get_completions(self, command, text): """Returns a list with the completions of a command.""" dict_target = (item for item in self.actions if type(item) == dict and command in item ).next() # next() will return the first match completions_list = dict_target[command] return [i for i in completions_list if i.startswith(text)] def interrupt_handler(self, signal, frame): """Closes Jarvis on SIGINT signal. (Ctrl-C)""" self.close() def do_ask(self, s): """Start chating with Jarvis""" if six.PY2: chat.main(self) else: print_say("Feature currently not available in Python 3", self, Fore.RED) def help_ask(self): """Prints help about ask command.""" print_say("Start chating with Jarvis", self) def do_calculate(self, s): """Jarvis will get your calculations done!""" tempt = s.replace(" ", "") if len(tempt) > 1: evaluator.calc(tempt, self) else: print_say("Error: Not in correct format", self, Fore.RED) def help_calculate(self): """Print help about calculate command.""" print_say("Jarvis will get your calculations done!", self) print_say("-- Example:", self) print_say("\tcalculate 3 + 5", self) def do_check(self, s): """Checks your system's RAM stats.""" # if s == "ram": if "ram" in s: system("free -lm") # if s == "time" elif "time" in s: timeIn.main(self, s) elif "forecast" in s: forecast.main(self, s) # if s == "weather" elif "weather" in s: try: weatherIn.main(self, s) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_check(self): """Prints check command help.""" print_say("ram: checks your system's RAM stats.", self) print_say("time: checks the current time in any part of the globe.", self) print_say( "weather in *: checks the current weather in any part of the globe.", self) print_say("forecast: checks the weather forecast for the next 7 days.", self) print_say("-- Examples:", self) print_say("\tcheck ram", self) print_say("\tcheck time in Manchester (UK)", self) print_say("\tcheck weather in Canada", self) print_say("\tcheck forecast", self) print_say("\tcheck forecast in Madrid", self) # add here more prints def complete_check(self, text, line, begidx, endidx): """Completions for check command""" return self.get_completions("check", text) def do_clear(self, s=None): """Clear terminal screen. """ clear_scr() def help_clear(self): """Help:Clear terminal screen""" print_say("Clears terminal", self) def do_cricket(self, s=None): """Jarvis will show current matches and their score for you""" try: score(self) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_cricket(self): """cricket package for Jarvis""" print_say("Enter cricket and follow the instructions", self) def complete_decrease(self, text, line, begidx, endidx): """Completions for decrease command""" return self.get_completions("decrease", text) def do_dictionary(self, s): """Returns meaning, synonym and antonym of any english word""" dictionary(self) def help_dictionary(self): """Print help about dictionary feature""" print_say("Get meaning, synonym and antonym of any word", self) def do_directions(self, data): """Get directions about a destination you are interested to.""" try: directions_to.main(data) except ValueError: print("Please enter destination") except ConnectionError: print(CONNECTION_ERROR_MSG) def help_directions(self): """Prints help about directions command""" print_say("Get directions about a destination you are interested to.", self) print_say("-- Example:", self) print_say("\tdirections to the Eiffel Tower", self) def do_disable(self, s): """Deny Jarvis to use his voice.""" if "sound" in s: self.enable_voice = False def help_disable(self): """Displays help about disable command""" print_say("sound: Deny Jarvis his voice.", self) def complete_disable(self, text, line, begidx, endidx): """Completions for check command""" return self.get_completions("disable", text) def do_display(self, s): """Displays photos.""" if "pics" in s: s = s.replace("pics", "").strip() picshow.showpics(s) def help_display(self): """Prints help about display command""" print_say("Displays photos of the topic you choose.", self) print_say("-- Example:", self) print_say("\tdisplay pics of castles", self) def complete_display(self, text, line, begidx, endidx): """Completions for display command""" return self.get_completions("display", text) def do_enable(self, s): """Let Jarvis use his voice.""" if "sound" in s: self.enable_voice = True def help_enable(self): """Displays help about enable command""" print_say("sound: Let Jarvis use his voice.", self) def complete_enable(self, text, line, begidx, endidx): """Completions for enable command""" return self.get_completions("enable", text) def do_file_organise(self, s=None): """Jarvis will organise the given folder and group the files""" file_manage(self) def help_file_organise(self): """Help for file organise""" print_say("Type file_organise and follow instructions", self) print_say("It organises selected folder based on extension", self) def do_fb(self, s=None): """Jarvis will login into your facebook account either by prompting id-password or by using previously saved""" try: fb_login(self) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_fb(self): """Help for fb""" print_say("type fb and follow instructions", self) def do_hackathon(self, s=None): """Find upcoming hackathons from hackerearth""" find_hackathon(self) def help_hackathon(self): """Prints help about hackathon command.""" print_say("Find upcoming hackathons from hackerearth", self) @unsupported(platform=MACOS) def do_hotspot(self, s): """Jarvis will set up your own hotspot.""" if "start" in s: system("sudo ap-hotspot start") elif "stop" in s: system("sudo ap-hotspot stop") @unsupported(platform=MACOS) def help_hotspot(self): """Print help about hotspot commando.""" print_say("start: Jarvis will set up your own hotspot.", self) print_say("stop: Jarvis will stop your hotspot.", self) def complete_hotspot(self, text, line, begidx, endidx): """Completions for enable command""" return self.get_completions("hotspot", text) def do_how_are_you(self, s): """Jarvis will inform you about his status.""" print_say("I am fine, How about you?", self, Fore.BLUE) def help_how_are_you(self): """Print info about how_are_you command""" print_say("Jarvis will inform you about his status.", self) def do_lyrics(self, s): # TODO: maybe add option to download lyrics not just print them there lyr = lyrics() response = lyr.find(s) print_say(response, self) def help_lyrics(self): """explains how lyrics work""" print_say("finds lyrics\n", self) print_say("the format is song,artist\n", self) print_say("song and artist are separated by a - \n", self) print_say("-- Example:", self) print_say("\tlyrics wonderful tonight-eric clapton", self) def do_match(self, s): """Matches patterns in a string by using regex.""" file_name = input(Fore.RED + "Enter file name?:\n" + Fore.RESET) pattern = input(Fore.GREEN + "Enter string:\n" + Fore.RESET) file_name = file_name.strip() if file_name == "": print("Invalid Filename") else: system("grep '" + pattern + "' " + file_name) def help_match(self): """Prints help about match command""" print_say("Matches a string pattern in a file using regex.", self) print_say("Type \"match\" and you'll be prompted.", self) def do_movie(self, s): """Jarvis will get movie details for you""" k = s.split(' ', 1) if k[0] == "cast": data = movie.cast(k[1]) for d in data: print_say(d['name'], self) elif k[0] == "director": data = movie.director(k[1]) for d in data: print_say(d['name'], self) elif k[0] == "plot": data = movie.plot(k[1]) print_say(data, self) elif k[0] == "producer": data = movie.producer(k[1]) for d in data: print_say(d['name'], self) elif k[0] == "rating": data = movie.rating(k[1]) print_say(str(data), self) elif k[0] == "year": data = movie.year(k[1]) print_say(str(data), self) def help_movie(self): """Print help about movie command.""" print_say("Jarvis - movie command", self) print_say("List of commands:", self) print_say("movie cast", self) print_say("movie director", self) print_say("movie plot", self) print_say("movie producer", self) print_say("movie rating", self) print_say("movie year", self) @unsupported(platform=MACOS) def do_movies(self, s): """Jarvis will find a good movie for you.""" movie_name = input(Fore.RED + "What do you want to watch?\n" + Fore.RESET) system("ims " + movie_name) @unsupported(platform=MACOS) def help_movies(self): """Print help about movies command.""" print_say("Jarvis will find a good movie for you", self) @unsupported(platform=MACOS) def do_music(self, s): """Jarvis will find you a good song to relax!""" play(s) @unsupported(platform=MACOS) def help_music(self): """Print help about music command.""" print_say("Jarvis will find you the song you want", self) print_say("-- Example:", self) print_say("\tmusic wonderful tonight", self) def do_near(self, data): """Jarvis can find what is near you!""" near_me.main(data) def help_near(self): """Print help about near command.""" print_say("Jarvis can find what is near you!", self) print_say("-- Examples:", self) print_say("\trestaurants near me", self) print_say("\tmuseums near the eiffel tower", self) def do_news(self, s): """Time to get an update about the local news.""" if s == "quick": try: n = News() n.quick_news() except: print_say("I couldn't find news", self, Fore.RED) else: try: n = News() n.news() except: print_say("I couldn't find news", self, Fore.RED) def help_news(self): """Print help about news command.""" print_say("Time to get an update about the local news.", self) print_say( "Type \"news\" to choose your source or \"news quick\" for some headlines.", self) def do_open(self, s): """Jarvis will open the camera for you.""" if "camera" in s: if IS_MACOS: system('open /Applications/Photo\ Booth.app') else: print_say("Opening cheese.......", self, Fore.RED) system("cheese") def help_open(self): """Print help about open command.""" print_say("camera: Jarvis will open the camera for you.", self) def complete_open(self, text, line, begidx, endidx): """Completions for open command""" return self.get_completions("open", text) def do_pinpoint(self, s): """Jarvis will pinpoint your location.""" try: mapps.locate_me() except ConnectionError: print(CONNECTION_ERROR_MSG) def help_pinpoint(self): """Print help about pinpoint command.""" print_say("Jarvis will pinpoint your location.", self) @unsupported(platform=MACOS) def do_play(self, s): """Jarvis will find you a good song to relax!""" play(s) @unsupported(platform=MACOS) def help_play(self): """Print help about play command.""" print_say("Jarvis will find you the song you want", self) print_say("-- Example:", self) print_say("\tplay eye of the tiger", self) def do_quote(self, s=None): """Show quote of the day or quotes based on a gven word""" show_quote(self) def help_quote(self): """Help for quote""" print_say( "quote prints quote for the day for you" + "or quotes based on a given keyword", self) def do_currencyconv(self, s=None): """Show the convert from a currency to another""" currencies = find_currencies() amount = get_float('Enter an amount: ') from_currency = get_currency('Enter from which currency: ', currencies) to_currency = get_currency('Enter to which currency: ', currencies) currencyconv(self, amount, from_currency, to_currency) def help_currencyconv(self): """Help for currencyConverter""" print_say("Convert an amount of money from a currency to another.", self) print_say( "-- Type currencyconv, press enter and follow the" + "instructions!", self) def do_remind(self, data): """Handles reminders""" reminder_handler(data) def help_remind(self): """Print help about remind command.""" print_say("Handles reminders", self) print_say("add: adds a reminder", self) print_say("remove: removes a reminder", self) print_say("list: lists all reminders", self) print_say("clear: clears all reminders", self) print_say("-- Examples:", self) print_say("\tremind add 14:25 buy tomatoes", self) print_say("\tremind add 14:26 buy potatoes too", self) print_say("\tremind remove buy potatoes too", self) print_say("\tremind list", self) print_say("\tremind clear", self) def do_say(self, s): """Reads what is typed.""" if not s: print_say("What should I say?", self) else: voice_state = self.enable_voice self.enable_voice = True self.speech.text_to_speech(s) self.enable_voice = voice_state def help_say(self): """Prints help text from say command.""" print_say("Reads what is typed.") def do_tempconv(self, s): """Convert temperature from Celsius to Fahrenheit or vice versa""" temp_main(self, s) def help_tempconv(self): """Print help information for tempconv command.""" print_say( "Convert temperature from Fahrenheit to Celsius and vice versa", self) print_say("Examples: 32f, 18C, -20F, -8c, 105.4F, -10.21C", self) def do_todo(self, data): """Create your personal TODO list!""" todoHandler(data) def help_todo(self): """Print help about todo command.""" print_say("Create your personal TODO list!", self) print("Supported Commands: todo <command>") print( "\tadd [<index>] <todo - comment>, add comment <index> <comment>, add due <index> <time>" ) print("\tremove <index>") print("\tcomplete <index> [<completion>]") print("\tpriority <index> [<level>]") print("\tlist") def do_translate(self, s): """Translates text from one language (source) to another(destination)""" translate.main(self) def help_translate(self): """Print help for translate function""" print_say("translates from one language to another.", self) def do_twitter(self, s): """Jarvis will login into your facebook account either by prompting id-password or by using previously saved""" if "login" in s: try: driver = twitter_login(self) twitter_end(self, driver) except ConnectionError: print(CONNECTION_ERROR_MSG) elif "tweet" in s: try: driver = twitter_tweet(self) twitter_end(self, driver) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_twitter(self): """help for twitter""" print_say("enter twitter and follow the instructions", self) def do_umbrella(self, s): """If you're leaving your place, Jarvis will inform you if you might need an umbrella or not""" s = 'umbrella' try: weather_pinpoint.main(MEMORY, self, s) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_umbrella(self): """Print info about umbrella command.""" print_say( "If you're leaving your place, Jarvis will inform you if you might need an umbrella or not.", self, Fore.BLUE) def do_update(self, s): """Updates location or system.""" if "location" in s: location = MEMORY.get_data('city') loc_str = str(location) print_say("Your current location is set to " + loc_str, self) print_say("What is your new location?", self) i = input() MEMORY.update_data('city', i) MEMORY.save() elif "system" in s: update_system() def help_update(self): """Prints help about update command""" print_say("location: Updates location.", self) print_say("system: Updates system.", self) def complete_update(self, text, line, begidx, endidx): """Completions for update command""" return self.get_completions("update", text) def do_weather(self, s): """Get information about today's weather.""" try: weather_pinpoint.main(MEMORY, self, s) except ConnectionError: print(CONNECTION_ERROR_MSG) def help_weather(self): """Prints help about weather command.""" print_say( "Get information about today's weather in your current location.", self) def do_imgur(self, s): """Uploads image to imgur""" imgur(self, s) def help_imgur(self): """Prints help about imgur command""" print_say("Uploads an image to imgur", self) print_say("use imgur <image>", self)