diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2009-11-02 15:08:07 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2009-11-02 15:08:07 +0100 |
commit | 528cd7438ca34880844b2c808a6eca30a06f80aa (patch) | |
tree | bd4f521cee749d90524ea5036a6545259ad8ffee | |
parent | ade97313e211aae97e9c9661ae04442fef7055ed (diff) |
Implemented ANIME.
-rw-r--r-- | pyanidb/__init__.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pyanidb/__init__.py b/pyanidb/__init__.py index bb8f234..57c44c2 100644 --- a/pyanidb/__init__.py +++ b/pyanidb/__init__.py @@ -48,6 +48,9 @@ class AniDBUnknownFile(AniDBError): class AniDBNotInMylist(AniDBError): pass +class AniDBUnknownAnime(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) @@ -173,3 +176,26 @@ class AniDB: self.auth() else: raise AniDBReplyError(code, text) + + def get_anime(self, aid = None, aname = None, amask = None, retry = False): + args = {} + if not aid == None: + args['aid'] = aid + elif not aname == None: + args['aname'] == aname + else: + raise TypeError('must set either aid or aname') + + args['amask'] = amask or '00'*7 + args['s'] = self.session + + while 1: + code, text, data = self.execute('ANIME', args, retry) + if code == 230: + return data[0] + elif code == 330: + raise AniDBUnknownAnime() + elif code in (501, 506): + self.auth() + else: + raise AniDBReplyError(code, text) |