fix sqlalchemy bug
[rainbowstream.git] / rainbowstream / draw.py
index 9a8fbdd..148fc58 100644 (file)
@@ -15,6 +15,29 @@ from .db import *
 
 db = RainbowDB()
 
+def check_theme():
+    """
+    Check current theme and update if necessary
+    """
+    exists = db.theme_query()
+    themes = [t.theme_name for t in exists]
+    if c['theme'] != themes[0]:
+        c['theme'] = themes[0]
+        # Determine path
+        if c['theme'] == 'custom':
+            config = os.environ.get(
+                'HOME',
+                os.environ.get(
+                'USERPROFILE',
+                '')) + os.sep + '.rainbow_config.json'
+        else:
+            config = 'rainbowstream/colorset/'+c['theme']+'.json'
+        # Load new config
+        data = load_config(config)
+        if data:
+            for d in data:
+                c[d] = data[d]
+
 
 def color_func(func_name):
     """
@@ -31,6 +54,7 @@ def draw(t, iot=False, keyword=None, fil=[], ig=[]):
     Draw the rainbow
     """
 
+    check_theme()
     # Retrieve tweet
     tid = t['id']
     text = t['text']
@@ -280,6 +304,6 @@ def print_trends(trends):
     for topic in trends[:c['TREND_MAX']]:
         name = topic['name']
         url = topic['url']
-        line = cycle_color(name) + ': ' + color_func(TREND['url'])(url)
+        line = cycle_color(name) + ': ' + color_func(c['TREND']['url'])(url)
         printNicely(line)
     printNicely('')