def test_weather(self): """Test different cities""" self.assertEqual(functions.weather('погода в городе Москва', True), 'Москва') self.assertEqual( functions.weather('Какая сейчас погода в городе Канберра', True), 'Канберра') self.assertEqual(functions.weather('погода Осло', True), 'Осло') self.assertEqual( functions.weather('Погода сейчас в городе Солт-Лейк-Сити', True), 'Солт-Лейк-Сити') self.assertEqual(functions.weather('погода в Минск', True), 'Минск')
def dialog(message): global user #user.set(message.from_user.id) if message.text != 'Хватит' and user[message.from_user.id]['weather']: gorod = str(message.text) temperature = f.weather(gorod) bot.send_message(message.chat.id, temperature) #elif message.text != 'Хватит' and user.number and user.code == message.from_user.id: # number = str(message.text) # number = f.simple(number) # bot.send_message(message.chat.id, number) elif message.text == 'Хватит': #user.number = False user[message.from_user.id]['weather'] = False markup = f.menu() bot.send_message(message.chat.id, 'Ok', reply_markup=markup) elif message.text == '5 Новостей': for i in f.parser(): bot.send_message(message.chat.id, i) elif message.text == 'Орел и Решка': choice = f.orel() bot.send_message(message.chat.id, choice) elif message.text == 'Простое число': #user.number = True markup = f.break_() bot.send_message(message.chat.id, 'Введи число', parse_mode='html', reply_markup=markup) elif message.text == 'Погода': user[message.from_user.id]['weather'] = True markup = f.break_() bot.send_message(message.chat.id, 'Введи город', parse_mode='html', reply_markup=markup) elif message.text == 'Угадай число': bot.send_message(message.chat.id, x) else: print(user) bot.send_message(message.chat.id, 'Мой глупый автор не прописал диалоги 😢')
def parseFunctions(self, user, channel, msg): """Executes all of the function commands""" if msg.startswith("!user"): msg = functions.get_user(msg) elif msg.startswith("!weather"): msg = functions.weather(msg) elif msg.startswith("!jerkcity"): msg = functions.jerkcity() elif msg.startswith("!seen"): msg = self.seen.get_seen(msg) else: msg = "Invalid Request" self.msg(channel, msg)
def speak(self): opcode = 0 #check keys for key in DIRECTION_KEYS: if key in self.string: opcode = 1 for key in WEATHER_KEYS: if key in self.string: opcode = 2 if opcode == 1: #from '' to '' phrasing if self.string_list.index('from') < self.string_list.index('to'): #get indices address 1 ad1 = '' ad1_start = self.string_list.index('from') + 1 ad1_end = self.string_list.index('to') #get indices adress 2 ad2 = '' ad2_start = self.string_list.index('to') + 1 ad2_end = len(self.string_list) - 1 #get address 1 for i in range(ad1_start, ad1_end): ad1 = ad1 + self.string_list[i] + ' ' #get address 2 for k in range(ad2_start, ad2_end): ad2 = ad2 + self.string_list[k] + ' ' else: #get indices address 1 ad2 = '' ad2_start = self.string_list.index('to') + 1 ad2_end = self.string_list.index('from') #get indices adress 2 ad1 = '' ad1_start = self.string_list.index('from') + 1 ad1_end = len(self.string_list) - 1 #get address 1 for i in range(ad2_start, ad2_end): ad2 = ad2 + self.string_list[i] + ' ' #get address 2 for k in range(ad1_start, ad1_end): ad1 = ad1 + self.string_list[k] + ' ' #get directions return(functions.directions(ad1, ad2)) if opcode == 2: #at phrasing if 'at' in self.string_list: #get indices address 1 ad1 = '' ad1_start = self.string_list.index('at') + 1 #in phrasing elif 'in' in self.string_list: #get indices address 1 ad1 = '' ad1_start = self.string_list.index('in') + 1 ad1_end = len(self.string_list) - 1 #get address 1 for i in range(ad1_start, ad1_end): ad1 = ad1 + self.string_list[i] + ' ' ret_value = 0 #check future keys for key in FUTURE_KEYS: if key in self.string: ret_value = 1 if ret_value == 0: #return return(functions.weather(ad1)) elif ret_value == 1: #return return(functions.forecast(ad1))
# Sensors PIR1 = 11 PIR2 = 15 GPIO.setmode(GPIO.BOARD) GPIO.setup(PIR1, GPIO.IN, GPIO.PUD_DOWN) GPIO.setup(PIR2, GPIO.IN, GPIO.PUD_DOWN) # create instance of frame buffer screen mytft = framebuffer() # hide mouse pointer pygame.mouse.set_visible(False) # data initialisation weather_outside = functions.weather("SIXX0002", "outside") weather_inside = functions.weather("SIXX0002", "inside") weather_wind = functions.weather("SIXX0002", "wind") weather_humidity = functions.weather("SIXX0002", "humidity") weather_text = functions.weather("SIXX0002", "text") # bus initialisation (time ignore, station) left = functions.busrefresh(7, 103071) right = functions.busrefresh(7, 103161) # counters initialisation seconds = 1 n = 1 busnumber = 0 catsound = 0 while True:
# Sensors PIR1 = 11 PIR2 = 15 GPIO.setmode(GPIO.BOARD) GPIO.setup(PIR1,GPIO.IN,GPIO.PUD_DOWN) GPIO.setup(PIR2,GPIO.IN,GPIO.PUD_DOWN) # create instance of frame buffer screen mytft = framebuffer() # hide mouse pointer pygame.mouse.set_visible(False) # data initialisation weather_outside = functions.weather("SIXX0002","outside") weather_inside = functions.weather("SIXX0002","inside") weather_wind = functions.weather("SIXX0002","wind") weather_humidity = functions.weather("SIXX0002","humidity") weather_text = functions.weather("SIXX0002","text") # bus initialisation (time ignore, station) left = functions.busrefresh(7,103071) right = functions.busrefresh(7,103161) # counters initialisation seconds = 1 n = 1 busnumber = 0 catsound = 0 while True:
# elif ('время ' in text.lower()) or ('времени ' in text.lower()) or ( ('который ' in text.lower()) and ('час ' in text.lower())): functions.timeNow() # elif (('сегодня ' in text.lower()) and (('день ' in text.lower()) or ('дата ' in text.lower()) or ('число ' in text.lower()))): functions.dateNow() # elif ('анекдот ' in text.lower()) or ('шутку ' in text.lower()) or ( ('рассмеши ' in text.lower()) and ('меня ' in text.lower())): functions.joke() # elif (('погода ' in text.lower()) or ('погоду ' in text.lower())): functions.weather(text) # elif ('календарь ' in text.lower()): if ('год ' in text.lower()): functions.showCalendar(True) else: # Month and everything else functions.showCalendar(False) # elif ('очисти ' in text.lower()) or ('сотри ' in text.lower()) or ('очистить ' in text.lower()): functions.os.system('cls') # elif ('подожди ' in text.lower()): functions.wait() #