add 256 RGB supported
[rainbowstream.git] / rainbowstream / config.py
index a0cdc22e92922836adec9d3ab4fd30c1754999c6..de49969846a83d7712b02c192de2b37057bd684e 100644 (file)
@@ -1,3 +1,34 @@
-# This is RainbowStream App info
-CONSUMER_KEY = 'Xk1DGhR1FJa4xjg7GbdogzLJw'
-CONSUMER_SECRET = 'SpHtDmbSGCSm55AAlIeb2PsD3kGEzxyo1325rJgrND5abeOh2T'
+import json
+import re
+import os
+import os.path
+from twitter.util import printNicely
+
+# Regular expression for comments
+comment_re = re.compile(
+    '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
+    re.DOTALL | re.MULTILINE
+)
+
+def load_config(filepath):
+    """
+    Load config from filepath
+    """
+    try:
+        with open(filepath) as f:
+            content = ''.join(f.readlines())
+            match = comment_re.search(content)
+            while match:
+                content = content[:match.start()] + content[match.end():]
+                match = comment_re.search(content)
+        data = json.loads(content)
+        for d in data:
+            globals()[d] = data[d]
+    except:
+        pass
+
+# Load colorset
+default_config = 'rainbowstream/colorset/default.json'
+rainbow_config = os.environ.get('HOME', os.environ.get('USERPROFILE','')) + os.sep + '.rainbow_config.json'
+load_config(default_config)
+load_config(rainbow_config)