Commits

Stefan Scherfke committed 8490b53

code cleanup

Comments (0)

Files changed (1)

templatetags/lastfm_widget.py

     {% get_lastfm_widget as lastfm_widget %}
 """
 
-import json
-import urllib
 
 from django import template
 
-from django_site import settings
-
 
 register = template.Library()
 
         
         context[self.var_name] = lastfm_widget
         return ''
-        
-    def _get_recent_tracks(self):
-        params = urllib.urlencode({
-            'method': 'user.getRecentTracks',
-            'user': settings.LASTFM_USER,
-            'limit': settings.LASTFM_NUM_IMAGES,
-            'api_key': settings.LASTFM_API_KEY,
-            'format': 'json',
-        })
-        result = urllib.urlopen(self.url + params).read()
-        data = json.loads(result)['recenttracks']['track']
-        tracks = []
-        for d in data:
-            track = {
-                'title': d['artist']['#text'] + u' – ' + d['name'],
-                'url': d['url'],
-                'img_url': 'http://cdn.last.fm/depth/catalogue/' + \
-                        'noimage/cover_85px.gif',
-            }
-            for img in d['image']:
-                if img['size'] == 'medium' and img['#text']:
-                    track['img_url'] = img['#text']
-                    break
-            tracks.append(track)
-        return tracks
-            
-    def _get_weekly_top_artists(self):
-        params = urllib.urlencode({
-            'method': 'user.getWeeklyArtistChart',
-            'user': settings.LASTFM_USER,
-            'limit': settings.LASTFM_NUM_IMAGES,
-            'api_key': settings.LASTFM_API_KEY,
-            'format': 'json',
-        })
-        result = urllib.urlopen(self.url + params).read()
-        data = json.loads(result)['weeklyartistchart']['artist']
-        
-        artists = []
-        for d in data:
-            artist = {
-                'title': '%s (%s plays)' % (d['name'], d['playcount']),
-                'url': d['url'],
-                'img_url': 'http://cdn.last.fm/flatness/catalogue/' + \
-                        'noimage/2/default_artist_large.png',
-            }
-
-            params = urllib.urlencode({
-                'method': 'artist.getimages',
-                'artist': d['name'],
-                'limit': 1,
-                'api_key': settings.LASTFM_API_KEY,
-                'format': 'json',
-            })
-            url = 'http://ws.audioscrobbler.com/2.0/?'
-            result = urllib.urlopen(url + params).read()
-            img_data = json.loads(result)['images']
-            if 'image' in img_data:
-                img_data = img_data['image']
-                img_data = img_data['sizes']['size']
-                for img_d in img_data:
-                    if img_d['name'] == 'largesquare':
-                        artist['img_url'] = img_d['#text']
-                        break
-            artists.append(artist)
-        return artists
-        
-    def _get_top_artists(self):
-        params = urllib.urlencode({
-            'method': 'user.getTopArtists',
-            'user': settings.LASTFM_USER,
-            'api_key': settings.LASTFM_API_KEY,
-            'period': settings.LASTFM_TOP_ARTISTS_PERIOD,
-            'format': 'json'
-        })
-        result = urllib.urlopen(self.url + params).read()
-        data = json.loads(result)['topartists']['artist']
-        artists = []
-        for i, d in enumerate(data):
-            if i == int(settings.LASTFM_NUM_IMAGES):
-                break
-            artist = {
-                'title': '%s (%s plays)' % (d['name'], d['playcount']),
-                'url': d['url'],
-                'img_url':'http://cdn.last.fm/flatness/catalogue/' + \
-                        'noimage/2/default_artist_large.png',
-            }
-            for img in d['image']:
-                if img['size'] == 'medium' and img['#text']:
-                    artist['img_url'] = img['#text']
-                    break
-            artists.append(artist)
-        return artists
 
 
 @register.tag
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.