Skip to content
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased] - 2025-08-31

### Changed
- Switched from front-end API url to *official* REST API url for autocompletion.
- Updated documentation for `rule34Py.autocomplete`
- Updated unit tests
- Changed `API_URLS.AUTOCOMPLETE` to semi official endpoint

## [4.0.0] - 2025-08-31

Expand Down
1 change: 1 addition & 0 deletions docs/api/rule34Py/__init__.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ rule34Py
post_comment
rule34
toptag
autocomplete_tag
5 changes: 5 additions & 0 deletions docs/api/rule34Py/autocomplete_tag.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rule34Py.autocomplete_tag
=========================

.. automodule:: rule34Py.autocomplete_tag
:members:
3 changes: 1 addition & 2 deletions rule34Py/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

__base_url__ = "https://rule34.xxx/"
__api_url__ = "https://api.rule34.xxx/"
__autocomplete_url__ = "https://ac.rule34.xxx/"

class API_URLS(str, Enum):
"""rule34.xxx API endpoint URLs.
Expand All @@ -49,4 +48,4 @@ class API_URLS(str, Enum):
#: The HTML toptags URL.
TOPMAP = f"{__base_url__}index.php?page=toptags"
#: The tags autocomplete URL
AUTOCOMPLETE = f"{__autocomplete_url__}autocomplete.php?q={{q}}"
AUTOCOMPLETE = f"{__api_url__}autocomplete.php?q={{q}}"
11 changes: 10 additions & 1 deletion rule34Py/autocomplete_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
"""Provides the AutocompleteTag class used for tag suggestions from Rule34 autocomplete."""

from dataclasses import dataclass
from typing import Union

@dataclass
class AutocompleteTag:
"""Represents a tag suggestion from autocomplete.

.. important::

Do to switching from the website endpoint to the REST API endpoint, the``type`` is currently always **None**.

Parameters:
label: The full tag label including count (e.g., "hooves (95430)").
value: The clean tag value (e.g., "hooves").
Expand All @@ -33,4 +38,8 @@ class AutocompleteTag:
#: The clean tag value without count information.
value: str
#: The category of the tag (general/copyright/other).
type: str
#:
#: .. important::
#:
#: Do to switching from the website endpoint to the REST API endpoint, the``type`` is currently always **None**.
type: Union[str, None]
11 changes: 2 additions & 9 deletions rule34Py/rule34.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,12 @@ def autocomplete(self, tag_string: str) -> list[AutocompleteTag]:
""" # noqa: DOC502
params = [["q", tag_string]]
formatted_url = self._parseUrlParams(API_URLS.AUTOCOMPLETE.value, params)
response = self._get(
formatted_url,
headers={
"Referer": "https://rule34.xxx/",
"Origin": "https://rule34.xxx",
"Accept": "*/*",
},
)
response = self._get(formatted_url)
response.raise_for_status()

raw_data = response.json()
results = [
AutocompleteTag(label=item["label"], value=item["value"], type=item["type"])
AutocompleteTag(label=item["label"], value=item["value"], type=None)
for item in raw_data
]
return results
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/mock34/responses.yml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/unit/test_rule34Py.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
import importlib.metadata
import re
from typing import Union

import pytest

Expand Down Expand Up @@ -29,7 +30,7 @@ def test_rule34Py_autocomplete(rule34):
assert hasattr(first, 'type')
assert isinstance(first.label, str)
assert isinstance(first.value, str)
assert isinstance(first.type, str)
#assert isinstance(first.type, (str, Type(None)))

empty_suggestions = rule34.autocomplete("")
assert isinstance(empty_suggestions, list)
Expand Down
Loading