Source code for asyncdagpi.objects

import json
from typing import Dict, Any, List


[docs]class BaseDagpiObject: """ Base AsyncDagpi object .. container:: Attributes **Attributes** dict: :class:`Dict` """ def __init__(self, dictionary: Dict[str, Any]): """ Initialise a BaseDagpiObject """ self.dict = 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 = data self.category = data["category"] self.line = 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 = data["Data"] self.dict = data self.abilities: List[str] = mon["abilities"] self.ascii: str = mon.get("ascii") self.height: float = mon.get("height") self.id: int = int(mon.get("id")) self.link: str = mon.get("link") self.name: str = mon.get("name") self.type: List[str] = mon.get("type") self.weight: float = mon.get("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 = data self.headline: str = data["text"] self.fake: bool = data["fake"]