diff --git a/lib/adba/__init__.py b/lib/adba/__init__.py index 59de2d92..93817404 100644 --- a/lib/adba/__init__.py +++ b/lib/adba/__init__.py @@ -244,23 +244,56 @@ class Connection(threading.Thread): """ return self.handle(PushAckCommand(nid), callback) - def notifyadd(self, aid=None, gid=None, type=None, priority=None, callback=None): + def notification(self, aid=None, gid=None, type=None, priority=None, callback=None): """ Add a notification - + parameters: aid - Anime id gid - Group id type - Type of notification: type=> 0=all, 1=new, 2=group, 3=complete priority - low = 0, medium = 1, high = 2 (unconfirmed) - + structure of parameters: [aid={int}|gid={int}]&type={int}&priority={int} - + + """ + + return self.handle(Notification(aid, gid, type, priority), callback) + + def notifyadd(self, aid=None, gid=None, type=None, priority=None, callback=None): + """ + Add a notification + + parameters: + aid - Anime id + gid - Group id + type - Type of notification: type=> 0=all, 1=new, 2=group, 3=complete + priority - low = 0, medium = 1, high = 2 (unconfirmed) + + structure of parameters: + [aid={int}|gid={int}]&type={int}&priority={int} + """ return self.handle(NotifyAddCommand(aid, gid, type, priority), callback) + def notifydel(self, aid=None, gid=None, type=None, priority=None, callback=None): + """ + Add a notification + + parameters: + aid - Anime id + gid - Group id + type - Type of notification: type=> 0=all, 1=new, 2=group, 3=complete + priority - low = 0, medium = 1, high = 2 (unconfirmed) + + structure of parameters: + [aid={int}|gid={int}]&type={int}&priority={int} + + """ + + return self.handle(NotifyDelCommand(aid, gid, type, priority), callback) def notify(self, buddy=None, callback=None): """ diff --git a/lib/adba/aniDBAbstracter.py b/lib/adba/aniDBAbstracter.py index 428bfa29..64ebd851 100644 --- a/lib/adba/aniDBAbstracter.py +++ b/lib/adba/aniDBAbstracter.py @@ -99,9 +99,18 @@ class aniDBabstractObject(object): priority - low = 0, medium = 1, high = 2 (unconfirmed) """ - if (self.aid): + if self.aid: self.aniDB.notifyadd(aid=self.aid, type=1, priority=1) + def del_notification(self): + """ + type - Type of notification: type=> 0=all, 1=new, 2=group, 3=complete + priority - low = 0, medium = 1, high = 2 (unconfirmed) + + """ + if self.aid: + self.aniDB.notifydel(aid=self.aid, type=1, priority=1) + class Anime(aniDBabstractObject): def __init__(self, aniDB, name=None, aid=None, tvdbid=None, paramsA=None, autoCorrectName=False, load=False): diff --git a/lib/adba/aniDBcommands.py b/lib/adba/aniDBcommands.py index 190234bf..74d62806 100644 --- a/lib/adba/aniDBcommands.py +++ b/lib/adba/aniDBcommands.py @@ -103,6 +103,14 @@ class PushAckCommand(Command): Command.__init__(self, 'PUSHACK', **parameters) +class Notification(Command): + def __init__(self, aid=None, gid=None, type=None, priority=None): + if not (aid or gid) or (aid and gid): + raise AniDBIncorrectParameterError, "You must provide aid OR gid for NOTIFICATION command" + parameters = {'aid': aid, "gid": gid, "type": type, "priority": priority} + Command.__init__(self, 'NOTIFICATION', **parameters) + + class NotifyAddCommand(Command): def __init__(self, aid=None, gid=None, type=None, priority=None): if not (aid or gid) or (aid and gid): @@ -111,6 +119,14 @@ class NotifyAddCommand(Command): Command.__init__(self, 'NOTIFICATIONADD', **parameters) +class NotifyDelCommand(Command): + def __init__(self, aid=None, gid=None, type=None, priority=None): + if not (aid or gid) or (aid and gid): + raise AniDBIncorrectParameterError, "You must provide aid OR gid for NOTIFICATIONDEL command" + parameters = {'aid': aid, "gid": gid, "type": type, "priority": priority} + Command.__init__(self, 'NOTIFICATIONDEL', **parameters) + + class NotifyCommand(Command): def __init__(self, buddy=None): parameters = {'buddy': buddy} diff --git a/lib/adba/aniDBresponses.py b/lib/adba/aniDBresponses.py index 597021ef..7504ce17 100644 --- a/lib/adba/aniDBresponses.py +++ b/lib/adba/aniDBresponses.py @@ -436,6 +436,27 @@ class MylistStatsResponse(Response): self.coderep = () +class NotificationResponse(Response): + def __init__(self, cmd, restag, rescode, resstr, datalines): + """ + attributes: + + data: + nid - notification id + unknown - unsure what this parameter is + type - Type of notification: type=> 0=all, 1=new, 2=group, 3=complete + aid - anime id + priority - low = 0, medium = 1, high = 2 (unconfirmed) + date - date notification subscribed to + + """ + Response.__init__(self, cmd, restag, rescode, resstr, datalines) + self.codestr = 'NOTIFICATION' + self.codehead = () + self.codetail = ('nid', 'unknown', 'type', 'aid', 'priority', 'date') + self.coderep = () + + class AnimeResponse(Response): def __init__(self, cmd, restag, rescode, resstr, datalines): Response.__init__(self, cmd, restag, rescode, resstr, datalines) @@ -759,6 +780,21 @@ class NotificationAddedResponse(Response): self.codetail = ('nid') self.coderep = () +class NotificationDeletedResponse(Response): + def __init__(self, cmd, restag, rescode, resstr, datalines): + """ + attributes: + + data: + nid - notofication id + + """ + Response.__init__(self, cmd, restag, rescode, resstr, datalines) + self.codestr = 'NOTIFICATION_ITEM_DELETED' + self.codehead = () + self.codetail = () + self.coderep = () + class NotificationUpdatedResponse(Response): def __init__(self, cmd, restag, rescode, resstr, datalines): @@ -776,6 +812,25 @@ class NotificationUpdatedResponse(Response): self.coderep = () +class MultipleNotificationResponse(Response): + def __init__(self, cmd, restag, rescode, resstr, datalines): + """ + attributes: + + data: + nid - notification id + type - + priority - + + + """ + Response.__init__(self, cmd, restag, rescode, resstr, datalines) + self.codestr = 'MULTIPLE NOTIFICATION ITEMS' + self.codehead = () + self.codetail = () + self.coderep = ('nid', 'type', 'priority',) + + class NotificationEnabledResponse(Response): def __init__(self, cmd, restag, rescode, resstr, datalines): """ @@ -913,7 +968,7 @@ class NotifyackSuccessfulNResponse(Response): self.coderep = () -class NotificationResponse(Response): +class NotificationStateResponse(Response): def __init__(self, cmd, restag, rescode, resstr, datalines): """ attributes: @@ -1233,6 +1288,21 @@ class MultipleFilesFoundResponse(Response): self.coderep = ('fid',) +class NoSuchNotificationResponse(Response): + def __init__(self, cmd, restag, rescode, resstr, datalines): + """ + attributes: + + data: + + """ + Response.__init__(self, cmd, restag, rescode, resstr, datalines) + self.codestr = 'NO_SUCH_NOTIFICATION' + self.codehead = () + self.codetail = () + self.coderep = () + + class NoGroupsFoundResponse(Response): def __init__(self, cmd, restag, rescode, resstr, datalines): """ @@ -1868,6 +1938,7 @@ responses = { '220': FileResponse, '221': MylistResponse, '222': MylistStatsResponse, + '224': NotificationResponse, '225': GroupstatusResponse, '230': AnimeResponse, '231': AnimeBestMatchResponse, @@ -1875,7 +1946,9 @@ responses = { '240': EpisodeResponse, '245': ProducerResponse, '246': NotificationAddedResponse, + '247': NotificationDeletedResponse, '248': NotificationUpdatedResponse, + '249': MultipleNotificationResponse, '250': GroupResponse, '253': BuddyListResponse, '254': BuddyStateResponse, @@ -1895,7 +1968,7 @@ responses = { '280': PushackConfirmedResponse, '281': NotifyackSuccessfulMResponse, '282': NotifyackSuccessfulNResponse, - '290': NotificationResponse, + '290': NotificationStateResponse, '291': NotifylistResponse, '292': NotifygetMessageResponse, '293': NotifygetNotifyResponse, @@ -1914,6 +1987,7 @@ responses = { '320': NoSuchFileResponse, '321': NoSuchEntryResponse, '322': MultipleFilesFoundResponse, + '324': NoSuchNotificationResponse, '325': NoGroupsFoundResponse, '330': NoSuchAnimeResponse, '340': NoSuchEpisodeResponse,