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() if self.first_reaction: self._api.say(self.first_reaction_text)
def main(self, s): # Trim input command to get only the location loc = s.replace('weather', '').replace('in ', '').strip() # Checks country country = mapps.get_location()['country_name'] # If country is US, shows weather in Fahrenheit if country == 'United States': send_url = ("http://api.openweathermap.org/data/2.5/weather?q={0}" "&APPID=ab6ec687d641ced80cc0c935f9dd8ac9&units=imperial". format(loc)) unit = ' ºF in ' # If country is not US, shows weather in Celsius else: send_url = ( "http://api.openweathermap.org/data/2.5/weather?q={0}" "&APPID=ab6ec687d641ced80cc0c935f9dd8ac9&units=metric".format(loc)) unit = ' ºC in ' r = requests.get(send_url) j = json.loads(r.text) if 'message' in j.keys() and ('city not found' in j['message'] or 'Nothing to geocode' in j['message']): return pinpoint.main(Memory(), self, s) temperature = j['main']['temp'] description = j['weather'][0]['main'] location = j['name'] print(Fore.BLUE + "It's " + str(temperature) + unit + str(location.title()) + " (" + str(description) + ")" + Fore.RESET)
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 setUp(self): self.test = self.load_plugin(basketball) m = Memory("basketball.json") self.unable_to_test_plugin = False if m.get_data("API_KEY") is None: self.unable_to_test_plugin = True else: self.headers = {"x-rapidapi-host": "api-basketball.p.rapidapi.com", "x-rapidapi-key": m.get_data("API_KEY")}
def remove_task_from_memory(self, task_name): m = Memory("tasks.json") task_list = m.get_data("tasks_list") if task_list is None: return old_task = filter(lambda x: x["name"] != task_name, task_list) m.update_data("tasks_list", list(old_task)) m.save()
def update_tasks(self, new_tasks): m = Memory("tasks.json") if m.get_data("tasks_list") is None: m.add_data("tasks_list", new_tasks) else: m.update_data("tasks_list", new_tasks) m.save() self.tasks = new_tasks
def get_api_key(self, jarvis): m = Memory("basketball.json") if m.get_data("API_KEY") is None: user_api_key = jarvis.input("Enter Api-BasketBall.com API_KEY: ", Fore.GREEN) m.add_data("API_KEY", user_api_key) m.save() self.key = user_api_key else: self.key = m.get_data("API_KEY")
def update_api_key( self, jarvis, ): user_api_key = jarvis.input("Enter New Api-BasketBall.com API_KEY: ", Fore.GREEN) m = Memory("basketball.json") m.update_data("API_KEY", user_api_key) m.save() self.key = user_api_key
def lookup_taks_in_memory(self, task_name): m = Memory("tasks.json") task_list = m.get_data("tasks_list") if task_list is None: return False result = False for i in range(len(task_list)): if task_list[i]["name"] == task_name: result = True self.remove_task_from_memory(task_name) return result
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 lookup_taks_priority_in_memory(self, task_name, desired_priority): m = Memory("tasks.json") task_list = m.get_data("tasks_list") if task_list is None: return False result = False for i in range(len(task_list)): if task_list[i]["name"] == task_name: try: result = task_list[i]["priority"] == desired_priority except: pass self.remove_task_from_memory(task_name) return result
def test_memory(self): m = Memory("test-mem.json") m.add_data("test", "test_data") self.assertEqual(m.get_data("test"), "test_data") m.update_data("test", "test_update") self.assertEqual(m.get_data("test"), "test_update") m.del_data("test") self.assertEqual(m.get_data("test"), None) m.add_data("test1", "test_data1") m.add_data("test2", "test_data2") self.assertEqual(m.get_all(), { "test1": "test_data1", "test2": "test_data2" })
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() # what if the platform does not have any engines, travis doesn't have sapi5 acc to me try: self.speech = create_voice() 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._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 main(self, s): # Trim input command to get only the location loc = s.replace('weather', '').replace('in ', '').replace('at ', '').strip() # Checks country country = mapps.get_location()['country_name'] # If country is US, shows weather in Fahrenheit if country == 'United States': send_url = ("http://api.openweathermap.org/data/2.5/weather?q={0}" "&APPID=ab6ec687d641ced80cc0c935f9dd8ac9&units=imperial". format(loc)) unit = ' ºF in ' # If country is not US, shows weather in Celsius else: send_url = ( "http://api.openweathermap.org/data/2.5/weather?q={0}" "&APPID=ab6ec687d641ced80cc0c935f9dd8ac9&units=metric".format(loc)) unit = ' ºC in ' r = requests.get(send_url) j = json.loads(r.text) if 'message' in list(j.keys()) and ('city not found' in j['message'] or 'Nothing to geocode' in j['message']): print("Location invalid. Please be more specific") return pinpoint.main(Memory(), self, s) temperature = j['main']['temp'] description = j['weather'][0]['main'] location = j['name'] print("{COLOR}It's {TEMP}{UNIT}{LOCATION} ({DESCRIPTION}){COLOR_RESET}". format(COLOR=Fore.BLUE, COLOR_RESET=Fore.RESET, TEMP=temperature, UNIT=unit, LOCATION=location.title(), DESCRIPTION=description))
def __init__(self): self.spinner_running = False self.memory = Memory() self.scheduler = schedule.Scheduler() # Remember voice settings self.enable_voice = self.get_data('enable_voice') self.speech_rate = self.get_data('speech_rate') if not self.speech_rate: self.speech_rate = 120 self.io = DummyIO() # what if the platform does not have any engines, travis doesn't have sapi5 acc to me try: gtts_status = self.get_data('gtts_status') self.speech = create_voice(self, gtts_status, rate=self.speech_rate) except Exception as e: self.say("Voice not supported", self, Fore.RED) self.say(str(e), self, Fore.RED)
def test_memory(self): m = Memory('test-mem.json') m.add_data('test', 'test_data') self.assertEqual(str(m.get_data('test')), 'test_data')
def get_task_count(self): m = Memory("tasks.json") task_list = m.get_data("tasks_list") if task_list is None: return 0 return len(task_list)
from packages.lyrics import lyrics from packages.music import play from packages.todo import todoHandler from packages.reminder import reminder_handler, reminder_quit from packages import mapps, picshow, evaluator, forecast, plot from packages import chat, directions_to, near_me, weather_pinpoint, chuck, weatherIn, timeIn from packages.memory.memory import Memory from packages.shutdown import shutdown_system, cancel_shutdown, reboot_system from packages.systemOptions import turn_off_screen, update_system from packages.news import News from packages.clear import clear_scr from packages.file_organise import file_manage from packages.fb import fb_login MEMORY = Memory() CONNECTION_ERROR_MSG = "You are not connected to Internet" 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, first_reaction=True,
def load_tasks(self): m = Memory("tasks.json") if m.get_data("tasks_list") is None: self.tasks = [] else: self.tasks = m.get_data("tasks_list")