diff --git a/hatenadir/ds/v2-xx/search.py b/hatenadir/ds/v2-xx/search.py new file mode 100644 index 0000000..a2b2f94 --- /dev/null +++ b/hatenadir/ds/v2-xx/search.py @@ -0,0 +1,29 @@ +from twisted.web import resource + +from hatena import NotFound, as_text +from reximemo import search_keyboard_response + + +class PyResource(resource.Resource): + isLeaf = False + + def getChild(self, name, request): + scope = as_text(name) + if scope in {"flipnotes.kbd", "creators.kbd"}: + return SearchKeyboard(scope.split(".", 1)[0]) + return NotFound + + +class SearchKeyboard(resource.Resource): + isLeaf = True + + def __init__(self, scope): + super().__init__() + self.scope = scope + + def render_POST(self, request): + return search_keyboard_response(request, self.scope) + + def render_GET(self, request): + request.setResponseCode(405) + return b""