예제 #1
1
파일: list_tags.py 프로젝트: lleene/pybooru
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pybooru import Danbooru

client = Danbooru('danbooru')
tags = client.tag_list(order='date')

for tag in tags:
    print("Tag: {0} ----- {1}".format(tag['name'], tag['category']))
예제 #2
0
def get_from_danbooru(char_name, anime_name):
    full_tag = char_name + " (" + anime_name + ")"
    #print(full_tag)
    client = Danbooru('danbooru')
    #getting full tag AKA Character_Nme(Anime Name) format
    tags = client.tag_list(name_matches=full_tag,
                           hide_empty="yes",
                           order="count")
    print(tags)
    tag = ""
    #Checking if there were no search results, and then getting tags with merely the character name
    if (len(tags) == 0):
        tags = client.tag_list(name_matches=char_name,
                               hide_empty="yes",
                               order="count")

    if (len(tags) == 0):
        #searching for last name, first name format, if the other doesn't work
        reverse_name = ""
        name = char_name.split(' ')
        n = len(name) - 1
        while (n >= 0):
            reverse_name = reverse_name + " " + name[n]
            n -= 1

        print(reverse_name)

        tags = client.tag_list(name_matches=reverse_name,
                               hide_empty="yes",
                               order="count")

    for x in tags:
        if len(x) != 0:
            tag = x["name"]
            break
    print(tag)

    #get posts for tag.
    posts = client.post_list(tags=tag, random=True, raw=True)
    #print(posts[0]['large_file_url'])
    return posts
예제 #3
0
def get_from_danbooru_by_tag(tag):
    client = Danbooru('danbooru')
    tags = client.tag_list(name_matches=tag, hide_empty="yes", order="count")
    tag = ""
    for x in tags:
        if len(x) != 0:
            #making sure that the particular tag isn't empty. If it is, then a random image is displayed.
            tag = x["name"]
            break

    #got the tags. Now what? Images!

    posts = client.post_list(tags=tag, random=True, raw=True)
    return posts
예제 #4
0
def send_found_photos(message):
    msg_args = message.text.split(' ')

    POST_PER_REQUEST = 200

    bot.send_message(message.chat.id, 'Начинаю...')

    tag_names = msg_args[1]
    client = Danbooru('danbooru')
    total_posts = client.tag_list(name=tag_names)[0]['post_count']

    pages_found = (total_posts // POST_PER_REQUEST) + 1
    params = {'limit': total_posts, 'tags': tag_names, 'page': None}
    for page in range(1, pages_found + 1):
        params['page'] = page
        founded_posts = client.post_list(**params)
        for post in founded_posts:
            if not 'file_url' in post.keys():
                continue
            file_url = post['file_url']
            response = requests.get(file_url)
            file_content = response.content
            bot.send_photo(message.chat.id, file_content)
예제 #5
0
class Danbooru(commands.Cog):
    """Commands for Danbooru integration"""
    def __init__(self, bot):
        self.bot = bot
        self.client = Client('danbooru')

    @commands.group(aliases=['db'],
                    pass_context=True,
                    invoke_without_command=True)
    @commands.cooldown(1, 5, commands.BucketType.member)
    async def danbooru(self, ctx, *, query: str):
        """Return a random image from danbooru"""
        exceptions = (custom_exceptions.NSFWException,
                      custom_exceptions.ResourceNotFound,
                      custom_exceptions.Error, Exception)
        try:
            adapted_query = check_query(query)
            post = self.client.post_list(tags='rating:safe ' + adapted_query,
                                         limit=1,
                                         random=True)
            embed = discord.Embed(color=discord.Colour.red()).set_image(
                url=return_valid_image(post))
            await ctx.message.add_reaction('\U00002705')
            await ctx.send(embed=embed)
        except exceptions as e:
            await ctx.message.add_reaction('\U0000274c')
            await ctx.send(e, delete_after=10)

    @danbooru.command(aliases=['n'])
    @commands.cooldown(1, 5, commands.BucketType.member)
    async def nsfw(self, ctx, *, query: str):
        """Return a random NSFW image from danbooru"""
        exceptions = (custom_exceptions.NSFWException,
                      custom_exceptions.ResourceNotFound,
                      custom_exceptions.Error, Exception)
        try:
            check_nsfw(ctx)
            adapted_query = check_nsfw_query(query)
            post = self.client.post_list(tags=adapted_query,
                                         limit=1,
                                         random=True)
            embed = discord.Embed(color=discord.Colour.red()).set_image(
                url=return_valid_image(post))
            await ctx.message.add_reaction('\U00002705')
            await ctx.send(embed=embed)
        except exceptions as e:
            await ctx.message.add_reaction('\U0000274c')
            await ctx.send(e, delete_after=10)

    @danbooru.command(aliases=['t'])
    @commands.cooldown(1, 5, commands.BucketType.member)
    async def tags(self, ctx, *, query: str):
        """Return name matches from your query"""
        exceptions = (custom_exceptions.ResourceNotFound, Exception)
        try:
            list_tags = self.client.tag_list(name_matches=query)
            tags = return_tags(list_tags)
            pages = Pages(ctx, lines=tags)
            await ctx.message.add_reaction('\U00002705')
            await pages.paginate()
        except exceptions as e:
            await ctx.message.add_reaction('\U0000274c')
            await ctx.send(e, delete_after=10)
예제 #6
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)
예제 #7
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)