minor changes
This commit is contained in:
parent
5a4296fa73
commit
36b2aea1fd
@ -13,7 +13,7 @@ __package__ = "lastfm"
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from lastfm.album import Album
|
||||
from lastfm.api import Api
|
||||
|
@ -64,6 +64,7 @@ class Api(object):
|
||||
self._no_cache = no_cache
|
||||
self._debug = debug
|
||||
self._last_fetch_time = datetime.now()
|
||||
self._lock = Lock()
|
||||
|
||||
@property
|
||||
def api_key(self):
|
||||
@ -643,13 +644,14 @@ class Api(object):
|
||||
return urllib.urlencode([(k, self._encode(parameters[k])) for k in keys if parameters[k] is not None])
|
||||
|
||||
def _read_url_data(self, opener, url, data = None):
|
||||
now = datetime.now()
|
||||
delta = now - self._last_fetch_time
|
||||
delta = delta.seconds + float(delta.microseconds)/1000000
|
||||
if delta < Api.FETCH_INTERVAL:
|
||||
time.sleep(Api.FETCH_INTERVAL - delta)
|
||||
url_data = opener.open(url, data).read()
|
||||
self._last_fetch_time = datetime.now()
|
||||
with self._lock:
|
||||
now = datetime.now()
|
||||
delta = now - self._last_fetch_time
|
||||
delta = delta.seconds + float(delta.microseconds)/1000000
|
||||
if delta < Api.FETCH_INTERVAL:
|
||||
time.sleep(Api.FETCH_INTERVAL - delta)
|
||||
url_data = opener.open(url, data).read()
|
||||
self._last_fetch_time = datetime.now()
|
||||
return url_data
|
||||
|
||||
def _fetch_url(self,
|
||||
@ -765,6 +767,7 @@ class Api(object):
|
||||
return "<lastfm.Api: %s>" % self._api_key
|
||||
|
||||
from datetime import datetime
|
||||
from threading import Lock
|
||||
import sys
|
||||
import time
|
||||
import urllib
|
||||
|
@ -60,7 +60,7 @@ def cached_property(func):
|
||||
return property(fget = wrapper, doc = func.__doc__)
|
||||
|
||||
@decorator
|
||||
def authenticate(func, *args, **kwargs):
|
||||
def authentication_required(func, *args, **kwargs):
|
||||
"""
|
||||
A decorator to check if the current user is authenticated or not. Used only
|
||||
on the functions that need authentication. If not authenticated then an
|
||||
|
@ -6,14 +6,14 @@ __license__ = "GNU Lesser General Public License"
|
||||
__package__ = "lastfm.mixins"
|
||||
|
||||
from lastfm.safelist import SafeList
|
||||
from lastfm.decorators import cached_property, authenticate
|
||||
from lastfm.decorators import cached_property, authentication_required
|
||||
|
||||
class Taggable(object):
|
||||
def init(self, api):
|
||||
self._api = api
|
||||
|
||||
@cached_property
|
||||
@authenticate
|
||||
@authentication_required
|
||||
def tags(self):
|
||||
from lastfm.tag import Tag
|
||||
params = self._default_params({'method': '%s.getTags' % self.__class__.__name__.lower()})
|
||||
@ -28,7 +28,7 @@ class Taggable(object):
|
||||
],
|
||||
self.add_tags, self.remove_tag)
|
||||
|
||||
@authenticate
|
||||
@authentication_required
|
||||
def add_tags(self, tags):
|
||||
from lastfm.tag import Tag
|
||||
while(len(tags) > 10):
|
||||
@ -52,7 +52,7 @@ class Taggable(object):
|
||||
self._api._post_data(params)
|
||||
self._tags = None
|
||||
|
||||
@authenticate
|
||||
@authentication_required
|
||||
def remove_tag(self, tag):
|
||||
from lastfm.tag import Tag
|
||||
if isinstance(tag, Tag):
|
||||
|
Loading…
Reference in New Issue
Block a user