Пример #1
0
def main():
    configurations.parseArgs(sys.argv)
    listener = Listener()
    if configurations.ARGS["quiet"]:
        print("Running in quiet mode")
    while True:
        try:
            print("What's up?")
            if not configurations.ARGS["quiet"]:
                command = Command(listener.listen())
            else:
                command = Command(input())

            if command is not None and command.name is not None:
                print("Command " + command.name)
                if command.command_type == CommandTypes.AUDIO:
                    # Music procssor here
                    audioProcessor = AudioProcessor()
                    audioProcessor.process(command)
                elif command.command_type == CommandTypes.SYSTEM:
                    #System processor here
                    systemProcessor = SystemProcessor()
                    systemProcessor.process(command)
                elif command.command_type == CommandTypes.SOCIAL:
                    mediaProcessor = SocialMediaProcessor()
                    mediaProcessor.process(command)
                elif command.name.lower() == "exit":
                    print("Exiting")
                    sys.exit(0)
                else:
                    print("Command not recognized.")
            else:
                print("I'm sorry, I didn't catch that")
        except CancelCommand:
            pass
Пример #2
0
def main():
  configurations.parseArgs(sys.argv)
  listener = Listener()
  if configurations.ARGS["quiet"]:
    print("Running in quiet mode")
  while True:
    try:
      print("What's up?")
      if not configurations.ARGS["quiet"]:
        command = Command(listener.listen())
      else:
        command = Command(input())

      if command is not None and command.name is not None:
        print("Command " + command.name)
        if command.command_type == CommandTypes.AUDIO:
          # Music procssor here
          audioProcessor = AudioProcessor()
          audioProcessor.process(command)
        elif command.command_type == CommandTypes.SYSTEM:
          #System processor here
          systemProcessor = SystemProcessor()
          systemProcessor.process(command)
        elif command.command_type == CommandTypes.SOCIAL:
          mediaProcessor = SocialMediaProcessor()
          mediaProcessor.process(command)
        elif command.name.lower() == "exit":
          print("Exiting")
          sys.exit(0)
        else:
          print("Command not recognized.")
      else:
        print("I'm sorry, I didn't catch that")
    except CancelCommand:
      pass
Пример #3
0
  def _play(self, ext):

    mplayer = Popen(["mplayer", "-slave", "-really-quiet", configurations.BUFFERED_TEMP_LOCATION+"."+ext], stdin=PIPE)
    listener = Listener()
    paused = False
    stdin = mplayer.stdin
    while mplayer.poll() is None:
        if not paused:
          command = listener.get_input("Break/Stop", False, timeout=configurations.COMMAND_TIMEOUT)
        else:
          command = listener.get_input("Play/Stop", False, timeout=configurations.COMMAND_TIMEOUT)
        if command is not None:
          command = command.lower()
          if command == "break" and not paused: 
            stdin.write(b"p\n")
            stdin.flush()
            paused = True
          elif command == "play" and paused:
            stdin.write(b"p\n")
            stdin.flush()
            paused = False
          elif command == "stop":
            mplayer.terminate()
            break
          elif command == "volume up":
            stdin.write(b"/\n")
            stdin.flush()
          elif command == "volume down":
            stdin.write(b"*\n")
            stdin.flush()
Пример #4
0
 def process(self, command):
   listener = Listener()
   media = listener.get_input("Which Social Media")
   if media.lower() == SocialMediaTypes.TWITTER:
     message = listener.get_input("What's your cool new post", timeout=60)
     while len(message) > 140:
       print("That's a bit too long (" + str(len(message)) + ")")
       message = __input("What's your cool new post?")
     twitter_poster.post(message)
Пример #5
0
 def _play_note(self):
   listener = Listener()
   title = listener.get_input("What the title", timeout=20)
   client = MongoClient()
   cursor = client[configurations.DB.NAME][configurations.DB.COLLECTIONS.NOTES]
   notes = list(cursor.find({"title" : title}))
   if len(notes) == 0:
     print("Note not found")
   else:
     print(note['title'])
     print(note['note'])
   client.close()
Пример #6
0
 def _play_note(self):
     listener = Listener()
     title = listener.get_input("What the title", timeout=20)
     client = MongoClient()
     cursor = client[configurations.DB.NAME][
         configurations.DB.COLLECTIONS.NOTES]
     notes = list(cursor.find({"title": title}))
     if len(notes) == 0:
         print("Note not found")
     else:
         print(note['title'])
         print(note['note'])
     client.close()
Пример #7
0
 def _get_information(self):
   client = MongoClient()
   cursor = client[configurations.DB.NAME][configurations.DB.COLLECTIONS.MUSIC]
   poss = list(cursor.find({"title" : self.title}))
   if len(poss) == 0:
     print("Song not found, need to fetch it, implement eventually")
   elif len(poss) == 1:
     self.url = poss[0]['url']
     self.artist = poss[0]['artist'].lower()
   elif len(poss) == 2:
     listener = Listener()
     self.artist = listener.get_input("What artist?").lower()
   client.close()
Пример #8
0
 def _get_information(self):
     client = MongoClient()
     cursor = client[configurations.DB.NAME][
         configurations.DB.COLLECTIONS.MUSIC]
     poss = list(cursor.find({"title": self.title}))
     if len(poss) == 0:
         print("Song not found, need to fetch it, implement eventually")
     elif len(poss) == 1:
         self.url = poss[0]['url']
         self.artist = poss[0]['artist'].lower()
     elif len(poss) == 2:
         listener = Listener()
         self.artist = listener.get_input("What artist?").lower()
     client.close()
