Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
__pycache__
.venv

# ignore local dev / util files
pybooru/resources.py

# build/dist files
build/
dist/
Expand Down
4 changes: 4 additions & 0 deletions pybooru/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
pybooru -- Main module of Pybooru, contains Pybooru class.
moebooru -- Contains Moebooru main class.
danbooru -- Contains Danbooru main class.
gelbooru -- Contains Gelbooru main class.
api_moebooru -- Contains all Moebooru API functions.
api_danbooru -- Contains all Danbooru API functions.
api_gelbooru -- Contains all Gelbooru API functions.
exceptions -- Manages and builds Pybooru errors messages.
resources -- Contains all resources for Pybooru.
"""
Expand All @@ -25,4 +27,6 @@
# pybooru imports
from .moebooru import Moebooru
from .danbooru import Danbooru
from .gelbooru import Gelbooru
from .e621 import E621
from .exceptions import (PybooruError, PybooruAPIError, PybooruHTTPError)
57 changes: 37 additions & 20 deletions pybooru/api_danbooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class DanbooruApi_Mixin(object):
* Doc: https://danbooru.donmai.us/wiki_pages/43568
"""

def post_exists(self, post_md5):
"""Check if a md5 exists in database.

Parameters:
post_md5 (str): 32 char md5 hash string ff00ff00ff00ff00ff00ff00ff00ff00.
"""
url = "{0}/{1}={2}".format(self.site_url, 'posts.json?md5', post_md5)
return self._try(url)


def post_list(self, **params):
"""Get a list of posts.

Expand Down Expand Up @@ -69,7 +79,7 @@ def post_update(self, post_id, tag_string=None, rating=None, source=None,
params = {
'post[tag_string]': tag_string,
'post[rating]': rating,
'ost[source]': source,
'post[source]': source,
'post[parent_id]': parent_id,
'post[has_embedded_notes]': has_embedded_notes,
'post[is_rating_locked]': is_rating_locked,
Expand Down Expand Up @@ -494,8 +504,8 @@ def dmail_delete(self, dmail_id):
auth=True)

def artist_list(self, query=None, artist_id=None, creator_name=None,
creator_id=None, is_active=None, is_banned=None,
empty_only=None, order=None):
creator_id=None, any_name_matches=None, is_active=None,
empty_only=None, order=None, is_banned=None, extra_params={}):
"""Get an artist of a list of artists.

Parameters:
Expand Down Expand Up @@ -528,12 +538,14 @@ def artist_list(self, query=None, artist_id=None, creator_name=None,
'search[name]': query,
'search[id]': artist_id,
'search[creator_name]': creator_name,
'search[any_name_matches]': any_name_matches,
'search[creator_id]': creator_id,
'search[is_active]': is_active,
'search[is_banned]': is_banned,
'search[empty_only]': empty_only,
'search[order]': order
}
params.update(extra_params)
return self._get('artists.json', params)

def artist_show(self, artist_id):
Expand All @@ -544,14 +556,14 @@ def artist_show(self, artist_id):
"""
return self._get('artists/{0}.json'.format(artist_id))

def artist_create(self, name, other_names_comma=None, group_name=None,
def artist_create(self, name, other_names=None, group_name=None,
url_string=None, body=None):
"""Function to create an artist (Requires login) (UNTESTED).
"""Function to create an artist (Requires login).

Parameters:
name (str):
other_names_comma (str): List of alternative names for this
artist, comma delimited.
other_names (str): List of alternative names for this
artist, space delimited.
group_name (str): The name of the group this artist belongs to.
url_string (str): List of URLs associated with this artist,
whitespace or newline delimited.
Expand All @@ -560,22 +572,22 @@ def artist_create(self, name, other_names_comma=None, group_name=None,
"""
params = {
'artist[name]': name,
'artist[other_names_comma]': other_names_comma,
'artist[other_names_string]': other_names,
'artist[group_name]': group_name,
'artist[url_string]': url_string,
'artist[body]': body,
}
return self.get('artists.json', params, method='POST', auth=True)
return self._get('artists.json', params, method='POST', auth=True)

