import os
import os.path
+from .db import *
+
+db = RainbowDB()
+
# Regular expression for comments
comment_re = re.compile(
'(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
while match:
content = content[:match.start()] + content[match.end():]
match = comment_re.search(content)
+ db.theme_store('user')
return json.loads(content)
- except:
+ except IOError:
+ db.theme_store('default')
pass
# Load default colorset
import os
from sqlalchemy import create_engine
+from sqlalchemy import update
from sqlalchemy.orm import sessionmaker
from .table_def import *
"""
Session = sessionmaker(bind=self.engine)
session = Session()
- m = Tweet(tweet_id)
- session.add(m)
+ t = Tweet(tweet_id)
+ session.add(t)
session.commit()
def rainbow_to_tweet_query(self, rid):
session = Session()
res = session.query(Message).filter_by(message_id=mid).all()
return res
+
+ def theme_store(self, theme_name):
+ """
+ Store theme
+ """
+ Session = sessionmaker(bind=self.engine)
+ session = Session()
+ th = Theme(theme_name)
+ session.add(th)
+ session.commit()
+
+ def theme_update(self, theme_name):
+ """
+ Update theme
+ """
+ Session = sessionmaker(bind=self.engine)
+ session = Session()
+ res = session.query(Theme).all()
+ for r in res:
+ r.theme_name = theme_name
+ session.commit()
+
+ def theme_query(self):
+ """
+ Query theme
+ """
+ Session = sessionmaker(bind=self.engine)
+ session = Session()
+ res = session.query(Theme).all()
+ return res
from .db import *
db = RainbowDB()
+cur_theme = None
+
+def check_theme():
+ """
+ Check current theme and update if necessary
+ """
+ exists = db.theme_query()
+ themes = [t.theme_name for t in exists]
+ if cur_theme != themes[0]:
+ cur_theme = themes[0]
+ # Determine path
+ if cur_theme == 'user':
+ config = os.environ.get(
+ 'HOME',
+ os.environ.get(
+ 'USERPROFILE',
+ '')) + os.sep + '.rainbow_config.json'
+ else:
+ config = 'rainbowstream/colorset/'+cur_theme+'.json'
+ # Load new config
+ data = load_config(config)
+ for d in data:
+ c[d] = data[d]
def color_func(func_name):
Draw the rainbow
"""
+ check_theme()
# Retrieve tweet
tid = t['id']
text = t['text']
files = os.listdir('rainbowstream/colorset')
themes = [f.split('.')[0] for f in files if f.split('.')[-1] == 'json']
+ themes += ['user']
g['themes'] = themes
"""
if not g['stuff']:
# List themes
+ line = ' ' * 2 + light_yellow('* ')
for theme in g['themes']:
- line = ' ' * 2 + light_yellow('* ' + theme)
+ # Detect custom config
+ if theme == 'user':
+ line += light_magenta('custom')
+ exists = db.theme_query()
+ themes = [t.theme_name for t in exists]
+ if themes[0] == 'user':
+ line += light_magenta(' (applied)')
+ else:
+ line += light_magenta(' (not specified)')
+ else:
+ line += light_magenta(theme)
printNicely(line)
else:
# Change theme
new_config = load_config(new_config)
for nc in new_config:
c[nc] = new_config[nc]
- # Reset stream
- g['stuff'] = 'mine'
- g['ascii_art'] = False
- switch()
+ # Update db
+ theme_update(g['stuff'])
g['decorated_name'] = color_func(
c['DECORATED_NAME'])(
'[@' + g['original_name'] + ']: ')
self.message_id = message_id
+class Theme(Base):
+
+ __tablename__ = "theme"
+
+ theme_id = Column(Integer, primary_key=True)
+ theme_name = Column(String)
+ changed = Column(Boolean, default=False)
+
+ def __init__(self, theme_name):
+ self.theme_name = theme_name
+ self.Boolean = False
+
+
def init_db():
Base.metadata.create_all(engine)