def wallparser(bot, update, tags, pages, chat_id, info=None): #Wallpaper parser bot.sendChatAction(chat_id, "upload_photo") client = Pybooru('Yandere') try: randompage = randint(1, int(pages)) posts = client.posts_list(tags=str(tags), limit=1, page=str(randompage)) for post in posts: tmp_data = "Uploader: " + post['author'] + "\nID: " + str( post['id']) globalarray[chat_id] = dict(data=tmp_data) photo = post['file_url'] reply_markup = ikeyboard if info != None: bot.sendPhoto(chat_id, photo, reply_markup=reply_markup, caption=info + '\n' + tmp_data) else: bot.sendPhoto(chat_id, photo, reply_markup=reply_markup, caption=tmp_data) except Exception as e: print(e) print("Retrying...") print(wallparser(bot, update, tags, pages, chat_id))
def inline(bot, update): #Inline Handler & Parser query = update.inline_query.query if query is None: query = 'rating:s' client = Pybooru('Yandere') posts = client.posts_list(tags=query, limit=50) lposts = len(posts) inlinequery = list() reply_markup = InlineKeyboardMarkup( [InlineKeyboardButton("More", callback_data='More')]) for post in posts: inlinequery.append( InlineQueryResultPhoto( type='photo', id=uuid4(), photo_url=post['file_url'], photo_width=post['preview_width'] * 6, photo_height=post['preview_height'] * 6, #reply_markup=reply_markup, thumb_url=post['preview_url']), ) bot.answerInlineQuery(update.inline_query.id, results=inlinequery, switch_pm_text="Help", switch_pm_parameter="ihelp") inlinequery.clear() else: client = Pybooru('Yandere') posts = client.posts_list(tags=query, limit=50) lposts = len(posts) inlinequery = list() reply_markup = InlineKeyboardMarkup( [InlineKeyboardButton("More", callback_data='More')]) for post in posts: inlinequery.append( InlineQueryResultPhoto( type='photo', id=uuid4(), photo_url=post['file_url'], photo_width=post['preview_width'] * 6, photo_height=post['preview_height'] * 6, #reply_markup=reply_markup, thumb_url=post['preview_url']), ) bot.answerInlineQuery(update.inline_query.id, results=inlinequery, switch_pm_text="Help", switch_pm_parameter="ihelp") inlinequery.clear()
def idd(bot, update, tags=None, chat_id=None): randomint = randint(1000, 10000000) try: bot.sendChatAction(chat_id, "upload_document") tags = update.message.text.split(' ', 1)[1] chat_id = update.message.chat_id try: client = Pybooru('Yandere') posts = client.posts_list(tags="id:" + str(tags), limit=1) for post in posts: urllib.request.urlretrieve( post['file_url'], "tmp/anime_bot_" + str(randomint) + ".jpg") tmp_data = "Uploader: " + post['author'] + "\nID: " + str( post['id']) globalarray[chat_id] = dict(data=tmp_data) photo = open('tmp/anime_bot_' + str(randomint) + ".jpg", 'rb') reply_markup = InlineKeyboardMarkup( [[InlineKeyboardButton("More", callback_data='More')]]) bot.sendDocument(chat_id, photo, reply_markup=reply_markup) os.remove('tmp/anime_bot_' + str(randomint) + ".jpg") except Exception as e: print(e) except: bot.sendChatAction(chat_id, "upload_document") client = Pybooru('Yandere') try: posts = client.posts_list(tags="id:" + str(tags), limit=1) for post in posts: urllib.request.urlretrieve( post['file_url'], "tmp/anime_bot_" + str(randomint) + ".jpg") tmp_data = "Uploader: " + post['author'] + "\nID: " + str( post['id']) globalarray[chat_id] = dict(data=tmp_data) photo = open('tmp/anime_bot_' + str(randomint) + ".jpg", 'rb') reply_markup = InlineKeyboardMarkup( [[InlineKeyboardButton("More", callback_data='More')]]) bot.sendDocument(chat_id, photo, reply_markup=reply_markup) os.remove('tmp/anime_bot_' + str(randomint) + ".jpg") except Exception as e: print(e)
def noparser( bot, update, tags, pages, chat_id, info=None): #Parser without retry loop (to prevent infinte exception) bot.sendChatAction(chat_id, "upload_photo") client = Pybooru('Yandere') randomint = randint(1000, 10000000) try: randompage = randint(1, int(pages)) posts = client.posts_list(tags=str(tags), limit=1, page=str(randompage)) for post in posts: urllib.request.urlretrieve( post['file_url'], "tmp/anime_bot_" + str(randomint) + ".jpg") tmp_data = "Uploader: " + post['author'] + "\nID: " + str( post['id']) globalarray[chat_id] = dict(data=tmp_data) photo = open('tmp/anime_bot_' + str(randomint) + ".jpg", 'rb') reply_markup = ikeyboard if info != None: bot.sendPhoto(chat_id, photo, reply_markup=reply_markup, caption=info + '\n' + tmp_data) os.remove('tmp/anime_bot_' + str(randomint) + ".jpg") else: bot.sendPhoto(chat_id, photo, reply_markup=reply_markup, caption=tmp_data) os.remove('tmp/anime_bot_' + str(randomint) + ".jpg") except Exception as e: print(e)
# -*- coding: utf-8 -*- from __future__ import unicode_literals from pybooru import Pybooru client = Pybooru('Konachan') posts = client.posts_list('blue_eyes', 10) for post in posts: print("URL imagen: {0}".format(post['file_url']))
# -*- coding: utf-8 -*- from __future__ import unicode_literals from pybooru import Pybooru client = Pybooru("Konachan") posts = client.posts_list("blue_eyes", 10) for post in posts: print("URL imagen: {0}".format(post["file_url"]))