luquedaniel / pybooru Goto Github PK
View Code? Open in Web Editor NEWPybooru is a Python package to access to the API of Danbooru/Moebooru based sites
License: MIT License
Pybooru is a Python package to access to the API of Danbooru/Moebooru based sites
License: MIT License
i can't seem to find danbooru's hot page support here but it be amazing if you add it very helpful
Create documentation for Pybooru. With Sphinx and Read the Docs.
Migrating to python 3.
Revise and refactoring all code.
pyproject.toml
setup.py
metadata to setup.cfg
setup.py
setup.py
to Python 3 only5.0.0.dev1
project_urls
metadataMANIFEST.in
Pipfile
gitignore
requirements.txt
Make a function to return information of the last call.
Well, i'm getting the next error:
[TypeError]: list indices must be integers or slices, not str
While using the Moebooru client. This is my code:
@commands.command(pass_context = True)
async def booru(self, ctx, *args):
"""Obtiene una imagen aleatoria de cualquier Booru"""
mention = '<@{}>'.format(ctx.author.id)
try:
if funcs.noMention(ctx.message):
try:
booru = args[0]
tags = list(args)
tags.pop(0)
tags = ' '.join(map(str, args))
client = Moebooru(booru, username = self.Bot.danbooru_username)
post = client.post_list(tags = tags, page = randint(1, 1000), limit = 1)
try:
image_url = post[0]['file_url']
except:
image_url = 'https://danbooru.donmai.us{}'.format(post['source'])
async with ctx.channel.typing():
embed = discord.Embed(title = 'There you go!')
embed.set_image(url = image_url)
async with ctx.channel.typing():
await ctx.channel.send('{}'.format(mention), embed = embed)
except Exception as e:
async with ctx.channel.typing():
print('Comando booru: [{}]: {}'.format(type(e).__name__, e))
await ctx.channel.send('{}, me temo que no pude conseguir una imagen.'.format(mention))
else:
await ctx.channel.send('{}, evita las menciones al utilizar este comando.'.format(mention))
except Exception as e:
print('Comando booru: [{}]: {}'.format(type(e).__name__, e))
I'm using discord.py (rewrite) and I can't find where the error is, any idea?
Add all Danbooru API functions.
Thank you for your work on the development of this very useful code! I have recently encountered an error (it was working fine before, I think that Danbooru changed something in their API)
When using two tags to access random picture:
danbo_client = Danbooru('danbooru')
picture = danbo_client.post_list(tags=_tags, limit=1, random=True)
The following error occurs:
In _request: 422 - Locked, The resource is locked and cannot be modified - URL
After checking what is happening with the link it provides, it actually contains the requested list with a JSON object. But when fetched with python results in the following error:
{
"backtrace": [],
"message": "Can't verify CSRF token authenticity.",
"success": false
}
Return of list containing JSON object
Proper behavior for 1 tag and 1 tag with rating tag. Error when inputting more than one tag.
The issue prevents from using more than one tag, excluding rating tag.
Pybooru Version: 4.2.2
Python Version: 3.8
Operating system: Windows 10
Link to your project: https://github.com/Magos-Errant/Shinsha
The Danbooru API docs mention that all searches support a common set of parameters.
None of these common parameters are supported in api_danbooru.py.
I'm specifically interested in the "page" parameter.
I am attempting to use pybooru to fetch notes for all posts [see my project Danbooru2019]. This because qwern doesn't include notes in his dataset.
Anywho, I found the note API will only return 20 notes for a given post. I.e. I'm using pybooru
as follows:
nl = client.note_list(post_id=77, is_active=True)
And this only returns 20 notes, whereas post id 77 actually has 21 notes.
So I need to be able to request pages to get all notes, e.g.:
nl = client.note_list(post_id=77, is_active=True, page=1)
if (len(nl) == 20):
nl = client.note_list(post_id=77, is_active=True, page=2)
Reworking api_danbooru.py
, note_list
as follows appears to do the trick [documentation removed for conciseness]:
def note_list(self, body_matches=None, post_id=None, post_tags_match=None,
creator_name=None, creator_id=None, is_active=None, page=1):
params = {
'search[body_matches]': body_matches,
'search[post_id]': post_id,
'search[post_tags_match]': post_tags_match,
'search[creator_name]': creator_name,
'search[creator_id]': creator_id,
'search[is_active]': is_active,
'page' : page
}
return self._get('notes.json', params)
Lines 49 to 50 in 3293755
I am running a function similar to the below after obtaining a post from client.post_list().
I've made sure that the post_id being passed is valid, and the login auth appears to be fine since other functions like favorites_list() work as expected
client = Danbooru('danbooru', username=API_USER, api_key=API_KEY)
def favoriteId(post_id):
client.favorite_add(post_id)
However, nothing appears to happen and the post is not added to favorites.
Ive been trying to add multiple tags for danbooru and I figured it was one of the following:
tags='tag1 tag2'
tags='tag1', 'tag2'
tags=["tag1", "tag2"]
Which it was none of, im greatly confused on this issue and any information would help.
Along with that this one is more simple, but I have no clue on how to declare the site name for moebooru.
Actually, nvm it was just the tag I was using but why doesnt it work?
Revise and improve packaging method.
It seems that in a recent update the way file uploads are handled is changed in Danbooru? There is some support for bulk uploading, and there are some other changes surrounding this.
I tried the following code:
from pybooru import Danbooru
client = Danbooru(site_url='---my-selfhosted-danboory-url---', username='--my-username---', api_key='---api-key---')
client.upload_create('some tags here', 's', file_='C:/images/76a88b52a8f5c825c2ade9486127b953.jpg')
File is uploaded and posted with the given tags
Fails.
I printed the response:
{'_content': b'{"success":false,"error":"ActionController::UnpermittedParameters","message":"found unpermitted parameters: :rating, :tag_string, :file","backtrace":["app/controllers/uploads_controller.rb:13:in `create\'"]}
The api key has all access rights and I am "owner" on the board. I can perform all these tasks through the website; but not through the api. I should mention that other scripts and online sources for uploading also fail. I really think danbooru changed something recently.
If needed I can provide my danbooru installation (i can share details in private) for testing. Since it is early in it's hosting cycle you don't have to worry about posting a mess; I will just clean it up.
Cannot parse data from Yande.re and Konachan.com
Ex. of problem:
PybooruHTTPError: In _request: 404 - Not Found, Not found - URL: https://yande.re/posts.json?random=True&limit=1
Works with Danbooru, but not with yandere and konachan, for yandere and konachan it should be "post.json" not "posts.json".
Cannot parse data from Yande.re
<telegram.utils.promise.Promise object at 0x7fa70014ebe0>
'In _json_request: 404, Not Found - Not found -- URL: https://yande.re/post.json'
I was wondering if you had any plans on moving the library to asyncio and aiohttp, and in general putting effort into making the library asynchronous? Thank you, Daniel!
I am having an issue with the favorite_remove() function. It will remove the favorite as expected, but it throws an error while doing it. When I refresh my favorites the post is no longer there, but it'd be nice to not see the error.
from pybooru import Danbooru
client = Danbooru('danbooru', username=$USERNAME, api_key=$API_KEY')
post_id = $POST # as an int
client.favorite_remove(post_id)
I get the following error:
Traceback (most recent call last):
File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/pybooru/pybooru.py", line 179, in _request
return response.json()
File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/home/ryan/.pyenv/versions/3.8.0/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/home/ryan/.pyenv/versions/3.8.0/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/ryan/.pyenv/versions/3.8.0/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3343, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-102-8ebb0139f2f3>", line 1, in <module>
client.favorite_remove(3694909)
File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/pybooru/api_danbooru.py", line 437, in favorite_remove
return self._get('favorites/{0}.json'.format(post_id), method='DELETE',
File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/pybooru/danbooru.py", line 86, in _get
return self._request(url, api_call, request_args, method)
File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/pybooru/pybooru.py", line 185, in _request
raise PybooruError("JSON Error: {0} in line {1} column {2}".format(
pybooru.exceptions.PybooruError: JSON Error: Expecting value in line 1 column 1
Replace urllib/urllib2 for Requests.
Small chages in README.markdown.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.