def search(query, linksMode, bot, update): global captchaLocked, captchaLockParams if len(query.strip()) < 1: query = text.get_random_artist() payload = {'q': query}; if captchaLocked: payload.update(captchaLockParams) payload.update({'captcha_key': query}) result = requests.get(DATMUSIC_API_ENDPOINT, params=payload, headers=DEFAULT_HEADERS); try: response = result.json(); if response['status'] == 'ok': response = response["data"]; captchaLocked = False captchaLockParams = {} replyAudioSearchResults(response, query, linksMode, bot, update) else: error = response['error'] if error and 'captcha_id' in error: onCaptchaLock(error, query) replyCaptchaInline(query, bot, update) except ValueError as e: println("Failed to parse result:") print(e)
def search(query): if len(query.strip()) < 1: query = text.get_random_artist() logger.info("Search query is '%s'" % query) payload = {'q': query}; result = requests.get(DATMUSIC_API_ENDPOINT, params = payload); response = result.json()["data"]; return response;
def search(query): if len(query.strip()) < 1: query = text.get_random_artist() logger.info("Search query is '%s'" % query) payload = { 'q': query }; result = requests.get(DATMUSIC_API_ENDPOINT, params = payload); response = result.json()["data"]; return response; def error(bot, update, error): logger.warn('Update "%s" caused error "%s"' % (update, error)) def add_update_handlers(dp): dp.add_handler(CommandHandler("start", text.start)) dp.add_handler(CommandHandler("about", text.about)) dp.add_handler(InlineQueryHandler(inlinequery)) return dp def main(): token = os.getenv("DATMUSIC_BOT_TOKEN") if not token: logging.critical('NO TOKEN FOUND!') sys.exit() # Create the Updater and pass it your bot 's token. updater = Updater(token) # Get the dispatcher to register handlers dp = updater.dispatcher add_update_handlers(dp) # log all errors dp.add_error_handler(error) # Start the Bot updater.start_polling() # Block until the user presses Ctrl - C or the process receives SIGINT, #SIGTERM or SIGABRT.This should be used most of the time, since# start_polling() is non - blocking and will stop the bot gracefully. updater.idle() if __name__ == '__main__': main()
def search(query, links_mode, bot, update, search_type=None): is_minerva_search = False if search_type is None: search_type = 'minerva' is_minerva_search = True global captchaLocked, captchaLockParams if len(query.strip()) < 1: query = text.get_random_artist() payload = {'q': query, 'types[]': [search_type]} if captchaLocked: payload.update(captchaLockParams) payload.update({'captcha_key': query}) result = requests.get(DATMUSIC_API_ENDPOINT, params=payload, headers=DEFAULT_HEADERS) try: response = result.json() if response['status'] == 'ok': results = response["data"][search_type] if not results and is_minerva_search: logger.info( 'Minerva returned empty results, falling back to audios') return search(query, links_mode, bot, update, 'audios') captchaLocked = False captchaLockParams = {} reply_audio_search_results(results, query, links_mode, bot, update) else: error = response['error'] if error and 'captcha_id' in error: on_captcha_lock(error, query) reply_captcha_inline(query, bot, update) except ValueError as e: print("Failed to parse result:") print(e)