Exemplo n.º 1
0
 def test_text_to_int(self):
   self.assertEqual([utils.text_to_int(word) for word in
     ["one", "two", "three", "four", "five", "six", "seven", "eight",
     "nine", "ten", "fifteen", "eighteen", "twenty", "twenty five",
     "ten and a quarter", "fifteen and a half",
     "thirty five and three-quarters"]],
     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 18, 20, 25, 10.25, 15.5, 35.75])
Exemplo n.º 2
0
 def test_text_to_int(self):
     self.assertEqual([
         utils.text_to_int(word) for word in [
             "one", "two", "three", "four", "five", "six", "seven", "eight",
             "nine", "ten", "fifteen", "eighteen", "twenty", "twenty five",
             "ten and a quarter", "fifteen and a half",
             "thirty five and three-quarters"
         ]
     ], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 18, 20, 25, 10.25, 15.5, 35.75])
Exemplo n.º 3
0
    def execute(self, **kwargs):
        """Schedule a command to be run at a later time.

    Keyword arguments:
    command -- the command (in natural language) to be run
    in -- a relative time offset (hours, minutes, and/or seconds)
    at -- an absolute time to run the command

    """
        expire = 0
        if "command" not in kwargs:
            raise plugin.UnsuccessfulExecution("No command provided.")

        if "in" in kwargs:
            try:
                idx = kwargs["in"].rfind(" ")
                wait = kwargs["in"][:idx]
                scale = kwargs["in"][idx + 1:]
            except ValueError:
                raise plugin.UnsuccessfulExecution("Error parsing time.")
            try:
                expire = int(wait)
            except ValueError:
                try:
                    expire = utils.text_to_int(wait)
                except:
                    raise plugin.UnsuccessfulExecution("Error parsing time.")
            if scale.startswith("h"):
                expire = datetime.datetime.now() + datetime.timedelta(
                    hours=expire)
            elif scale.startswith("m"):
                expire = datetime.datetime.now() + datetime.timedelta(
                    minutes=expire)
            elif scale.startswith("s"):
                expire = datetime.datetime.now() + datetime.timedelta(
                    seconds=expire)
            else:
                raise plugin.UnsuccessfulExecution(
                    "Could not determine time scale (h/m/s).")
        elif "at" in kwargs:
            expire = utils.text_to_absolute_time(wait)
            if not expire:
                raise plugin.UnsuccessfulExecution("Error parsing time.")
        else:
            raise plugin.UnsuccessfulExecution(
                'Command could not be scheduled. Must specify "in" or "at"')

        cmd, namespace, args = self.registrar.find_best_service(
            kwargs["command"])
        if cmd is None:
            raise plugin.UnsuccessfulExecution("Provided text could not be "
                                               "converted into a command.")
        self.queue.put((expire, (cmd, namespace, args)))
        self.event.set()
        return 'Command scheduled.'
Exemplo n.º 4
0
  def execute(self, **kwargs):
    """Schedule a command to be run at a later time.

    Keyword arguments:
    command -- the command (in natural language) to be run
    in -- a relative time offset (hours, minutes, and/or seconds)
    at -- an absolute time to run the command

    """
    expire = 0
    if "command" not in kwargs:
      raise plugin.UnsuccessfulExecution("No command provided.")
    
    if "in" in kwargs:
      try:
        idx = kwargs["in"].rfind(" ")
        wait = kwargs["in"][:idx]
        scale = kwargs["in"][idx + 1:]
      except ValueError:
        raise plugin.UnsuccessfulExecution("Error parsing time.")
      try:
        expire = int(wait)
      except ValueError:
        try:
          expire = utils.text_to_int(wait)
        except:
          raise plugin.UnsuccessfulExecution("Error parsing time.")
      if scale.startswith("h"):
        expire = datetime.datetime.now() + datetime.timedelta(hours=expire)
      elif scale.startswith("m"):
        expire = datetime.datetime.now() + datetime.timedelta(minutes=expire)
      elif scale.startswith("s"):
        expire = datetime.datetime.now() + datetime.timedelta(seconds=expire)
      else:
        raise plugin.UnsuccessfulExecution(
                          "Could not determine time scale (h/m/s).")
    elif "at" in kwargs:
      expire = utils.text_to_absolute_time(wait)
      if not expire:
        raise plugin.UnsuccessfulExecution("Error parsing time.")        
    else:
      raise plugin.UnsuccessfulExecution(
        'Command could not be scheduled. Must specify "in" or "at"')

    cmd, namespace, args = self.registrar.find_best_service(kwargs["command"])
    if cmd is None:
      raise plugin.UnsuccessfulExecution("Provided text could not be "
        "converted into a command.")
    self.queue.put((expire, (cmd, namespace, args)))
    self.event.set()
    return 'Command scheduled.'