<commit_before># -*- coding: utf-8 -*-

"""pybooru.api_danbooru

This module contains all API calls of Danbooru.

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

# __future__ imports
from __future__ import absolute_import

# pybooru imports
from .exceptions import PybooruAPIError


class DanbooruApi_Mixin(object):
    """Contains all Danbooru API calls.

    * API Version commit: 9996030
    * Doc: https://danbooru.donmai.us/wiki_pages/43568
    """

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

        Parameters:
            limit (int): How many posts you want to retrieve. There is a hard
                         limit of 100 posts per request.
            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.
            md5 (str): The md5 of the image to search for.
            random (bool): Can be: True, False.
            raw (bool): When this parameter is set the tags parameter will not
                        be parsed for aliased tags, metatags or multiple tags,
                        and will instead be parsed as a single literal tag.
        """
        return self._get('posts.json', params)

    def post_show(self, post_id):
        """Get a post.

        Parameters:
            post_id (int): Where post_id is the post id.
        """
        return self._get('posts/{0}.json'.format(post_id))

    def post_update(self, post_id, tag_string=None, rating=None, source=None,
                    parent_id=None, has_embedded_notes=None,
                    is_rating_locked=None, is_note_locked=None,
                    is_status_locked=None):
        """Update a specific post (Requires login).

        Parameters:
            post_id (int): The id number of the post to update.
            tag_string (str): A space delimited list of tags.
            rating (str): The rating for the post. Can be: safe, questionable,
                          or explicit.
            source (str): If this is a URL, Danbooru will download the file.
            parent_id (int): The ID of the parent post.
            has_embedded_notes (int): Can be 1, 0.
            is_rating_locked (int): Can be: 0, 1 (Builder+ only).
            is_note_locked (int): Can be: 0, 1 (Builder+ only).
            is_status_locked (int): Can be: 0, 1 (Admin only).
        """
        params = {
            'post[tag_string]': tag_string,
            'post[rating]': rating,
            'ost[source]': source,
            'post[parent_id]': parent_id,
            'post[has_embedded_notes]': has_embedded_notes,
            'post[is_rating_locked]': is_rating_locked,
            'post[is_note_locked]': is_note_locked,
            'post[is_status_locked]': is_status_locked
            }
        return self._get('posts/{0}.json'.format(post_id), params, 'PUT',
                         auth=True)

    def post_revert(self, post_id, version_id):
        """Function to reverts a post to a previous version (Requires login).

        Parameters:
            post_id (int):
            version_id (int): The post version id to revert to.
        """
        return self._get('posts/{0}/revert.json'.format(post_id),
                         {'version_id': version_id}, 'PUT', auth=True)

    def post_copy_notes(self, post_id, other_post_id):
        """Function to copy notes (requires login).

        Parameters:
            post_id (int):
            other_post_id (int): The id of the post to copy notes to.
        """
        return self._get('posts/{0}/copy_notes.json'.format(post_id),
                         {'other_post_id': other_post_id}, 'PUT', auth=True)

    def post_mark_translated(self, post_id, check_translation,
                             partially_translated):
        """Mark post as translated (Requires login) (UNTESTED).

        If you set check_translation and partially_translated to 1 post will
        be tagged as 'translated_request'

        Parameters:
            post_id (int):
            check_translation (int): Can be 0, 1.
            partially_translated (int): Can be 0, 1
        """
        param = {
            'post[check_translation]': check_translation,
            'post[partially_translated]': partially_translated
            }
        return self._get('posts/{0}/mark_as_translated.json'.format(post_id),
                         param, method='PUT', auth=True)

    def post_vote(self, post_id, score):
        """Action lets you vote for a post (Requires login).
        Danbooru: Post votes/create.

        Parameters:
            post_id (int):
            score (str): Can be: up, down.
        """
        return self._get('posts/{0}/votes.json'.format(post_id),
                         {'score': score}, 'POST', auth=True)

    def post_unvote(self, post_id):
        """Action lets you unvote for a post (Requires login).

        Parameters:
            post_id (int):
        """
        return self._get('posts/{0}/unvote.json'.format(post_id),
                         method='PUT', auth=True)

    def post_flag_list(self, creator_id=None, creator_name=None, post_id=None,
                       reason_matches=None, is_resolved=None, category=None):
        """Function to flag a post (Requires login).

        Parameters:
            creator_id (int): The user id of the flag's creator.
            creator_name (str): The name of the flag's creator.
            post_id (int): The post id if the flag.
        """
        params = {
            'search[creator_id]': creator_id,
            'search[creator_name]': creator_name,
            'search[post_id]': post_id,
            }
        return self._get('post_flags.json', params, auth=True)

    def post_flag_show(self, flag_id):
        """Show specific flagged post (Requires login).

        Parameters:
            flag_id (int):
        """
        return self._get('post_appeals/{0}.json'.format(flag_id), auth=True)

    def post_flag_create(self, post_id, reason):
        """Function to flag a post.

        Parameters:
            post_id (int): The id of the flagged post.
            reason (str): The reason of the flagging.
        """
        params = {'post_flag[post_id]': post_id, 'post_flag[reason]': reason}
        return self._get('post_flags.json', params, 'POST', auth=True)

    def post_appeals_list(self, creator_id=None, creator_name=None,
                          post_id=None):
        """Function to return list of appeals (Requires login).

        Parameters:
            creator_id (int): The user id of the appeal's creator.
            creator_name (str): The name of the appeal's creator.
            post_id (int): The post id if the appeal.
        """
        params = {
            'creator_id': creator_id,
            'creator_name': creator_name,
            'post_id': post_id
            }
        return self._get('post_appeals.json', params, auth=True)

    def post_appeals_show(self, appeal_id):
        """Show a specific post appeal (Requires login) (UNTESTED).

        Parameters:
            appeal_id:
        """
        return self._get('post_appeals/{0}.json'.format(appeal_id), auth=True)

    def post_appeals_create(self, post_id, reason):
        """Function to create appeals (Requires login).

        Parameters:
            post_id (int): The id of the appealed post.
            reason (str) The reason of the appeal.
        """
        params = {'post_appeal[post_id]': post_id,
                  'post_appeal[reason]': reason}
        return self._get('post_appeals.json', params, 'POST', auth=True)

    def post_versions_list(self, updater_name=None, updater_id=None,
                           post_id=None, start_id=None):
        """Get list of post versions.

        Parameters:
            updater_name (str):
            updater_id (int):
            post_id (int):
            start_id (int):
        """
        params = {
            'search[updater_name]': updater_name,
            'search[updater_id]': updater_id,
            'search[post_id]': post_id,
            'search[start_id]': start_id
            }
        return self._get('post_versions.json', params)

    def post_versions_show(self, version_id):
        """Show a specific post version (UNTESTED).

        Parameters:
            version_id (int):
        """
        return self._get('post_versions/{0}.json'.format(version_id))

    def post_versions_undo(self, version_id):
        """Undo post version (Requires login) (UNTESTED).

        Parameters:
            version_id (int):
        """
        return self._get('post_versions/{0}/undo.json'.format(version_id),
                         method='PUT', auth=True)

    def count_posts(self, tags=None):
        """Show the number of posts on Danbooru or a specific tag search.

        Parameters:
            tags (str):
        """
        return self._get("counts/posts.json", {"tags": tags})

    def upload_list(self, uploader_id=None, uploader_name=None, source=None):
        """Search and eturn a uploads list (Requires login).

        Parameters:
            uploader_id (int): The id of the uploader.
            uploader_name (str): The name of the uploader.
            source (str): The source of the upload (exact string match).
        """
        params = {
            'search[uploader_id]': uploader_id,
            'search[uploader_name]': uploader_name,
            'search[source]': source
            }
        return self._get('uploads.json', params, auth=True)

    def upload_show(self, upload_id):
        """Get a upload (Requires login).

        Parameters:
            upload_id (int):<commit_msg>Fix spelling mistakes in api_pybooru docstrings<commit_after># -*- coding: utf-8 -*-

"""pybooru.api_danbooru

