Skip to content

Commit

Permalink
Added __str__ method in all classes
Browse files Browse the repository at this point in the history
  • Loading branch information
eitozx committed Oct 1, 2022
1 parent dea1014 commit 6f1dc98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions animu/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from animu import model

class Client:

def __init__(self, token: str):
self._header = {"Auth": token}
self._baseurl = "https://animu.ml/api/"
Expand Down
38 changes: 25 additions & 13 deletions animu/model.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
class Base:
class _Base:
def __init__(self, data):
self._data = data

def __getitem__(self, key):
return self._data[key]

def __str__(self):
return str(self._data)


class Fact(Base):
class Fact(_Base):
def __init__(self, data):
super().__init__(data)

self.id = data.get('_id')
self.fact = data.get('fact')
self.tags = data.get('tags')

def __str__(self):
return self.fact

class Password(Base):
def __init__(self, data):

class Password(_Base):
def __init__(self, data):
super().__init__(data)

self.password = data.get('pass')

def __str__(self):
return self.password


class Quote(Base):
class Quote(_Base):
def __init__(self, data):
super().__init__(data)

self.id = data.get('_id')
self.quote = data.get('quote')
self.anime = data.get('anime')
self.said = data.get('said')

def __str__(self):
return self.quote


class Roleplay(Base):
class Roleplay(_Base):
def __init__(self, data):
super().__init__(data)

self.url = data.get('url')

def __str__(self):
return self.url


class Waifu(Base):
class Waifu(_Base):
def __init__(self, data):
super().__init__(data)

Expand All @@ -63,4 +72,7 @@ def __init__(self, data):
self.love = self.statistics.get('love')
self.hate = self.statistics.get('hate')
self.upvote = self.statistics.get('upvote')
self.downvote = self.statistics.get('downvote')
self.downvote = self.statistics.get('downvote')

def __str__(self):
return self.en_name or self.jp_name or self.alt_name

0 comments on commit 6f1dc98

Please sign in to comment.