def artist_update(self, artist_id, name=None, other_names_comma=None,
def artist_update(self, artist_id, name=None, other_names=None,
group_name=None, url_string=None, body=None):
"""Function to update artists (Requires login) (UNTESTED).

Parameters:
artist_id (str):
name (str): Artist name.
other_names_comma (str): List of alternative names for this
artist, comma delimited.
other_names (str): List of alternative names for this
artist, space delimited.
group_name (str): The name of the group this artist belongs to.
url_string (str): List of URLs associated with this artist,
whitespace or newline delimited.
Expand All @@ -584,12 +596,12 @@ def artist_update(self, artist_id, name=None, other_names_comma=None,
"""
params = {
'artist[name]': name,
'artist[other_names_comma]': other_names_comma,
'artist[other_names_string]': other_names,
'artist[group_name]': group_name,
'artist[url_string]': url_string,
'artist[body]': body
'artist[notes]': body
}
return self .get('artists/{0}.json'.format(artist_id), params,
return self._get('artists/{0}.json'.format(artist_id), params,
method='PUT', auth=True)

def artist_delete(self, artist_id):
Expand Down Expand Up @@ -792,7 +804,7 @@ def note_update(self, note_id, coor_x=None, coor_y=None, width=None,
'note[height]': height,
'note[body]': body
}
return self._get('notes/{0}.jso'.format(note_id), params, method='PUT',
return self._get('notes/{0}.json'.format(note_id), params, method='PUT',
auth=True)

def note_delete(self, note_id):
Expand Down Expand Up @@ -988,7 +1000,7 @@ def pool_versions(self, updater_id=None, updater_name=None, pool_id=None):
return self._get('pool_versions.json', params)

def tag_list(self, name_matches=None, name=None, category=None,
hide_empty=None, has_wiki=None, has_artist=None, order=None):
hide_empty=None, has_wiki=None, has_artist=None, order=None, extra_params={}):
"""Get a list of tags.

Parameters:
Expand All @@ -1014,6 +1026,7 @@ def tag_list(self, name_matches=None, name=None, category=None,
'search[has_artist]': has_artist,
'search[order]': order
}
params.update(extra_params)
return self._get('tags.json', params)

def tag_show(self, tag_id):
Expand All @@ -1033,23 +1046,27 @@ def tag_update(self, tag_id, category):
character respectively).
"""
param = {'tag[category]': category}
return self._get('pools/{0}.json'.format(tag_id), param, method='PUT',
return self._get('tags/{0}.json'.format(tag_id), param, method='PUT',
auth=True)

def tag_aliases(self, name_matches=None, antecedent_name=None,
tag_id=None):
def tag_aliases(self, name_matches=None, antecedent_name=None, category=None,
tag_id=None, extra_params={}):
"""Get tags aliases.

Parameters:
name_matches (str): Match antecedent or consequent name.
antecedent_name (str): Match antecedent name (exact match).
category (str): Can be: 0, 1, 3, 4 (general, artist, copyright,
character respectively).
tag_id (int): The tag alias id.
"""
params = {
'search[name_matches]': name_matches,
'search[antecedent_name]': antecedent_name,
'search[category]': category,
'search[id]': tag_id
}
params.update(extra_params)
return self._get('tag_aliases.json', params)

def tag_implications(self, name_matches=None, antecedent_name=None,
Expand Down
127 changes: 127 additions & 0 deletions pybooru/api_e621.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-

"""pybooru.api_danbooru

This module contains all API calls of E621.

Classes:
E621Api_Mixin -- Contains all API endspoints.
"""

# __future__ imports
from __future__ import absolute_import

class E621Api_Mixin(object):
"""Contains all E621 API calls.
* API Version commit: ?
* Doc: https://e621.net/help/api#posts
"""

def post_list(self, **params):
"""Get a list of posts.

Parameters:
page (int): The page number.
tags (str): The tags to search for. Any tag combination that works
on the web site will work here. This includes all the
meta-tags.
"""

return self._get('posts.json', params)


def tag_list(self, name=None, category=None, order=None, hide_empty=None, has_wiki=None, has_artist=None, extra_params={}):
"""Get a list of tags.

Parameters:
name_matches (str): A tag name expression to match against
category (int): Filters results to a particular category
order (str): date/count/name
has_wiki (str): Show only tags with wiki, true/false
has_artist (str): true/false

"""
params = {
'search[name_matches]': name,
'search[category]': category,
'search[order]': order,
'search[hide_empty]': hide_empty,
'search[has_wiki]': has_wiki,
'search[has_artist]': has_artist,
}
params.update(extra_params)
return self._get('tags.json', params)



def artist_list(self, query=None, artist_id=None, creator_name=None,
creator_id=None, any_name_matches=None, is_active=None,
empty_only=None, order=None, is_banned=None, extra_params={}):
"""Get an artist of a list of artists.

Parameters:
query (str):
This field has multiple uses depending on what the query starts
with:
'http:desired_url':
Search for artist with this URL.
'name:desired_url':
Search for artists with the given name as their base name.
'other:other_name':
Search for artists with the given name in their other
names.
'group:group_name':
Search for artists belonging to the group with the given
name.
'status:banned':
Search for artists that are banned. else Search for the
given name in the base name and the other names.
artist_id (id): The artist id.
creator_name (str): Exact creator name.
creator_id (id): Artist creator id.
is_active (bool): Can be: true, false
is_banned (bool): Can be: true, false
empty_only (True): Search for artists that have 0 posts. Can be:
true
order (str): Can be: name, updated_at.
"""
params = {
'search[name]': query,
'search[id]': artist_id,
'search[creator_name]': creator_name,
'search[any_name_matches]': any_name_matches,
'search[creator_id]': creator_id,
'search[is_active]': is_active,
'search[is_banned]': is_banned,
'search[empty_only]': empty_only,
'search[order]': order
}
params.update(extra_params)
return self._get('artists.json', params)

def wiki_list(self, title=None, creator_id=None, body_matches=None,
other_names_match=None, creator_name=None, hide_deleted=None,
other_names_present=None, order=None):
"""Function to retrieves a list of every wiki page.

Parameters:
title (str): Page title.
creator_id (int): Creator id.
body_matches (str): Page content.
other_names_match (str): Other names.
creator_name (str): Creator name.
hide_deleted (str): Can be: yes, no.
other_names_present (str): Can be: yes, no.
order (str): Can be: date, title.
"""
params = {
'search[title]': title,
'search[creator_id]': creator_id,
'search[body_matches]': body_matches,
'search[other_names_match]': other_names_match,
'search[creator_name]': creator_name,
'search[hide_deleted]': hide_deleted,
'search[other_names_present]': other_names_present,
'search[order]': order
}
return self._get('wiki_pages.json', params)
Loading