Commits

Stefan Scherfke committed 31d5622

Added default settings to simplify sphinx builds.

Comments (0)

Files changed (3)

 # use glob syntax.
 syntax: glob
 
-# Misc
 *.pyc
 *~
 .DS_Store
+_build/*
+*.egg-info/*
 
 # switch to regexp syntax.
 # syntax: regexp
 # serve to show the default.
 
 import sys, os
-# from django.conf import settings
-# settings.configure()
+from django.conf import settings
+settings.configure()
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 from django.utils import simplejson as json
 
 
-url = 'http://ws.audioscrobbler.com/2.0/?'
+URL = 'http://ws.audioscrobbler.com/2.0/?'
+
+LASTFM_USER = getattr(settings, 'LASTFM_USER', '')
+LASTFM_API_KEY = getattr(settings, 'LASTFM_API_KEY', '')
+LASTFM_SECRET = getattr(settings, 'LASTFM_SECRET', '')
+LASTFM_CHART_TYPE = getattr(settings, 'LASTFM_CHART_TYPE', 'top_artists')
+LASTFM_WIDGET_TITLE = getattr(settings, 'LASTFM_WIDGET_TITLE',
+        'Weekly Top Artists')
+LASTFM_NUM_IMAGES = getattr(settings, 'LASTFM_NUM_IMAGES', '12')
+LASTFM_TOP_ARTISTS_PERIOD = getattr(settings, 'LASTFM_TOP_ARTISTS_PERIOD', 
+        '7day')
+LASTFM_IMG_SIZE = getattr(settings, 'LASTFM_IMG_SIZE', 'large')
 
 
 def lastfm_data(request):
         'weekly_top_artists': WeeklyTopArtists,
         'top_artists': TopArtists,
     }
-    img_size = 'large'
-    if hasattr(settings, 'LASTFM_IMG_SIZE'):
-        img_size = settings.LASTFM_IMG_SIZE
+    img_size = LASTFM_IMG_SIZE
         
-    chart = chart_types[settings.LASTFM_CHART_TYPE]()
+    chart = chart_types[LASTFM_CHART_TYPE]()
     
     try:
         params = urllib.urlencode(chart.params)
-        data = json.loads(urllib.urlopen(url + params).read())
+        data = json.loads(urllib.urlopen(URL + params).read())
     except IOError:
         return HttpResponse(json.dumps([]), mimetype='application/json')
     
     for i, d in enumerate(chart.get_data(data)):
         # Not every last.fm method supports the ``limit`` parameter so we have
         # to take care of this ourselves.
-        if i == int(settings.LASTFM_NUM_IMAGES):
+        if i == int(LASTFM_NUM_IMAGES):
             break
         
         item = {
     """This class handles the API call ``user.getRecentTracks``."""
     params = {
         'method': 'user.getRecentTracks',
-        'user': settings.LASTFM_USER,
-        'limit': settings.LASTFM_NUM_IMAGES,
-        'api_key': settings.LASTFM_API_KEY,
+        'user': LASTFM_USER,
+        'limit': LASTFM_NUM_IMAGES,
+        'api_key': LASTFM_API_KEY,
         'format': 'json',
     }
     
     """This class handles the API call ``user.getWeeklyArtistChart``."""
     params = {
         'method': 'user.getWeeklyArtistChart',
-        'user': settings.LASTFM_USER,
-        'limit': settings.LASTFM_NUM_IMAGES,
-        'api_key': settings.LASTFM_API_KEY,
+        'user': LASTFM_USER,
+        'limit': LASTFM_NUM_IMAGES,
+        'api_key': LASTFM_API_KEY,
         'format': 'json',
     }
     
             'method': 'artist.getimages',
             'artist': item['name'],
             'limit': 1,
-            'api_key': settings.LASTFM_API_KEY,
+            'api_key': LASTFM_API_KEY,
             'format': 'json',
         })
         
         try:
-            img_data = json.loads(urllib.urlopen(url + params).read())['images']
+            img_data = json.loads(urllib.urlopen(URL + params).read())['images']
         except IOError:
             return ''
         if 'image' in img_data:
     be defined in the site’s settings module."""
     params = {
         'method': 'user.getTopArtists',
-        'user': settings.LASTFM_USER,
-        'api_key': settings.LASTFM_API_KEY,
-        'period': settings.LASTFM_TOP_ARTISTS_PERIOD,
+        'user': LASTFM_USER,
+        'api_key': LASTFM_API_KEY,
+        'period': LASTFM_TOP_ARTISTS_PERIOD,
         'format': 'json'
     }