load config
authorVu Nhat Minh <vunhat_minh@dwango.co.jp>
Wed, 2 Jul 2014 06:17:49 +0000 (15:17 +0900)
committerVu Nhat Minh <vunhat_minh@dwango.co.jp>
Wed, 2 Jul 2014 06:17:49 +0000 (15:17 +0900)
rainbowstream/colorset/__init__.py [new file with mode: 0644]
rainbowstream/colorset/default.py [new file with mode: 0644]
rainbowstream/config.py
rainbowstream/draw.py

diff --git a/rainbowstream/colorset/__init__.py b/rainbowstream/colorset/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/rainbowstream/colorset/default.py b/rainbowstream/colorset/default.py
new file mode 100644 (file)
index 0000000..e6a7adc
--- /dev/null
@@ -0,0 +1,53 @@
+########## Default color config for rainbowstream ##########
+
+# Following 16 basic colors is supported:
+#   default
+#   black
+#   red
+#   green
+#   yellow
+#   blue
+#   magenta
+#   cyan
+#   grey
+#   light_red
+#   light_green
+#   light_yellow
+#   light_blue
+#   light_magenta
+#   light_cyan
+#   white
+
+TWEET = {
+    'nick'      : grey,
+    'clock'     : grey,
+    'id'        : grey,
+    'favourite' : light_green,
+    'rt'        : grey,
+    'link'      : light_cyan,
+    'keyword'   : on_light_yellow,
+}
+
+MESSAGE = {
+    'sender'    : grey,
+    'recipient' : grey,
+    'to'        : light_magenta,
+    'clock'     : grey,
+    'id'        : grey,
+}
+
+PROFILE = {
+    'statuses_count'    : light_green,
+    'friends_count'     : light_green,
+    'followers_count'   : light_green,
+    'nick'              : grey,
+    'profile_image_url' : light_cyan,
+    'description'       : light_yellow,
+    'location'          : light_magenta,
+    'url'               : light_cyan,
+    'clock'             : white,
+}
+
+TREND = {
+    'url': light_cyan,
+}
index 6afffd5f519526b705d9aef6f3313b0e2165d5e4..837aec0d4c19a59076ff3b0ff3947aeaff29c1eb 100644 (file)
@@ -1,4 +1,7 @@
 from .colors import *
 from .colors import *
+import json
+import os
+import os.path
 
 # 'search': max search record
 SEARCH_MAX_RECORD = 5
 
 # 'search': max search record
 SEARCH_MAX_RECORD = 5
@@ -22,57 +25,24 @@ PUBLIC_DOMAIN = 'stream.twitter.com'
 SITE_DOMAIN = 'sitestream.twitter.com'
 DOMAIN = USER_DOMAIN
 
 SITE_DOMAIN = 'sitestream.twitter.com'
 DOMAIN = USER_DOMAIN
 
+# Image config
 IMAGE_SHIFT = 10
 IMAGE_MAX_HEIGHT = 40
 
 IMAGE_SHIFT = 10
 IMAGE_MAX_HEIGHT = 40
 
-# Following 16 basic colors is supported:
-#   default
-#   black
-#   red
-#   green
-#   yellow
-#   blue
-#   magenta
-#   cyan
-#   grey
-#   light_red
-#   light_green
-#   light_yellow
-#   light_blue
-#   light_magenta
-#   light_cyan
-#   white
+# Load colorset
+COLOR_SET = ['colorset.default']
+modules = map(__import__, COLOR_SET)
 
 
-TWEET = {
-    'nick'      : grey,
-    'clock'     : grey,
-    'id'        : grey,
-    'favourite' : light_green,
-    'rt'        : grey,
-    'link'      : light_cyan,
-    'keyword'   : on_light_yellow,
-}
+# Load json config
+rainbow_config = os.environ.get(
+    'HOME', os.environ.get('USERPROFILE',''))
+    + os.sep + '.rainbow_config.json'
+try:
+    if os.path.exists(rainbow_config):
+        data = json.load(open(rainbow_config))
+        for d in data:
+            locals()[d] = data[d]
+except:
+    pass
 
 
-MESSAGE = {
-    'sender'    : grey,
-    'recipient' : grey,
-    'to'        : light_magenta,
-    'clock'     : grey,
-    'id'        : grey,
-}
 
 
-PROFILE = {
-    'statuses_count'    : light_green,
-    'friends_count'     : light_green,
-    'followers_count'   : light_green,
-    'nick'              : grey,
-    'profile_image_url' : light_cyan,
-    'description'       : light_yellow,
-    'location'          : light_magenta,
-    'url'               : light_cyan,
-    'clock'             : white,
-}
-
-TREND = {
-    'url': light_cyan
-}
\ No newline at end of file
index 096074b723540f89df7ec9cfdbf00c3a55bea5c4..33c8ffde7174b9e8a570afbdb0d0dcd6b21457d8 100644 (file)
@@ -144,7 +144,7 @@ def print_message(m):
     recipient = cycle_color(
         recipient_name) + MESSAGE['recipient'](' ' + recipient_screen_name + ' ')
     user = sender + MESSAGE['to'](' >>> ') + recipient
     recipient = cycle_color(
         recipient_name) + MESSAGE['recipient'](' ' + recipient_screen_name + ' ')
     user = sender + MESSAGE['to'](' >>> ') + recipient
-    meta = MESSAGE['clock']('[' + clock + ']' + MESSAGE['id'](' [message_id=' + str(rid) + '] ')
+    meta = MESSAGE['clock']('[' + clock + ']') + MESSAGE['id'](' [message_id=' + str(rid) + '] ')
     text = ''.join(map(lambda x: x + '  ' if x == '\n' else x, text))
 
     line1 = u"{u:>{uw}}:".format(
     text = ''.join(map(lambda x: x + '  ' if x == '\n' else x, text))
 
     line1 = u"{u:>{uw}}:".format(