Example #1
0
def inline(bot, update):  #Inline Handler & Parser
    query = update.inline_query.query
    offset = update.inline_query.offset
    if offset != '':
        query = offset.split(' ', 1)[0]
        offset = int(offset.split('page=', 1)[1])
        offset += 1
        offset = ' page=' + str(offset)
    else:
        offset = ' page=1'
    if query is None:
        query = 'rating:s'
        client = Moebooru('yandere')
        posts = client.post_list(tags=query,
                                 limit=50,
                                 page=int(offset.split('page=', 1)[1]))
        lposts = len(posts)
        inlinequery = list()
        for post in posts:
            inlinequery.append(
                InlineQueryResultPhoto(type='photo',
                                       id=uuid4(),
                                       photo_url=post['sample_url'],
                                       photo_width=post['width'] * 6,
                                       photo_height=post['height'] * 6,
                                       thumb_url=post['preview_url']), )
        if lposts >= 50:
            bot.answerInlineQuery(update.inline_query.id,
                                  results=inlinequery,
                                  next_offset=query + offset)
        else:
            bot.answerInlineQuery(update.inline_query.id, results=inlinequery)
        inlinequery.clear()
    else:
        client = Moebooru('yandere')
        posts = client.post_list(tags=query,
                                 limit=50,
                                 page=int(offset.split('page=', 1)[1]))
        lposts = len(posts)
        inlinequery = list()
        for post in posts:
            inlinequery.append(
                InlineQueryResultPhoto(type='photo',
                                       id=uuid4(),
                                       photo_url=post['sample_url'],
                                       photo_width=post['width'] * 6,
                                       photo_height=post['height'] * 6,
                                       thumb_url=post['preview_url']), )
        if lposts >= 50:
            bot.answerInlineQuery(update.inline_query.id,
                                  results=inlinequery,
                                  next_offset=query + offset)
        else:
            bot.answerInlineQuery(update.inline_query.id, results=inlinequery)
        inlinequery.clear()
Example #2
0
async def info_post(tags=None):
    client = Moebooru('yandere')
    posts = client.post_list(tags=tags)
    tags = {}
    for post in posts:
        tags = post
    return tags
Example #3
0
def grab(*grab_tags:str, grab_count:int, source:str):
    client = Moebooru(site_url="https://"+source)
    posts = client.post_list(tags=grab_tags, limit=grab_count)
    count = 0
    printAwesomeASCII()
    if(len(grab_count) == 0):
            print("No grab count specified!")
            print("returning...")
            gui()
    else:
        if((float(checkDiskSpace())-(float(grab_count)*5/1024)) >= 0):
            if(not posts):
                print("There wasn't any post to grab!")
                print("returning...")
                gui()
            else:
                print("=============================================================")
                printProgressBar(0, int(grab_count), prefix = 'Progress:', suffix = 'Complete', length = 50)
                for post in posts:
                    image_url = post["file_url"]
                    image_name = image_url.split("/")[-1]
                    image_path = os.getcwd()+"/pictures/"
                    img_data = requests.get(image_url).content
                    with open(image_path+image_name, "wb") as handler:
                        handler.write(img_data)
                        count+=1
                        printProgressBar(count, int(grab_count), prefix="Progress:", suffix="Complete", length=50)
                print("=============================================================")
                print("Finished grabbing")
                gui()
        else:
            print("Not enough disk space!")
            print("returning...")
            gui()
Example #4
0
async def idd(message, tags=None):
    randomint = randint(1000, 10000000)
    try:
        client = Moebooru('yandere')
        posts = client.post_list(tags=tags)
        for post in posts:
            urllib.request.urlretrieve(
                post['file_url'],
                "tmp/NekobinRobot_" + str(randomint) + ".jpg")
        try:
            c_id = parse_data['commands'].index(lastcmd.get(message.chat.id))
        except:
            c_id = 1  # For when downloading a file from channel without using a bot prior to this, default set to rating:s
        ckeyboard = types.InlineKeyboardMarkup(row_width=1)
        text_and_data = (('→ Next', c_id), )
        row_btns = (types.InlineKeyboardButton(text,
                                               callback_data=callback_cb.new(
                                                   function=text, data=data))
                    for text, data in text_and_data)
        ckeyboard.row(*row_btns)
        reply_markup = ckeyboard
        photo = open('tmp/NekobinRobot_' + str(randomint) + ".jpg", 'rb')
        await message.answer_document(photo, reply_markup=reply_markup)
        photo.close()
        os.remove('tmp/anime_bot_' + str(randomint) + ".jpg")
    except Exception:
        traceback.print_exc()