Пример #9
0
 def _take_note(self):
   listener = Listener()
   title = listener.get_input("What's the title of this note", timeout=20)
   note = listener.get_input("What's your note", timeout=120)
   client = MongoClient()
   cursor = client[configurations.DB.NAME][configurations.DB.COLLECTIONS.NOTES]
   note = dict()
   note['title'] = title
   note['note'] = note
   if len(list(cursor.find({"title" : note['title']}))) == 0:
     cursor.insert(note)
   else:
     print("Note with that name already exists")
   client.close()
Пример #10
0
 def _take_note(self):
     listener = Listener()
     title = listener.get_input("What's the title of this note", timeout=20)
     note = listener.get_input("What's your note", timeout=120)
     client = MongoClient()
     cursor = client[configurations.DB.NAME][
         configurations.DB.COLLECTIONS.NOTES]
     note = dict()
     note['title'] = title
     note['note'] = note
     if len(list(cursor.find({"title": note['title']}))) == 0:
         cursor.insert(note)
     else:
         print("Note with that name already exists")
     client.close()
Пример #11
0
  def _fetch_song(self):
    listener = Listener()
    song_name = listener.get_input("What song")
    artist = listener.get_input("Artist")
    client = MongoClient()
    cursor = client[configurations.DB.NAME][configurations.DB.COLLECTIONS.MUSIC]
    songs = list(cursor.find({"title" : song_name}))

    if len(songs) == 1:
      song = Song(songs[0]['title'], songs[0]['url'])
      return song
    elif len(songs) == 0:
      return self._add_song(song_name, artist)
    else:
      for song in songs:
        if song['artist'] == artist:
          return Song(song['title'], song['url'], songs['artist'])
      return self._add_song(song_name, artist)
Пример #12
0
    def _fetch_song(self):
        listener = Listener()
        song_name = listener.get_input("What song")
        artist = listener.get_input("Artist")
        client = MongoClient()
        cursor = client[configurations.DB.NAME][
            configurations.DB.COLLECTIONS.MUSIC]
        songs = list(cursor.find({"title": song_name}))

        if len(songs) == 1:
            song = Song(songs[0]['title'], songs[0]['url'])
            return song
        elif len(songs) == 0:
            return self._add_song(song_name, artist)
        else:
            for song in songs:
                if song['artist'] == artist:
                    return Song(song['title'], song['url'], songs['artist'])
            return self._add_song(song_name, artist)
Пример #13
0
  def _add_song(self, name=None, artist=None):
    listener = Listener()
    if name is None:
      name = listener.get_input("Song title")
    if artist is None:
      artist = listener.get_input("Artist")

    query_string = urllib.parse.urlencode({"search_query" : artist + " " +name})
    html_content = urllib.request.urlopen("http://www.youtube.com/results?" +
    query_string)
    search_results = re.findall(r'href=\"\/watch\?v=(.{11})',
    html_content.read().decode())

    top_result = "http://www.youtube.com/watch?v=" + search_results[0]

    song = Song(name, top_result, artist=artist)
    song.create()
    print(song.title + " by " + song.artist + " added")
    return song
Пример #14
0
    def _add_song(self, name=None, artist=None):
        listener = Listener()
        if name is None:
            name = listener.get_input("Song title")
        if artist is None:
            artist = listener.get_input("Artist")

        query_string = urllib.parse.urlencode(
            {"search_query": artist + " " + name})
        html_content = urllib.request.urlopen(
            "http://www.youtube.com/results?" + query_string)
        search_results = re.findall(r'href=\"\/watch\?v=(.{11})',
                                    html_content.read().decode())

        top_result = "http://www.youtube.com/watch?v=" + search_results[0]

        song = Song(name, top_result, artist=artist)
        song.create()
        print(song.title + " by " + song.artist + " added")
        return song
Пример #15
0
    def _play(self, ext):

        mplayer = Popen([
            "mplayer", "-slave", "-really-quiet",
            configurations.BUFFERED_TEMP_LOCATION + "." + ext
        ],
                        stdin=PIPE)
        listener = Listener()
        paused = False
        stdin = mplayer.stdin
        while mplayer.poll() is None:
            if not paused:
                command = listener.get_input(
                    "Break/Stop",
                    False,
                    timeout=configurations.COMMAND_TIMEOUT)
            else:
                command = listener.get_input(
                    "Play/Stop", False, timeout=configurations.COMMAND_TIMEOUT)
            if command is not None:
                command = command.lower()
                if command == "break" and not paused:
                    stdin.write(b"p\n")
                    stdin.flush()
                    paused = True
                elif command == "play" and paused:
                    stdin.write(b"p\n")
                    stdin.flush()
                    paused = False
                elif command == "stop":
                    mplayer.terminate()
                    break
                elif command == "volume up":
                    stdin.write(b"/\n")
                    stdin.flush()
                elif command == "volume down":
                    stdin.write(b"*\n")
                    stdin.flush()
Пример #16
0
 def _remove_song(self):
   listener = Listener()
   name = listener.get_input("Song title")
   song = Song(name)
   song.delete()
   print(name + " deleted")
Пример #17
0
 def _remove_song(self):
     listener = Listener()
     name = listener.get_input("Song title")
     song = Song(name)
     song.delete()
     print(name + " deleted")