Source code for asyncdagpi.objects

import json
from typing import Dict, Any, List, Optional


[docs]class BaseDagpiObject: """ Base AsyncDagpi object .. container:: Attributes **Attributes** dict: :class:`Dict` """ def __init__(self, dictionary: Dict[str, Any]): """ Initialise a BaseDagpiObject """ self.dict: Dict[str, Any] = dictionary def __str__(self) -> str: """ Returns a string of the data :returns :class:`str` """ return json.dumps(self.dict)
[docs] def raw_data(self) -> Dict[str, Any]: """ Dictionary with Raw Data :returns :class:`Dict` """ return self.dict
[docs]class PickupLine(BaseDagpiObject): """ A Dagpi PickupLine .. container:: Attributes **Attributes** dict: :class:`Dict` Dictionary with raw data (same returned by raw_data) category: :class:`str` String containing Type of Pickup Line line: :class:`str` String Containing Pickup Line """ def __init__(self, data: Dict[str, str]): super(PickupLine, self).__init__(data) self.dict: Dict[str, str] = data self.category: str = data["category"] self.line: str = data["joke"]
# class Pokemon(TypedDict): # abilities: List[str] # ascii: str # height: float # id: int # link: str # name: str # type: List[str] # weight: float
[docs]class WTP(BaseDagpiObject): """ A Dagpi PickupLine. A subclass of AsyncDagpi object .. container:: Attributes **Attributes** dict: :class:`Dict` Dictionary with raw data (same returned by raw_data) abilities: :class:`List[str]` A list containing the abilities the pokemon has ascii: :class:`str` String containing ascii data of pokemons image height: :class:`float` Float with height of pokemon weight: :class:`float` Float with weight of pokemon id: :class:`int` Integer with national dex id of pokemon link: :class:`str` String containing pokemondb link for pokemon name: :class:`str` String containing name of pokemon answer: :class:`str` String containing url for answer image question: :class:`str` String containing url for question image """ def __init__(self, data: Dict[str, Any]): super(WTP, self).__init__(data) mon: Dict[str, Any] = data["Data"] self.dict: Dict[str, Any] = data self.abilities: List[str] = mon["abilities"] self.ascii: str = mon["ascii"] self.height: float = mon["height"] self.id: int = int(mon["id"]) self.link: str = mon["link"] self.name: str = mon["name"] self.type: List[str] = mon["Type"] self.weight: float = mon["weight"] self.question: str = data["question"] self.answer: str = data["answer"]
class Headline(BaseDagpiObject): """ A Dagpi Headline .. container:: Attributes **Attributes** dict: :class:`Dict` Dictionary with raw data (same returned by raw_data) category: :class:`bool` Value stating whether headline is true or false headline: :class:`str` String Containing headline """ def __init__(self, data: Dict[str, Any]): super(Headline, self).__init__(data) self.dict: Dict[str, Any] = data self.headline: str = data["text"] self.fake: bool = data["fake"] class Captcha(BaseDagpiObject): """ An asyncdagpi Captcha .. container:: Attributes **Attributes** dict: :class:`Dict` Dictionary with raw data (same returned by raw_data) image: :class:`str` url for image with solution answer: :class:`str` string with captcha value """ def __init__(self, data: Dict[str, Any]): super(Captcha, self).__init__(data) self.dict: Dict[str, Any] = data self.image: str = data["image"] self.answer: str = data["answer"] class Typeracer(BaseDagpiObject): """ An asyncdagpi typeracer image .. container:: Attributes **Attributes** dict: :class:`Dict` Dictionary with raw data (same returned by raw_data) image: :class:`str` url for image with solution sentence: :class:`str` string with sentence """ def __init__(self, data: Dict[str, Any]): super(Typeracer, self).__init__(data) self.dict: Dict[str, Any] = data self.image: str = data["image"] self.sentence: str = data["sentence"]