def price_handler(bot, update, args): arg = ' '.join(args) if not arg: return help_handler(message) searcher = TB_Searcher(arg) try: logger.debug('Key word to search: [{}]'.format(arg)) update.message.reply_text( '最低:¥{:.2f}/最高:¥{:.2f}/平均:¥{:.2f}'.format(*searcher.price_tuple())) except: logger.exception('Fail to print prices') update.message.reply_text('Ooops, 臣妾做不到啊')
def search_handler(bot, update, args): arg = ' '.join(args) if not arg: return help_handler(bot, update) searcher = TB_Searcher(arg) try: logger.debug('Key word to search: [{}]'.format(arg)) update.message.reply_text('\n'.join( '{}: {}'.format(title, url) for title, url in searcher.list_items())) except: logger.exception('Fail to list items') update.message.reply_text('Ooops, 臣妾做不到啊')
def unit_price_handler(message): arg = retrieve_arg(message.text) if arg is None: return help_handler(message) searcher = TB_Searcher(arg) try: logger.debug('Key word to search: [{}]'.format(arg)) bot.reply_to( message, '最低价:{:.2f}RMB/斤\n最高价:{:.2f}RMB/斤\n平均价:{:.2f}RMB/斤' .format(*searcher.unit_price_tuple()) ) except: logger.exception('Fail to print unit prices') bot.reply_to(message, 'Ooops, 臣妾做不到啊')
def unit_price_handler(message): arg = retrieve_arg(message.text) if arg is None: return help_handler(message) searcher = TB_Searcher(arg) try: logger.debug('Key word to search: [{}]'.format(arg)) bot.reply_to( message, '(每斤)最低:¥{:.2f}/最高:¥{:.2f}/平均:¥{:.2f}' .format(*searcher.unit_price_tuple()) ) except: logger.exception('Fail to print unit prices') bot.reply_to(message, 'Ooops, 臣妾做不到啊(去掉u试试看)')
def search_handler(message): arg = retrieve_arg(message.text) if arg is None: return help_handler(message) searcher = TB_Searcher(arg) try: logger.debug('Key word to search: [{}]'.format(arg)) bot.reply_to( message, '\n'.join( '{}: {}'.format(title, url) for title, url in searcher.list_items()) ) except: logger.exception('Fail to list items') bot.reply_to(message, 'Ooops, 臣妾做不到啊')