def test_process_about_command(self, bot_mock, update_mock): update = MagicMock() update.message.text = '/about' update.message.chat.id = '123' update_mock.de_json.return_value = update telegram_bot = TelegramBot() telegram_bot.process_event({}) bot_mock.return_value.send_message.assert_any_call( chat_id='123', text='Made with ❤️ by @juanitodread')
def test_process_playing_command(self, gorrion_mock, bot_mock, update_mock): update = MagicMock() update.message.text = '/playing' update.message.chat.id = '123' update_mock.de_json.return_value = update gorrion_mock.return_value.playing.return_value.tweet = 'tweet-message' telegram_bot = TelegramBot() telegram_bot.process_event({}) bot_mock.return_value.send_message.assert_any_call( chat_id='123', text='tweet-message')
def test_process_playing_command_when_error(self, gorrion_mock, bot_mock, update_mock): update = MagicMock() update.message.text = '/playing' update.message.chat.id = '123' update_mock.de_json.return_value = update gorrion_mock.return_value.playing.side_effect = SpotifyApiError( 'error') telegram_bot = TelegramBot() telegram_bot.process_event({}) bot_mock.return_value.send_message.assert_any_call(chat_id='123', text='error')
def test_process_playing_album_command(self, gorrion_mock, bot_mock, update_mock): tweet = PublishedTweet(id_='1', tweet='tweet1', entity=None) update = MagicMock() update.message.text = '/album' update.message.chat.id = '123' update_mock.de_json.return_value = update gorrion_mock.return_value.playing_album.return_value = tweet telegram_bot = TelegramBot() telegram_bot.process_event({}) bot_mock.return_value.send_message.assert_any_call(chat_id='123', text='tweet1')
def get(self, day, show_content='tty'): try: day = date.today() if day is None else datetime.strptime( day, '%Y/%m/%d') day_str = day.strftime("%y%m%d") except ValueError: return 'Invalid date format' message = self._crawler.get_wod(day_str) if show_content == 'telegram': telegram_bot = TelegramBot() return telegram_bot.send_wod(message) return message
def test_process_start_command(self, bot_mock, update_mock): update = MagicMock() update.message.text = '/start' update.message.chat.id = '123' update_mock.de_json.return_value = update telegram_bot = TelegramBot() telegram_bot.process_event({}) bot_mock.return_value.send_message.assert_any_call( chat_id='123', text='Welcome to Gorrion Bot 🐦🤖') bot_mock.return_value.send_message.assert_any_call( chat_id='123', text=('Supported commands are: \n\n' '/start\n' '/playing\n' '/lyric\n' '/album\n' '/about'))
def test_constructor(self, bot_mock): telegram_bot = TelegramBot() assert telegram_bot._bot is not None bot_mock.assert_called_once_with(token=None)
return flowerName = context.args[0] flower = flowerHandler.getFlower(flowerName) logger.debug(f'Sending an mqtt - request for flower: {flower}') mqttClient.querySensor(flower) lastChatIds.append(chatId) flowerHandler = FlowerHandler() try: flowerHandler.parse('flowers.yaml') except ValueError: logger.error('Failed to parse the flower file.') exit(1) mqttClient = MqttClient(args.mqtt_server_address, args.mqtt_server_port, 'blume', mqttCallback) telegramBot = TelegramBot(args.telegram_api_token, telegramCallback) logger.info('Starting the MQTT - Client') mqttClient.start() try: logger.info('Entering the Telegram Bot listener loop') telegramBot.setup() telegramBot.listen() except KeyboardInterrupt: logger.info('Shutting down the bot...')
import logging from src.rss_filterer import RssFilterer from src.rss_list import RssList from src.telegram_bot import TelegramBot if __name__ == "__main__": try: while True: for rss in RssList.get(): logging.debug("rss: %s" % rss) RssFilterer(rss).filter().send_links() except Exception as e: TelegramBot.send( 'Erro fatal. Parei de mandar links por causa disso: %s' % str(e)) """" Known issues: Busca nao pega non ASC characters nao loga em arquivo """
def send_links(self): amount = len(self._pages) # if amount: print('sending %d links from %s to Telegram' % (amount, self._rss)) [TelegramBot.send(page) for page in self._pages]
def test_send_empty_msg(): TelegramBot.send('')
def test_send_msg(): TelegramBot.send('Getting a little better')