def func(): def getposit(city): x = 0 pos = pywapi.get_location_ids(city) for i in pos: x += 1 location_id = i result = pywapi.get_weather_from_weather_com(location_id) return(result['current_conditions']['temperature']) print('city') try: x= voice_rec.voice() except: return("don't understand") try: return(getposit(goslate.Goslate().translate(x, 'en'))) except : return(x, 'not a city')
import os import time from importlib.machinery import SourceFileLoader import voice_rec import Sintez_Audio as sau import Play as pau spis = os.listdir('/home/anton/PycharmProjects/untitled1/lib') modules = [] for i in spis: modules.append(i) while True: sau.gen('ожидаю запрос') pau.play() x = voice_rec.voice() if x != 'окей': while x != 'окей': x = voice_rec.voice() time.sleep(0.3) sau.gen('слушаю') pau.play() x = voice_rec.voice() for i in range(len(spis)): f = SourceFileLoader(modules[i], "lib/"+modules[i]).load_module() if f.KEYS == x: sau.gen(f.func()) pau.play()