def wish_morning(): wm = [ 'Good thoughts precede great deeds. Great deeds precede success. Have a great day.', 'This is not just another day, this is yet another chance to make your dreams come true. Good morning.' ] a = random.randint(0, 1) tts.voice(wm[a])
def wish_night(): wn = [ 'Do you think about me before you go to sleep? Good night.', 'I just wanted to let you know I think of you. Good Night', 'I am already missing you. Good night' ] b = random.randint(0, 2) tts.voice(wn[b])
def temp(): url = "http://api.openweathermap.org/data/2.5/weather?lat=22.57&lon=88.36&appid=ddc80cbc49644abd43d989deb781d0e3&mode=xml" response = urllib.urlopen(url) data = ET.parse(response) root = data.getroot() temp = root[1].attrib temp_val = float(temp['value']) - 273 text = "The temperature is " + str(int(temp_val)) + " degree Celsius" tts.voice(text)
def no_rep(): nr = [ 'Let me be sure I understand which information you are looking for.', 'Thats a timely question, because I am currently gathering information on that.', 'This is scary for me to say, so I am hoping you can really hear me and try not to judge me or give me any advice.', ' I will totally take a look at that.' ] n = random.randint(0, 3) tts.voice(nr[n])
def search(query): try: result = wikipedia.summary(query, sentences=1) tts.voice(result) except wikipedia.exceptions.DisambiguationError as de: error = de.options print(error[0]) except wikipedia.exceptions.PageError as pe: error = pe.error tts.voice("Nothing found on Wikipedia.")
def weather(): url = "http://api.openweathermap.org/data/2.5/weather?lat=22.57&lon=88.36&appid=ddc80cbc49644abd43d989deb781d0e3&mode=xml" response = urllib.urlopen(url) data = ET.parse(response) root = data.getroot() temp = root[1].attrib humid = root[2].attrib cloud = root[5].attrib temp_val = float(temp['value']) - 273 humid_val = int(humid['value']) cloud_type = cloud['name'] text = "The temperature is " + str( int(temp_val)) + " degree Celsius " + str( humid_val) + 'percent humidity and' + cloud_type tts.voice(text)
def unlock(): results = search() if not results: tts.voice('No keys found') for addr in results: if (addr == phone): tts.voice("Door Unlocked.") motor.open() break else: tts.voice("Key not found.")
def joke(): response = urllib2.urlopen("http://tambal.azurewebsites.net/joke/random") data = json.load(response) tts.voice(data['joke'])
tts.voice(wm[a]) def edit(): os.system('echo "NULL" > /var/www/html/test/val.txt') while True: with open('/var/www/html/test/val.txt') as data_file: val = data_file.readline() val = val.upper() if 'LIGHTS' in val: if 'BEDROOM' in val: if 'ON' in val: GPIO.output(11, True) tts.voice("Bedroom Lights on.") edit() elif 'OFF' in val: GPIO.output(11, False) tts.voice("Bedroom Lights off.") edit() if ('LIVING' in val and 'ROOM' in val): if 'ON' in val: GPIO.output(12, True) tts.voice("Living room Lights on.") edit() elif 'OFF' in val: GPIO.output(12, False)