]> kaliko git repositories - mpd-sima.git/commitdiff
Some light refactoring
authorkaliko <efrim@azylum.org>
Tue, 28 Jan 2014 19:07:37 +0000 (20:07 +0100)
committerkaliko <efrim@azylum.org>
Sat, 8 Feb 2014 13:11:43 +0000 (14:11 +0100)
sima/lib/simaecho.py

index 03892c0a3a7efd3ce1d41167e1a70ccbcccf3c80..4bc08b06e14a5c85ec25d02536dbb9ac86b4e13b 100644 (file)
@@ -84,6 +84,19 @@ class Cache():
         return self.elem
 
 
+def purge_cache(self, age=4):
+    now = datetime.utcnow()
+    if now.hour == SimaEch.timestamp.hour:
+        return
+    SimaEch.timestamp = datetime.utcnow()
+    cache = SimaEch.cache
+    delta = timedelta(hours=age)
+    for url in list(cache.keys()):
+        timestamp = cache.get(url).created()
+        if now - timestamp > delta:
+            cache.pop(url)
+
+
 class SimaEch():
     """
     """
@@ -154,18 +167,6 @@ class SimaEch():
         payload.update(results=30)
         return payload
 
-    def purge_cache(self, age=4):
-        now = datetime.utcnow()
-        if now.hour == SimaEch.timestamp.hour:
-            return
-        SimaEch.timestamp = datetime.utcnow()
-        cache = SimaEch.cache
-        delta = timedelta(hours=age)
-        for url in list(cache.keys()):
-            timestamp = cache.get(url).created()
-            if now - timestamp > delta:
-                cache.pop(url)
-
     def get_similar(self, artist=None):
         """
         """
@@ -177,9 +178,10 @@ class SimaEch():
             artist = {}
             mbid = None
             if 'foreign_ids' in art:
-               for frgnid in art.get('foreign_ids'):
-                   if frgnid.get('catalog') == 'musicbrainz':
-                       mbid = frgnid.get('foreign_id').lstrip('musicbrainz:artist:')
+                for frgnid in art.get('foreign_ids'):
+                    if frgnid.get('catalog') == 'musicbrainz':
+                        mbid = frgnid.get('foreign_id'
+                                          ).lstrip('musicbrainz:artist:')
             yield Artist(mbid=mbid, name=art.get('name'))