Example #5
0
 def __init__(self, client):
     self.client = client
     self.dan_client = Danbooru('danbooru',
                                username='******',
                                api_key='PubbhbW6nutC3yiFrBCrZs7S')
     self.yan_client = Moebooru(site_url='https://yande.re',
                                username='******',
                                password='******')
     self.default_tags = ['yuri']
Example #6
0
def get_anime(update, query, filename):
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    client = Moebooru("yandere")
    max_posts_to_load = 200
    posts = client.post_list(tags=query, limit=max_posts_to_load)
    post_count = len(posts)
    random = randint(0, post_count - 1)
    image_post = "https://yande.re/post/show/" + str(posts[random]["id"])
    image_url = posts[random]["sample_url"]
    dl = requests.get(image_url)
    with open(path + filename + ".jpg", "wb") as f:
        f.write(dl.content)
    return image_post
Example #7
0
async def inline_function(inline_query: InlineQuery):
    query = inline_query.query
    offset = inline_query.offset
    if offset != '':
        query = offset.split(' ', 1)[0]
        offset = int(offset.split('page=', 1)[1])
        offset += 1
        offset = ' page=' + str(offset)
    else:
        offset = ' page=1'
    if query is None:
        query = 'rating:s'
    client = Moebooru('yandere')
    posts = client.post_list(tags=query,
                             limit=50,
                             page=int(offset.split('page=', 1)[1]))
    lposts = len(posts)
    inlinequery = list()
    for post in posts:
        inlinequery.append(
            InlineQueryResultPhoto(
                id=str(uuid4()),
                photo_url=post['sample_url'],
                photo_width=post['width'],
                photo_height=post['height'],
                thumb_url=post['preview_url'],
                caption=
                '<a href="https://t.me/NekobinRobot?start=%s">Download</a>' %
                (post['id']),
                parse_mode=ParseMode.HTML), )
    if lposts >= 50:
        await bot.answer_inline_query(inline_query.id,
                                      results=inlinequery,
                                      next_offset=query + offset)
    else:
        await bot.answer_inline_query(inline_query.id, results=inlinequery)
    inlinequery.clear()
Example #8
0
def idd(bot, update, tags=None, chat_id=None):
    randomint = randint(1000, 10000000)
    try:
        bot.sendChatAction(chat_id, "upload_document")
        try:
            client = Moebooru('yandere')
            posts = client.post_list(tags=tags)
            for post in posts:
                urllib.request.urlretrieve(
                    post['file_url'],
                    "tmp/uncensored_bot_" + str(randomint) + ".jpg")
            ckeyboard = InlineKeyboardMarkup([[
                InlineKeyboardButton("Donate", url='https://paypal.me/ev3rest')
            ], [InlineKeyboardButton("More",
                                     callback_data="{'data':'More'}")]])
            reply_markup = ckeyboard
            photo = open('tmp/uncensored_bot_' + str(randomint) + ".jpg", 'rb')
            bot.sendDocument(chat_id, photo, reply_markup=reply_markup)
            photo.close()
            os.remove('tmp/uncensored_bot_' + str(randomint) + ".jpg")
        except Exception:
            traceback.print_exc()
    except Exception:
        traceback.print_exc()
Example #9
0
from flask import request, render_template, send_from_directory, url_for
from pybooru import Danbooru, Moebooru, PybooruHTTPError
from booru_extension import Safebooru, Gelbooru

from app.posts import bp

# Commas on the left for easy commenting
clients = [
    (Moebooru('konachan'), False), (Moebooru('yandere'), False),
    (Safebooru(), True)
    #,(Gelbooru(), True) # Currently, Gelbooru commonly 404s on its own images
]


def download_posts(tags, page):
    posts = []
    errors = []
    tag_count = {}
    for client, altbooru in clients:
        postList = []
        try:
            postList = client.post_list(
                tags=tags, limit=50,
                page=page)  # change the limit to be user defined from config
        except PybooruHTTPError as err:
            errors.append("{0} error: {1}".format(client.site_url, err))
            continue

        list_of_tags = []

        for post in postList:
Example #10
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pybooru import Moebooru

client = Moebooru(site_name='Konachan')

# notes = client.note_list()
# print(notes)

# wiki = client.wiki_list(query='nice', order='date')
# for msg in wiki:
#    print("Message: {0}".format(msg['body']))

# posts = client.post_list(tags='blue_eyes', limit=2)
# for post in posts:
#    print("Image URL: {0}".format(post['file_url']))

# tags = client.tag_list()
# for tag in tags:
#    print("Tag: {0} ----- {1}".format(tag['name'], tag['type']))
Example #11
0
 def __init__(self, bot):
     self.bot = bot
     self.yandere = Moebooru('yandere')
Example #12
0
# encoding: utf-8
from __future__ import print_function
from pybooru import Danbooru
from pybooru import Moebooru

konachan = Moebooru("konachan")

kona_tags = konachan.tag_list(order='date')
print(konachan.last_call)
kona_post = konachan.post_list()
print(konachan.last_call)

danbooru = Danbooru('danbooru')

dan_tags = danbooru.tag_list(order='name')
print(danbooru.last_call)
dan_post = danbooru.post_list(tags="computer")
print(danbooru.last_call)
Example #13
0
async def parser(message,
                 tags,
                 pages,
                 chat_id,
                 info=None,
                 ch_id=None):  #Usual parser for usual commands
    global x
    randomint = randint(1000, 10000000)
    await message.bot.send_chat_action(message.chat.id,
                                       ChatActions.UPLOAD_PHOTO)
    client = Moebooru('yandere')
    try:
        randompage = randint(1, int(pages))
        if len(x[str(ch_id)]['url']) == 0:
            posts = client.post_list(tags=str(tags), page=randompage, limit=40)
            for post in posts:
                if ch_id == '9':
                    fileurl = post['file_url']
                else:
                    fileurl = post['sample_url']
                x[str(ch_id)]['url'].append(fileurl)
                x[str(ch_id)]['id'].append(post['id'])
                x[str(ch_id)]['tags'].append(post['tags'])
        else:
            ikeyboard = types.InlineKeyboardMarkup(row_width=1)
            text_and_data = (
                ('ⓘ Info', x[str(ch_id)]['id'][0]),
                ('→ Next', ch_id),
            )
            row_btns = (types.InlineKeyboardButton(
                text, callback_data=callback_cb.new(function=text, data=data))
                        for text, data in text_and_data)
            ikeyboard.row(*row_btns)
            text_and_data = (('↧ Download', x[str(ch_id)]['id'][0]), )
            row_btns = (types.InlineKeyboardButton(
                text, callback_data=callback_cb.new(function=text, data=data))
                        for text, data in text_and_data)
            ikeyboard.row(*row_btns)
            reply_markup = ikeyboard
            # if info == None:
            # 	info = ''
            # info = info + "\n" + '<a href="%s">Source</a>' % (x[str(ch_id)]['tags'][0])
            await message.answer_photo(photo=x[str(ch_id)]['url'][0],
                                       reply_markup=reply_markup,
                                       caption=info,
                                       parse_mode=ParseMode.HTML)
        try:
            x[str(ch_id)]['url'].pop(0)
        except:
            traceback.print_exc()
        try:
            x[str(ch_id)]['id'].pop(0)
        except:
            traceback.print_exc()

    except Exception:
        traceback.print_exc()
        await message.reply(
            'Oops... Something went wrong, please call the command again!')
        try:
            os.remove('tmp/NekobinRobot_' + str(randomint) + ".jpg")
        except:
            pass
        try:
            x[str(ch_id)]['url'].pop(0)
        except:
            traceback.print_exc()
        try:
            x[str(ch_id)]['id'].pop(0)
        except:
            traceback.print_exc()
Example #14
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pybooru import Moebooru

client = Moebooru('Konachan')
posts = client.post_list(tags='blue_eyes', limit=10)

for post in posts:
    print("URL image: {0}".format(post['file_url']))
Example #15
0
# encoding: utf-8
from __future__ import print_function
from pybooru import Danbooru
from pybooru import Moebooru

konachan = Moebooru("konachan")

kona_tags = konachan.tag_list(order='date')
print(konachan.last_call)
kona_post = konachan.post_list()
print(konachan.last_call)

