def verifyNetworkConfiguration(self, userName, networkName): user = self.userDb.get(u(userName)) if not user: return "error:user not found" networkConfig = user.setdefault("imes", {}).setdefault("scrobbler", {}).setdefault(networkName, {}) if "auth_token" not in networkConfig: return "error:missing auth_token" # part of get_web_session_auth_key request = pylast._Request(self.networkFactory[networkName](), 'auth.getSession', {'token': networkConfig["auth_token"]}) request.sign_it() try: doc = request.execute() except pylast.WSError as e: if int(e.status) == pylast.STATUS_TOKEN_EXPIRED: return "error:token is expired, remove and re-start" elif int(e.status) == pylast.STATUS_TOKEN_UNAUTHORIZED: return "error:not authorized" raise result = doc.getElementsByTagName('key')[0].firstChild.data # success? print "verifyNetworkConfiguration", repr(result) networkConfig.pop("auth_token") networkConfig["session_token"] = result self.userDb[u(userName)] = user network = self.networkFactory[networkName](result) self.sessions.setdefault(userName, {})[networkName] = Session(self.db, self.userDb, networkName, network, userName, networkConfig.get("head")) self.pending.add(userName) self._catchupLater() return True
def lfm_request(method, params): try: lfm_network = self.__class__.engine.lfm_login() params['username'] = lfm_network.username return ET.fromstring(pylast._Request(lfm_network, method, params).execute(False).toxml()) except Exception as e: self.__class__.logger.warn('%s %s', type(e), e)
def lfm_request(method, params): try: lfm_network = self.__class__.engine.lfm_login() params['username'] = lfm_network.username return ET.fromstring( pylast._Request(lfm_network, method, params).execute(False).toxml()) except Exception as e: self.__class__.logger.warn('%s %s', type(e), e)
def test_get_cache_key(artist): request = pylast._Request(mock_network(), "some_method", params={"artist": artist}) request._get_cache_key()
def test_get_cache_key(artist): request = pylast._Request(mock_network(), 'some_method', params={'artist': artist}) request._get_cache_key()
def debug_now_playing(self, artist, title): params = {'track': title, 'artist': artist} return pylast._Request( self, 'track.updateNowPlaying', params ).execute()
def test_get_cache_key(artist): request = pylast._Request(mock_network(), 'some_method', params={'artist': artist}) request._get_cache_key()
def debug_now_playing(self, artist, title): params = {'track': title, 'artist': artist} return pylast._Request(self, 'track.updateNowPlaying', params).execute()
def test_get_cache_key(artist): request = pylast._Request(mock_network(), "some_method", params={"artist": artist}) request._get_cache_key()