def execute(self, operand): self.debug("Reminding " + operand) cmd = "play " + self.get_resource_path('ding.mp3') system.call_silently(cmd, sync=True) speech.say("Sir, " + operand, sync=False) response = inputs.get_string_timeout(self.get_config('TIME_OUT')) if not response: self.reschedule(operand) if meaning.means(response, "okay"): return elif meaning.means(response, "not_okay"): self.debug("Reminding again in one day.") reschedule_str = inputs.get_string("Schedule again in: ") try: delta = parse.time_delta(reschedule_str) except exceptions.PAULAParseException as e: outputs.print_error(str(e.__class__)) # fix bash issues again operand = operand.replace("\"", "\\\"") operand = operand.replace("\'", "\\\'") schedule.schedule_event_with_delta(delta, "paula_remind", operand) else: self.reschedule(operand)
def execute(self, operand): if operand.strip() == "": outputs.print_error("Nothing to remind you of.") return if not "in" in operand: #TODO too hard coded? self.debug("no \"in\", Exiting.") return operand_parts = operand.split(" in ") content = " in ".join(operand_parts[:-1]) moment = operand_parts[-1] if not " " in moment: self.debug("No space in moment, Exiting.") return try: delta = parse.time_delta(moment) except exceptions.PAULAParseException as e: outputs.print_error("An error occured while parsing the time delta.", error=e) return treated_content = self.treat_content(content) schedule.schedule_event_with_delta(delta, "paula_remind", treated_content) speech.say_random_from_file(self.get_resource_path('confirmation.paula_says'))
def __init__(self, date, command, operand): if not isinstance(date, datetime.datetime): outputs.print_error("class mismatch: date argument is not a datetime object.") exit(1) self.date = date self.command = command self.operand = operand self.file = os.path.join(conf.SCHEDULING_DIR, str(self.date)) if conf.DEBUG: outputs.print_debug("Constructed event " + str(self))
def load_module(self, script_name): try: module_name = "paula.scripts" + self.parent + "." + script_name + "." + script_name + "_script" debug("Importing module: " + module_name) module = importlib.import_module(module_name) except ImportError: outputs.print_error( "The " + script_name + " script is missing or does not exist. Either that or some import fails inside the script.") return return module
def get_current_album(): if not os.path.exists(conf.SONG_INFO): return None try: with open(conf.SONG_INFO, 'r') as f: lines = f.readlines() return lines[1] except IOError: outputs.print_error('Could not open paula_song.info')
def prompt_for_input_boolean(prompt=""): """ Prompt the user for a boolean, optionally given a specific prompt. @param prompt: A given prompt string @return: A boolean of the user's choice. """ while True: answer = string.prompt_for_input_string(prompt=prompt) if meaning.means(answer, "yes"): return True elif meaning.means(answer, "no"): return False else: outputs.print_error("Not a Boolean value.")
def prompt_for_input_int(prompt=""): """ Prompt for an integer, keep asking for new input untill a valid integer is provided. @param prompt: What should appear as the question. eg: prompt="why: " results in the following. why: <input text here> @return: """ value = None while not value: answer = input(prompt) try: value = int(answer) return value except ValueError: outputs.print_error("Not an Integer") value = None
def get_training_scheme(self, exercise, week, day, difficulty_level): """ Get's the training scheme for a given exercise, week, day and difficulty level @param exercise: A string representing an exercise. @param week: An integer representing a week in the training. @param day: An integer representing the day of the week. @param difficulty_level: A string representing a difficulty level. @return: A tuple with the amount of rest between each set, and a list of reps in the sets. """ self.debug("Loading " + exercise + " script") week_module = "paula.scripts.training.room_training.resources." + exercise + ".week_" + str(week) self.debug("importing " + week_module) try: module = importlib.import_module(week_module) except ImportError: outputs.print_error("TRAINING FILE MISSING") day = module.SCHEMES[day - 1] #-1 because arrays start at zero. rest, difficulties = day scheme = (rest, difficulties[difficulty_level]) return scheme