示例#1
0
def inquire():
    # voice(random.choice(inquiry))
    # voice("here give me a second")
    category = 'technology'
    response = urllib2.urlopen('http://www.reddit.com/r/' + category + "/top/.json").read()

    headlines = json.loads(response)

    # print json.dumps(headlines, sort_keys=True, indent=4, separators=(',', ': '))

    voice("How many articles would you like to hear about?")

    for i in range(0,5):
        print headlines['data']['children'][i]['data']['title'] + "\n"

    voice(headlines['data']['children'][0]['data']['title'])
    voice("would you like to hear more?")
    voice(headlines['data']['children'][1]['data']['title'])


    # for child in headlines['data']['children']:
    #     print child['data']['title'] + "\n"

    # print headlines['data']['children'][0]['data']['title']

    voice("hello ")
def queryWolfram(query):
    response = client.query(query)

    try: 
        print response.pods[1].format['plaintext'][0]
        voice("Do you want on this subject?")
    except:
        voice("I don't understand what you're saying")
def weatherLocation(location):
    response = urllib2.urlopen("http://api.aerisapi.com/forecasts/" + location + "?client_id=" + client_id + "&client_secret=" + client_secret).read()
    weather = json.loads(response)
    if weather['success']:
        period = weather['response'][0]['periods'][0]
        tempAvg = period['avgTempF']
        tempMax = period['maxTempF']
        tempMin = period['minTempF']
        precip = period['pop']
        snow = period['snowIN']
        wind = str(period['windGustMPH'])
        # voice output
        voice("The current weather in " + location + " is " + str(period['weather']))
        voice ("There will be a high of " + str(tempMax) + "and low of " + str(tempMin) + " degrees fahrenheit, with a " + str(precip) + " percent chance of rain.")
        voice(weatherComment(tempAvg, precip, snow))
    else: 
        print("An error has occured:" + weather['error']['description'])
def doubleChargeMeFoDat():
    voice("Ohhhhhhh, don't double charge me fo dat")
def mpdCommands(command, query):
    # Plays the next song
    if command == 'playSong':
        voice("playing song")
        client.play()
    elif command == 'nextSong':
        voice("playing next song")
        client.next()
    # Plays the previous song
    elif command == 'prevSong':
        client.previous()
        voice("playing previous song")
    # Pauses/Plays the current song
    elif command == 'pauseSong':
        data = client.status()
        state = data['state']
        if state == 'pause':
            voice("song resumed")
            client.pause()
        else: 
            client.pause()
            voice("song paused")
    # Voices the current song playing
    elif command == 'currentSong':
        client.setvol(5)
        data = client.currentsong()
        currentSong = data['title']
        artist = data['artist']
        voice("the current song is" + currentSong + " by " + artist)
        client.setvol(20)
    # Sets the volume for the MPD: 
    # NOT IMPLEMENTED
    elif command == 'setVolume':
        if query == 'less':
            client.volume(-10)
        elif query == 'more':
            client.volume(10)
        else:
            return
    # QUERY FUNCTIONS
    # query
    elif command == 'querySong':
        return
        # NOT IMPLEMENTED
    # Loads a playlist the user queries
    elif command == 'playPlaylist':
        client.load(query)
    else: 
        #do nothing
        return