From cf4160dbe6df5a54d27773eed669c9170f78bc19 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 2 Nov 2009 15:20:17 +0100 Subject: Implemented ANIMEDESC. --- pyanidb/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pyanidb/__init__.py b/pyanidb/__init__.py index 57c44c2..ccb8a89 100644 --- a/pyanidb/__init__.py +++ b/pyanidb/__init__.py @@ -51,6 +51,9 @@ class AniDBNotInMylist(AniDBError): class AniDBUnknownAnime(AniDBError): pass +class AniDBUnknownDescription(AniDBError): + pass + class AniDB: def __init__(self, username, password, localport = 1234, server = ('api.anidb.info', 9000)): self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -199,3 +202,24 @@ class AniDB: self.auth() else: raise AniDBReplyError(code, text) + + def get_animedesc(self, aid, retry = False): + args = {'aid': aid, 'part': 0, 's': self.session} + description = '' + while 1: + code, text, data = self.execute('ANIMEDESC', args, retry) + if code == 233: + curpart, maxpart, desc = data[0] + description += desc + if curpart == maxpart: + return description + else: + args['part'] = int(curpart)+1 + elif code == 330: + raise AniDBUnknownAnime() + elif code == 333: + raise AnidBUnknownDescription() + elif code in (501, 506): + self.auth() + else: + raise AniDBReplyError(code, text) -- cgit v1.2.3