From 2e73187a7ba3f38ac2cbdbe8a21dfec52f520dcc Mon Sep 17 00:00:00 2001 From: Vu Nhat Minh Date: Wed, 2 Jul 2014 16:11:50 +0900 Subject: [PATCH] json load --- rainbowstream/colorset/__init__.py | 0 rainbowstream/colorset/default.json | 57 +++++++++++++++++++++++++++++ rainbowstream/colorset/default.py | 53 --------------------------- rainbowstream/config.py | 16 +++++--- 4 files changed, 67 insertions(+), 59 deletions(-) delete mode 100644 rainbowstream/colorset/__init__.py create mode 100644 rainbowstream/colorset/default.json diff --git a/rainbowstream/colorset/__init__.py b/rainbowstream/colorset/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/rainbowstream/colorset/default.json b/rainbowstream/colorset/default.json new file mode 100644 index 0000000..4e3e36a --- /dev/null +++ b/rainbowstream/colorset/default.json @@ -0,0 +1,57 @@ +/* +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", + } + +} \ No newline at end of file diff --git a/rainbowstream/colorset/default.py b/rainbowstream/colorset/default.py index e6a7adc..e69de29 100644 --- a/rainbowstream/colorset/default.py +++ b/rainbowstream/colorset/default.py @@ -1,53 +0,0 @@ -########## 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, -} diff --git a/rainbowstream/config.py b/rainbowstream/config.py index 837aec0..67dfc91 100644 --- a/rainbowstream/config.py +++ b/rainbowstream/config.py @@ -30,18 +30,22 @@ IMAGE_SHIFT = 10 IMAGE_MAX_HEIGHT = 40 # Load colorset -COLOR_SET = ['colorset.default'] -modules = map(__import__, COLOR_SET) +default_colorset = 'colorset/default.json' +try: + if os.path.exists(default_colorset): + data = json.load(open(default_colorset)) + for d in data: + locals()[d] = local()[data[d]] +except: + pass # Load json config -rainbow_config = os.environ.get( - 'HOME', os.environ.get('USERPROFILE','')) - + os.sep + '.rainbow_config.json' +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] + locals()[d] = local()[data[d]] except: pass -- 2.25.1