refactor project structure

This commit is contained in:
Denis-Cosmin Nutiu 2024-01-30 23:03:27 +02:00
parent 3098368194
commit 748d3cd522
6 changed files with 20 additions and 11 deletions

View file

@ -1,10 +1,13 @@
"""
Pathfinder Archive of Nethys (AON) commands.
"""
import datetime import datetime
import disnake import disnake
import re import re
from disnake.ext import commands from disnake.ext import commands
from src.knowledge.pathfinder_archive_of_nethys import PathfinderArchiveOfNethysClient from src.knowledge.pathfinder.archive_of_nethys import ArchiveOfNethysClient
async def pathfinder_aon_lookup_autocomplete( async def pathfinder_aon_lookup_autocomplete(
@ -13,7 +16,7 @@ async def pathfinder_aon_lookup_autocomplete(
""" """
Autocompletes pathfinder archive of nethys queries. Autocompletes pathfinder archive of nethys queries.
""" """
async with PathfinderArchiveOfNethysClient() as aon_client: async with ArchiveOfNethysClient() as aon_client:
if user_input == "": if user_input == "":
return [ return [
"(archetype-182) Zombie", "(archetype-182) Zombie",
@ -59,7 +62,7 @@ class PathfinderArchiveOfNethysCog(commands.Cog):
""" """
Looks up a page on Archive of Nethys. Looks up a page on Archive of Nethys.
""" """
async with PathfinderArchiveOfNethysClient() as aon_client: async with ArchiveOfNethysClient() as aon_client:
match = re.match(self._id_regex, query) match = re.match(self._id_regex, query)
if match: if match:
data = await aon_client.search_page_by_id(document_id=match.groups()[0]) data = await aon_client.search_page_by_id(document_id=match.groups()[0])

View file

@ -1,3 +1,6 @@
"""
Dice commands.
"""
import typing import typing
from datetime import datetime from datetime import datetime

View file

@ -1,7 +1,10 @@
"""
Pathfinder Wiki commands.
"""
import disnake import disnake
from disnake.ext import commands from disnake.ext import commands
from src.knowledge.pathfinder_wiki import PathfinderWikiClient from src.knowledge.pathfinder.wiki import PathfinderWikiClient
async def pathfinder_wiki_lookup_autocomplete( async def pathfinder_wiki_lookup_autocomplete(

View file

View file

@ -6,7 +6,7 @@ import aiohttp
@dataclasses.dataclass @dataclasses.dataclass
class PathfinderArchiveOfNethysDocument: class ArchiveOfNethysDocument:
""" """
Represents an essential document for Archive of Nethys. Represents an essential document for Archive of Nethys.
""" """
@ -17,7 +17,7 @@ class PathfinderArchiveOfNethysDocument:
url: str url: str
class PathfinderArchiveOfNethysClient: class ArchiveOfNethysClient:
""" """
Simple PathfinderWikiClient Simple PathfinderWikiClient
""" """
@ -38,7 +38,7 @@ class PathfinderArchiveOfNethysClient:
async def search_page_by_id( async def search_page_by_id(
self, document_id: str self, document_id: str
) -> typing.Optional[PathfinderArchiveOfNethysDocument]: ) -> typing.Optional[ArchiveOfNethysDocument]:
""" """
Searches the Archive of Nethys by an id. Searches the Archive of Nethys by an id.
:param document_id: - The document id. :param document_id: - The document id.
@ -66,7 +66,7 @@ class PathfinderArchiveOfNethysClient:
) as response: ) as response:
result = await response.json() result = await response.json()
for item in result.get("hits", {}).get("hits", []): for item in result.get("hits", {}).get("hits", []):
return PathfinderArchiveOfNethysDocument( return ArchiveOfNethysDocument(
id=item.get("_id"), id=item.get("_id"),
name=item.get("fields", {}).get("name", ["Unknown"])[0], name=item.get("fields", {}).get("name", ["Unknown"])[0],
text=item.get("fields", {}).get("text", ["Unknown"])[0], text=item.get("fields", {}).get("text", ["Unknown"])[0],
@ -75,7 +75,7 @@ class PathfinderArchiveOfNethysClient:
async def search_pages( async def search_pages(
self, query: str, size: int = 10 self, query: str, size: int = 10
) -> list[PathfinderArchiveOfNethysDocument]: ) -> list[ArchiveOfNethysDocument]:
""" """
Searches the Archive of Nethys pages Searches the Archive of Nethys pages
:param query: The search query. :param query: The search query.
@ -103,7 +103,7 @@ class PathfinderArchiveOfNethysClient:
result = await response.json() result = await response.json()
for item in result.get("hits", {}).get("hits", []): for item in result.get("hits", {}).get("hits", []):
found_items.append( found_items.append(
PathfinderArchiveOfNethysDocument( ArchiveOfNethysDocument(
id=item.get("_id"), id=item.get("_id"),
name=item.get("fields", {}).get("name", ["Unknown"])[0], name=item.get("fields", {}).get("name", ["Unknown"])[0],
text=item.get("fields", {}).get("text", ["Unknown"])[0], text=item.get("fields", {}).get("text", ["Unknown"])[0],
@ -124,7 +124,7 @@ class PathfinderArchiveOfNethysClient:
if __name__ == "__main__": if __name__ == "__main__":
pf = PathfinderArchiveOfNethysClient() pf = ArchiveOfNethysClient()
result = asyncio.run(pf.search_pages("zom")) result = asyncio.run(pf.search_pages("zom"))
print(result) print(result)
for item in result: for item in result: