From df433543cbd671656aefa77053b88fb7fa448d20 Mon Sep 17 00:00:00 2001 From: kaliko Date: Tue, 28 Jan 2014 20:07:37 +0100 Subject: [PATCH] Some light refactoring --- sima/lib/simaecho.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/sima/lib/simaecho.py b/sima/lib/simaecho.py index 03892c0..4bc08b0 100644 --- a/sima/lib/simaecho.py +++ b/sima/lib/simaecho.py @@ -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')) -- 2.39.5