Commits

Bruce Kroeze committed b9c0dd4

added playainfo_settings

Comments (0)

Files changed (2)

playainfo/playainfo_settings.py

+"""A central mechanism for settings which have defaults.
+
+Repurposed from Sphene Community Tools: http://sct.sphene.net
+"""
+
+from django.conf import settings
+import urllib
+
+playainfo_settings_defaults = {
+    'refresh' : 600, #seconds between updates from BMEarth
+    'bmapi' : 'http://earth.burningman.com/api/0.1/2009/'
+}
+
+def get_playainfo_setting(name, default_value = None):
+    if not hasattr(settings, 'PLAYAINFO_SETTINGS'):
+        return playainfo_settings_defaults.get(name, default_value)
+
+    return settings.PLAYAINFO_SETTINGS.get(name, playainfo_settings_defaults.get(name, default_value))
+
+def bmapi_url(*args, **kwargs):
+    """Get the BMAPI url, optionally also adding arguments."""
+    url = get_playainfo_setting('bmapi')
+    if url.endswith('/'):
+        url = url[:-1]
+    for arg in args:
+        url = '%s/%s' % (url, arg)
+    if not url.endswith('/'):
+        url = url + '/'
+    if kwargs:
+        url += urllib.urlencode(kwargs.items())
+
+    return url

playainfo/settings.py

 }
 
 PLAYAINFO_CONFIG = {
-    'refresh' : 600,  #refresh data from BMEarth every x seconds
+    #refresh data from BMEarth every x seconds
+    'refresh' : 600,
+    # base URL for BMEarth - using 2009 data for now
+    'bmapi' : 'http://earth.burningman.com/api/0.1/2009/',
 }