This module contains all API calls of Danbooru.

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

# __future__ imports
from __future__ import absolute_import

# pybooru imports
from .exceptions import PybooruAPIError


class DanbooruApi_Mixin(object):
    """Contains all Danbooru API calls.

    * API Version commit: 9996030
    * Doc: https://danbooru.donmai.us/wiki_pages/43568
    """

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

        Parameters:
            limit (int): How many posts you want to retrieve. There is a hard
                         limit of 100 posts per request.
            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.
            md5 (str): The md5 of the image to search for.
            random (bool): Can be: True, False.
            raw (bool): When this parameter is set the tags parameter will not
                        be parsed for aliased tags, metatags or multiple tags,
                        and will instead be parsed as a single literal tag.
        """
        return self._get('posts.json', params)

    def post_show(self, post_id):
        """Get a post.

        Parameters:
            post_id (int): Where post_id is the post id.
        """
        return self._get('posts/{0}.json'.format(post_id))

    def post_update(self, post_id, tag_string=None, rating=None, source=None,
                    parent_id=None, has_embedded_notes=None,
                    is_rating_locked=None, is_note_locked=None,
                    is_status_locked=None):
        """Update a specific post (Requires login).

        Parameters:
            post_id (int): The id number of the post to update.
            tag_string (str): A space delimited list of tags.
            rating (str): The rating for the post. Can be: safe, questionable,
                          or explicit.
            source (str): If this is a URL, Danbooru will download the file.
            parent_id (int): The ID of the parent post.
            has_embedded_notes (int): Can be 1, 0.
            is_rating_locked (int): Can be: 0, 1 (Builder+ only).
            is_note_locked (int): Can be: 0, 1 (Builder+ only).
            is_status_locked (int): Can be: 0, 1 (Admin only).
        """
        params = {
            'post[tag_string]': tag_string,
            'post[rating]': rating,
            'ost[source]': source,
            'post[parent_id]': parent_id,
            'post[has_embedded_notes]': has_embedded_notes,
            'post[is_rating_locked]': is_rating_locked,
            'post[is_note_locked]': is_note_locked,
            'post[is_status_locked]': is_status_locked
            }
        return self._get('posts/{0}.json'.format(post_id), params, 'PUT',
                         auth=True)

    def post_revert(self, post_id, version_id):
        """Function to reverts a post to a previous version (Requires login).

        Parameters:
            post_id (int):
            version_id (int): The post version id to revert to.
        """
        return self._get('posts/{0}/revert.json'.format(post_id),
                         {'version_id': version_id}, 'PUT', auth=True)

    def post_copy_notes(self, post_id, other_post_id):
        """Function to copy notes (requires login).

        Parameters:
            post_id (int):
            other_post_id (int): The id of the post to copy notes to.
        """
        return self._get('posts/{0}/copy_notes.json'.format(post_id),
                         {'other_post_id': other_post_id}, 'PUT', auth=True)

    def post_mark_translated(self, post_id, check_translation,
                             partially_translated):
        """Mark post as translated (Requires login) (UNTESTED).

        If you set check_translation and partially_translated to 1 post will
        be tagged as 'translated_request'

        Parameters:
            post_id (int):
            check_translation (int): Can be 0, 1.
            partially_translated (int): Can be 0, 1
        """
        param = {
            'post[check_translation]': check_translation,
            'post[partially_translated]': partially_translated
            }
        return self._get('posts/{0}/mark_as_translated.json'.format(post_id),
                         param, method='PUT', auth=True)

    def post_vote(self, post_id, score):
        """Action lets you vote for a post (Requires login).
        Danbooru: Post votes/create.

        Parameters:
            post_id (int):
            score (str): Can be: up, down.
        """
        return self._get('posts/{0}/votes.json'.format(post_id),
                         {'score': score}, 'POST', auth=True)

    def post_unvote(self, post_id):
        """Action lets you unvote for a post (Requires login).

        Parameters:
            post_id (int):
        """
        return self._get('posts/{0}/unvote.json'.format(post_id),
                         method='PUT', auth=True)

    def post_flag_list(self, creator_id=None, creator_name=None, post_id=None,
                       reason_matches=None, is_resolved=None, category=None):
        """Function to flag a post (Requires login).

        Parameters:
            creator_id (int): The user id of the flag's creator.
            creator_name (str): The name of the flag's creator.
            post_id (int): The post id if the flag.
        """
        params = {
            'search[creator_id]': creator_id,
            'search[creator_name]': creator_name,
            'search[post_id]': post_id,
            }
        return self._get('post_flags.json', params, auth=True)

    def post_flag_show(self, flag_id):
        """Show specific flagged post (Requires login).

        Parameters:
            flag_id (int):
        """
        return self._get('post_appeals/{0}.json'.format(flag_id), auth=True)

    def post_flag_create(self, post_id, reason):
        """Function to flag a post.

        Parameters:
            post_id (int): The id of the flagged post.
            reason (str): The reason of the flagging.
        """
        params = {'post_flag[post_id]': post_id, 'post_flag[reason]': reason}
        return self._get('post_flags.json', params, 'POST', auth=True)

    def post_appeals_list(self, creator_id=None, creator_name=None,
                          post_id=None):
        """Function to return list of appeals (Requires login).

        Parameters:
            creator_id (int): The user id of the appeal's creator.
            creator_name (str): The name of the appeal's creator.
            post_id (int): The post id if the appeal.
        """
        params = {
            'creator_id': creator_id,
            'creator_name': creator_name,
            'post_id': post_id
            }
        return self._get('post_appeals.json', params, auth=True)

    def post_appeals_show(self, appeal_id):
        """Show a specific post appeal (Requires login) (UNTESTED).

        Parameters:
            appeal_id:
        """
        return self._get('post_appeals/{0}.json'.format(appeal_id), auth=True)

    def post_appeals_create(self, post_id, reason):
        """Function to create appeals (Requires login).

        Parameters:
            post_id (int): The id of the appealed post.
            reason (str) The reason of the appeal.
        """
        params = {'post_appeal[post_id]': post_id,
                  'post_appeal[reason]': reason}
        return self._get('post_appeals.json', params, 'POST', auth=True)

    def post_versions_list(self, updater_name=None, updater_id=None,
                           post_id=None, start_id=None):
        """Get list of post versions.

        Parameters:
            updater_name (str):
            updater_id (int):
            post_id (int):
            start_id (int):
        """
        params = {
            'search[updater_name]': updater_name,
            'search[updater_id]': updater_id,
            'search[post_id]': post_id,
            'search[start_id]': start_id
            }
        return self._get('post_versions.json', params)

    def post_versions_show(self, version_id):
        """Show a specific post version (UNTESTED).

        Parameters:
            version_id (int):
        """
        return self._get('post_versions/{0}.json'.format(version_id))

    def post_versions_undo(self, version_id):
        """Undo post version (Requires login) (UNTESTED).

        Parameters:
            version_id (int):
        """
        return self._get('post_versions/{0}/undo.json'.format(version_id),
                         method='PUT', auth=True)

    def count_posts(self, tags=None):
        """Show the number of posts on Danbooru or a specific tag search.

        Parameters:
            tags (str):
        """
        return self._get("counts/posts.json", {"tags": tags})

    def upload_list(self, uploader_id=None, uploader_name=None, source=None):
        """Search and return an uploads list (Requires login).

        Parameters:
            uploader_id (int): The id of the uploader.
            uploader_name (str): The name of the uploader.
            source (str): The source of the upload (exact string match).
        """
        params = {
            'search[uploader_id]': uploader_id,
            'search[uploader_name]': uploader_name,
            'search[source]': source
            }
        return self._get('uploads.json', params, auth=True)

    def upload_show(self, upload_id):
        """Get an upload (Requires login).

        Parameters:
            upload_id (int):
{'fraction_non_alphanumeric': 0.10660959078632218, 'fraction_numerical': 0.004280691025837028, 'mean_word_length': 1.9760388231725812, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2324041', 'n_tokens_mistral': 5694, 'n_tokens_neox': 5486, 'n_words': 1604}