Skip to content

Commit

Permalink
minimal refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
agonzalezro committed Sep 7, 2011
1 parent af08ba1 commit 9f3ffcd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pythonopensubtitles/opensubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@ def __init__(self, language=None):
allow_none=True)
self.language = language or Settings.LANGUAGE

def get_from_data_or_none(self, key):
"""Return the key getted from data if the status is 200,
otherwise return None.
"""
status, _ = self.data.get('status').split()
return self.data.get(key) if '200' == status else None

def login(self, username, password):
"""Returns token is login is ok, otherwise None."""
data = self.xmlrpc.LogIn(username, password,
self.data = self.xmlrpc.LogIn(username, password,
self.language, Settings.USER_AGENT)
if '200' in data.get('status'):
return data.get('token')
return self.get_from_data_or_none('token')

def logout(self, token):
"""Returns True is logout is ok, otherwise None."""
data = self.xmlrpc.LogOut(token)
if '200' in data.get('status'):
return True
return '200' in data.get('status')

def search_subtitles(self, token, params):
data = self.xmlrpc.SearchSubtitles(token, params)
if '200' in data.get('status'):
return data.get('data')
self.data = self.xmlrpc.SearchSubtitles(token, params)
return self.get_from_data_or_none('data')

def search_to_mail(self):
# array SearchToMail( $token, array( $sublanguageid, $sublanguageid, ...), array( array( 'moviehash' => $moviehash, 'moviesize' => $moviesize), array( 'moviehash' => $moviehash, 'moviesize' => $moviesize), ...) )'
Expand Down

0 comments on commit 9f3ffcd

Please sign in to comment.