Пример #1
0
def runCommand( string ):
	cmd = vConfig.getConfig( string )
        textString = ''
	if ( cmd is not None ):
	    if ( cmd == "class:weather" ):
                VoiceWeather.speakWeather( vConfig, string )
	    elif ( cmd == "class:download" ):
		downloadString = string[string.find(' '):]
                dl_result = VoiceDownloader.download( vConfig, downloadString )
		GoogleSpeech.tts( dl_result )
	    elif ( cmd == "class:hue_lights" ):
		hueController = VoiceHue()
		hueController.controlByCommand( string )
		lights = hueController.getLights()
		print lights

		groups = hueController.getGroups()
		print groups

		#hueController.toggleByName( "kitchen" )
		hueController.dimByName( "kitchen" , -50)
		hueController.dimByName( "kitchen" , +50)

	    else:	
	        p = Popen(cmd, shell=True, stdout=PIPE)
	        textString = p.communicate()[0].rstrip()

	return textString
Пример #2
0
    def speakWeather( config, string ):
        location_code = config.get( "weather", "weather_location_code" )

        weather_com_result = pywapi.get_weather_from_weather_com( str(location_code ))
        print weather_com_result
        print string


        lookupString = ''
        ### TODAY
        if ( re.compile( "today", re.IGNORECASE ).findall( string ,1 )):
            todayData = weather_com_result['forecasts'][0]
            if ( todayData['day']['text'] != 'N/A' ):
                    if ( int( todayData['day']['chance_precip'] ) > 40 ):
                        lookupString = "Today will be " + str( todayData['day']['text'] ) + " with a chance of showers and a high of " + str( todayData['high'] ) + "degrees"
                    else:
                        lookupString = "Today will be " + str( todayData['day']['text'] ) + " with a high of " + str( todayData['high'] ) + "degrees"
            else:
                    if ( int(todayData['night']['chance_precip'] ) > 40 ):
                        lookupString = "Tonight will be " + str( todayData['night']['text'] ) + " with a chance of showers"
                    else:
                        lookupString = "Tonight will be " + str( todayData['night']['text'] )


        ### TONIGHT
        elif ( re.compile( "tonight", re.IGNORECASE).findall( string ,1 )):
            todayData = weather_com_result['forecasts'][0]
            if ( int(todayData['night']['chance_precip'] ) > 40 ):
                lookupString = "Tonight will be " + str( todayData['night']['text'] ) + " with a chance of showers"
            else:
                lookupString = "Tonight will be " + str( todayData['night']['text'] )

        ### Tomorrow Night
        elif ( re.compile( "tomorrow night", re.IGNORECASE).findall( string ,1 )):
            todayData = weather_com_result['forecasts'][1]
            if ( int(todayData['night']['chance_precip'] ) > 40 ):
                lookupString = "Tomorrow night will be " + str( todayData['night']['text'] ) + " with a chance of showers"
            else:
                lookupString = "Tomorrow night will be " + str( todayData['night']['text'] )

        ### TODAY
        elif ( re.compile( "tomorrow", re.IGNORECASE ).findall( string ,1 )):
            todayData = weather_com_result['forecasts'][1]
            if ( todayData['day']['text'] != 'N/A' ):
                    if (( int( todayData['day']['chance_precip'] ) > 40 ) or ( int( todayData['night']['chance_precip'] ) > 40 )):
                        lookupString = "Tomorrow will be " + str( todayData['day']['text'] ) + " with a chance of showers and a high of " + str( todayData['high'] ) + " degrees"
                    else:
                        lookupString = "Tomorrow will be " + str( todayData['day']['text'] ) + " with a high of " + str( todayData['high'] ) + "degrees"


        else:
            lookupString = "It is currently " + str(weather_com_result['current_conditions']['text']) + " and " + weather_com_result['current_conditions']['temperature'] + "degrees.\n\n"


        print lookupString
        ## Work our magic
        if ( lookupString != '' ):
            GoogleSpeech.tts( lookupString )
        else:
            GoogleSpeech.tts( "Sorry, Weather information un-available at this time, please try again later" )