def say_message(message): global messageIndex print("We say '%s'" % message) (action, restOfPhrase) = extractAction(message) print("action: %s" % action) print("restOfPhrase: %s" % restOfPhrase) if action is not None: if action.lower() == "twitter": import brain as Brain Brain.searchTwitterForValue(restOfPhrase) return elif action == "neutral": ACTION.action_be_neutral() elif action == "happy": ACTION.action_be_happy() elif action == "unhappy": ACTION.action_be_unhappy() elif action == "angry": ACTION.action_be_angry() elif action == "surprised": ACTION.action_be_surprised() else: RESPONSE_INFO.analyse(message) thisIndex = messageIndex filename = os.path.realpath('audio/%s.wav' % thisIndex) os.system("espeak -g 10 -w %s \"%s\"" % (filename, restOfPhrase)) messageIndex = messageIndex + 1 for client in SocketManager.clients: client.write_message("audio:http://bb4d0cce.ngrok.io/audio/%s.wav" % thisIndex)
def weather_summary(location): location = geolocator.geocode(location) lat = location.latitude lng = location.longitude forecast = forecastio.load_forecast(api_key, lat, lng, units="uk") by_day = forecast.daily() if by_day.icon == "rain" or by_day.icon == "wind" or by_day.icon == "sleet" or by_day.icon == "fog": ACTION.action_be_unhappy() else: ACTION.action_be_happy() TALK.say_message(by_day.summary)
def analyse(message): values = { 'key' : '8ad960732d31af8741e42faf716b7d14', 'txt' : message, 'model' : 'general_en' } data = urllib.urlencode(values) req = urllib2.Request("https://api.meaningcloud.com/sentiment-2.0", data) response = urllib2.urlopen(req) data = json.load(response) if data['subjectivity'] == "SUBJECTIVE": # Opinion if data['score_tag'] == "P" or data['score_tag'] == "P+": print("Be happy") ACTION.action_be_happy() elif data['score_tag'] == "N" or data['score_tag'] == "N+": print("Be Sad") ACTION.action_be_unhappy() else: ACTION.action_be_surprised() print("No Comment") else: if data['score_tag'] == "P" or data['score_tag'] == "P+": print("I agree") ACTION.action_be_surprised() elif data['score_tag'] == "N" or data['score_tag'] == "N+": print("Be Angry") ACTION.action_be_angry() else: ACTION.action_be_surprised()