--- /dev/null
+{
+ // Themes
+ "THEME" : "monokai",
+ // 'search': max search record
+ "SEARCH_MAX_RECORD" : 5,
+ // 'home': default number of home's tweets
+ "HOME_TWEET_NUM" : 5,
+ // 'allrt': default number of retweets
+ "RETWEETS_SHOW_NUM" : 5,
+ // 'inbox','sent': default number of direct message
+ "MESSAGES_DISPLAY" : 5,
+ // 'trend': max trending topics
+ "TREND_MAX" : 10,
+ // List home timeline max
+ "LIST_MAX" : 5,
+ // 'switch': Filter and Ignore list ex: ['@fat','@mdo']
+ "ONLY_LIST" : [],
+ "IGNORE_LIST" : [],
+ // Autocomplete history file name
+ "HISTORY_FILENAME" : "completer.hist",
+ // Image config
+ "IMAGE_SHIFT" : 10,
+ "IMAGE_MAX_HEIGHT" : 40,
+ // Stream config
+ "USER_DOMAIN" : "userstream.twitter.com",
+ "PUBLIC_DOMAIN" : "stream.twitter.com",
+ "SITE_DOMAIN" : "sitestream.twitter.com"
+}
{
- // 'search': max search record
- "SEARCH_MAX_RECORD" : 5,
- // 'home': default number of home's tweets
- "HOME_TWEET_NUM" : 5,
- // 'allrt': default number of retweets
- "RETWEETS_SHOW_NUM" : 5,
- // 'inbox','sent': default number of direct message
- "MESSAGES_DISPLAY" : 5,
- // 'trend': max trending topics
- "TREND_MAX" : 10,
- // List home timeline max
- "LIST_MAX" : 5,
- // 'switch': Filter and Ignore list ex: ['@fat','@mdo']
- "ONLY_LIST" : [],
- "IGNORE_LIST" : [],
- // Autocomplete history file name
- "HISTORY_FILENAME" : "completer.hist",
- // Image config
- "IMAGE_SHIFT" : 10,
- "IMAGE_MAX_HEIGHT" : 40,
- // Stream config
- "USER_DOMAIN" : "userstream.twitter.com",
- "PUBLIC_DOMAIN" : "stream.twitter.com",
- "SITE_DOMAIN" : "sitestream.twitter.com",
-
/* Color config
There are 16 basic colors supported :
* default
* light_cyan
* white
and 256 colors from term_0 to term_255
- Color code can be reference at
- http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
*/
"DECORATED_NAME" : "grey",
import re
import os
import os.path
+from collections import OrderedDict
# Regular expression for comments
comment_re = re.compile(
re.DOTALL | re.MULTILINE
)
-
def load_config(filepath):
"""
Load config from filepath
while match:
content = content[:match.start()] + content[match.end():]
match = comment_re.search(content)
- return json.loads(content)
+ return json.loads(content, object_pairs_hook=OrderedDict)
# Config dictionary
c = {}
-# Load default
-default_config = os.path.dirname(__file__) + '/colorset/default.json'
-data = load_config(default_config)
-for d in data:
- c[d] = data[d]
-c['theme'] = 'default'
-# Load init if exist
-try:
- path = os.path.dirname(__file__) + '/colorset/init'
- f = open(path)
- lines = f.readlines()
- if len(lines) > 1:
- raise Exception('More than 1 default theme')
- theme_name = lines[0].strip()
- default_config = os.path.dirname(
- __file__) + '/colorset/' + theme_name + '.json'
- data = load_config(default_config)
- for d in data:
- c[d] = data[d]
- c['theme'] = theme_name
- f.close()
-except:
- pass
-# Load user's colorset
+
+# Load user's config
rainbow_config = os.environ.get(
'HOME',
os.environ.get(
data = load_config(rainbow_config)
for d in data:
c[d] = data[d]
- c['theme'] = 'custom'
+except:
+ pass
+
+# Load default theme
+theme_file = os.path.dirname(
+ __file__) + '/colorset/' + c['THEME'] + '.json'
+try:
+ data = load_config(theme_file)
+ for d in data:
+ c[d] = data[d]
except:
pass
"""
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 = os.path.dirname(
- __file__) + '/colorset/' + c['theme'] + '.json'
+ if c['THEME'] != themes[0]:
+ c['THEME'] = themes[0]
+ config = os.path.dirname(
+ __file__) + '/colorset/' + c['THEME'] + '.json'
# Load new config
data = load_config(config)
if data:
import time
import requests
import webbrowser
+import json
from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup
from twitter.api import *
files = os.listdir(os.path.dirname(__file__) + '/colorset')
themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
- themes += ['custom']
g['themes'] = themes
- db.theme_store(c['theme'])
+ db.theme_store(c['THEME'])
def switch():
if not g['stuff']:
# List themes
for theme in g['themes']:
- line = ''
- # Detect custom config
- if theme == 'custom':
- line += light_magenta('custom')
- custom_path = os.environ.get(
- 'HOME',
- os.environ.get('USERPROFILE',
- '')) + os.sep + '.rainbow_config.json'
- if not os.path.exists(custom_path):
- line += light_magenta(
- ' (create your own config file at ~/.rainbow_config.json)')
- else:
- line += light_magenta(' (loaded)')
- else:
- line += light_magenta(theme)
- if c['theme'] == theme:
+ line = light_magenta(theme)
+ if c['THEME'] == theme:
line = ' ' * 2 + light_yellow('* ') + line
else:
line = ' ' * 4 + line
printNicely(line)
elif g['stuff'] == 'current_as_default':
- # Set default
- path = os.path.dirname(__file__) + '/colorset/init'
- f = open(path, 'w')
- f.write(c['theme'])
- f.close()
+ # Set as default
+ def fixup(adict, k, v):
+ for key in adict.keys():
+ if key == k:
+ adict[key] = v
+ elif type(adict[key]) is dict:
+ fixup(adict[key], k, v)
+ # Modify
+ path = os.environ.get(
+ 'HOME',
+ os.environ.get(
+ 'USERPROFILE',
+ '')) + os.sep + '.rainbow_config.json'
+ data = load_config(rainbow_config)
+ fixup(data, 'THEME', c['THEME'])
+ # Save
+ with open(path, 'w') as out:
+ json.dump(data, out, indent = 4)
os.system('chmod 777 ' + path)
printNicely(light_green('Okay it will be applied from next time :)'))
else:
c[nc] = new_config[nc]
# Update db and reset colors
db.theme_update(g['stuff'])
- c['theme'] = g['stuff']
+ c['THEME'] = g['stuff']
reset_cycle()
g['decorated_name'] = color_func(
c['DECORATED_NAME'])(
'[@' + g['original_name'] + ']: ')
printNicely(green('Theme changed.'))
except:
- if g['stuff'] == 'custom':
- printNicely(red('~/.rainbow_config.json is not exists!'))
- else:
- printNicely(red('No such theme exists.'))
+ printNicely(red('No such theme exists.'))
def help_discover():
art_dict = {
c['USER_DOMAIN']: name,
c['PUBLIC_DOMAIN']: args.track_keywords,
- c['SITE_DOMAIN']: 'Site Stream',
+ c['SITE_DOMAIN']: name,
}
if g['ascii_art']:
ascii_art(art_dict[domain])
from setuptools import setup, find_packages
-import sys
+import os, sys
-version = '0.3.4'
+# Bumped version
+version = '0.3.5'
+# Require
install_requires = [
"python-dateutil",
"requests",
"twitter",
"Pillow",
]
+# Python 3 doesn't hava pysqlite
if sys.version[0] == "2":
install_requires += ["pysqlite"]
+# Copy default config if not exists
+default = os.environ.get(
+ 'HOME',
+ os.environ.get(
+ 'USERPROFILE',
+ '')) + os.sep + '.rainbow_config.json'
+if not os.path.isfile(default):
+ cmd = 'cp rainbowstream/colorset/config ' + default
+ os.system(cmd)
+
+# Setup
setup(name='rainbowstream',
version=version,
description="A smart and nice Twitter client on terminal.",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2.7",
- "Programming Language :: Python :: 3.2",
- "Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries",
"Topic :: Utilities",