lolibooru = Moebooru("lolibooru")

kona_tags = lolibooru.tag_list(order='date')
print(lolibooru.last_call)
kona_post = lolibooru.post_list()
print(lolibooru.last_call)

danbooru = Danbooru('danbooru')

dan_tags = danbooru.tag_list(order='name')
print(danbooru.last_call)
dan_post = danbooru.post_list(tags="computer")
print(danbooru.last_call)
Example #16
0
 def __init__(self, _tags, _pages, _booru):
     r = random.randint(1, 40 * _pages)
     client = Moebooru(_booru)
     print(_tags, _pages)
     self.posts = client.post_list(limit=1, tags=_tags, page=r)
Example #17
0
def parser(bot,
           update,
           tags,
           pages,
           chat_id,
           info=None,
           ch_id=None):  #Usual parser for usual commands
    global x
    global p_id
    randomint = randint(1000, 10000000)
    if ch_id == '9':
        bot.sendChatAction(chat_id, "upload_document")
        client = Danbooru('danbooru',
                          username='******',
                          api_key=danbooru_key)
    else:
        bot.sendChatAction(chat_id, "upload_photo")
        client = Moebooru('yandere')
    try:
        randompage = randint(1, int(pages))
        if len(x[str(ch_id)]['url']) == 0:
            posts = client.post_list(tags=str(tags), page=randompage, limit=40)
            for post in posts:
                if ch_id == '9':
                    fileurl = post['file_url']
                else:
                    fileurl = post['sample_url']
                x[str(ch_id)]['url'].append(fileurl)
                x[str(ch_id)]['id'].append(post['id'])
        if ch_id == '9':
            ikeyboard = InlineKeyboardMarkup(
                [[
                    InlineKeyboardButton("Donate",
                                         url='https://paypal.me/ev3rest')
                ],
                 [InlineKeyboardButton("Music", url='https://t.me/musicave')],
                 [
                     InlineKeyboardButton(
                         "More",
                         callback_data="{'data':'More', 'c_id':%s}" % ch_id)
                 ]])
        else:
            ikeyboard = InlineKeyboardMarkup(
                [[
                    InlineKeyboardButton("Donate",
                                         url='https://paypal.me/ev3rest')
                ],
                 [InlineKeyboardButton("Music", url='https://t.me/musicave')],
                 [
                     InlineKeyboardButton(
                         "Download",
                         callback_data="{'data':'Download', 'id':%s}" %
                         x[str(ch_id)]['id'][0])
                 ],
                 [
                     InlineKeyboardButton(
                         "More",
                         callback_data="{'data':'More', 'c_id':%s}" % ch_id)
                 ]])
        reply_markup = ikeyboard
        if ch_id != '9':
            bot.sendPhoto(chat_id,
                          photo=x[str(ch_id)]['url'][0],
                          reply_markup=reply_markup,
                          caption=info)
        else:
            bot.sendDocument(chat_id,
                             document=x[str(ch_id)]['url'][0],
                             reply_markup=reply_markup,
                             caption=info)
        try:
            x[str(ch_id)]['url'].pop(0)
        except:
            traceback.print_exc()
        try:
            x[str(ch_id)]['id'].pop(0)
        except:
            traceback.print_exc()

    except Exception:
        traceback.print_exc()
        bot.sendMessage(
            chat_id,
            'Oops... Something went wrong, please call the command again!')
        try:
            os.remove('tmp/uncensored_bot_' + str(randomint) + ".jpg")
        except:
            pass
        try:
            x[str(ch_id)]['url'].pop(0)
        except:
            traceback.print_exc()
        try:
            x[str(ch_id)]['id'].pop(0)
        except:
            traceback.print_exc()
Example #18
0
 def __init__(self):
     self.client = Moebooru(site_url=self.BASE_URL)
     self.local_cache = dict()
     self.max_page = 1e9
     self.created_tags = list()
Example #19
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pybooru import Moebooru

client = Moebooru('yandere')
wiki = client.wiki_list(body_matches='great', order='date')

for page in wiki:
    print("Message: {0}".format(page['body']))
Example #20
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pybooru import Moebooru

# replace login information
client = Moebooru('Konachan',
                  username='******',
                  password='******')
client.comment_create(post_id=id, comment_body='Comment content')

print(client.last_call)