From b2b933a939fc0a10b2a6300089ac2a72d2cfb17b Mon Sep 17 00:00:00 2001 From: vunhat_minh Date: Wed, 28 May 2014 19:46:48 +0900 Subject: [PATCH] autopep8 --- rainbowstream/db.py | 9 ++++++--- rainbowstream/interactive.py | 7 ++++--- rainbowstream/rainbow.py | 39 +++++++++++++++++++++++++++--------- rainbowstream/table_def.py | 4 +++- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/rainbowstream/db.py b/rainbowstream/db.py index e0c7e84..57428c4 100644 --- a/rainbowstream/db.py +++ b/rainbowstream/db.py @@ -4,9 +4,10 @@ from sqlalchemy.orm import sessionmaker from table_def import Map from .table_def import * + class RainbowDB(): - engine=None + engine = None def __init__(self): if not os.path.isfile('rainbow.db'): @@ -29,7 +30,8 @@ class RainbowDB(): """ Session = sessionmaker(bind=self.engine) session = Session() - res = session.query(Map).filter("rainbow_id =:rid").params(rid=rid).all() + res = session.query(Map) + .filter("rainbow_id =:rid").params(rid=rid).all() return res def tweet_query(self, tid): @@ -38,7 +40,8 @@ class RainbowDB(): """ Session = sessionmaker(bind=self.engine) session = Session() - res = session.query(Map).filter("tweet_id =:tid").params(tid=tid).all() + res = session.query(Map) + .filter("tweet_id =:tid").params(tid=tid).all() return res def truncate(self): diff --git a/rainbowstream/interactive.py b/rainbowstream/interactive.py index 2b61107..e27c177 100644 --- a/rainbowstream/interactive.py +++ b/rainbowstream/interactive.py @@ -1,7 +1,8 @@ import readline + class RainbowCompleter(object): - + def __init__(self, options): """ Init @@ -16,12 +17,12 @@ class RainbowCompleter(object): response = None if state == 0: if text: - self.matches = [s + self.matches = [s for s in self.options if s and s.startswith(text)] else: self.matches = self.options[:] - + try: response = self.matches[state] except IndexError: diff --git a/rainbowstream/rainbow.py b/rainbowstream/rainbow.py index bf4c336..ba811b8 100644 --- a/rainbowstream/rainbow.py +++ b/rainbowstream/rainbow.py @@ -1,19 +1,23 @@ """ Colorful user's timeline stream """ +import os +import os.path +import sys +import signal +import argparse +import time +import datetime from __future__ import print_function from multiprocessing import Process - -import os, os.path, sys,signal -import argparse, time, datetime +from dateutil import parser from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup from twitter.api import * from twitter.oauth import OAuth, read_token_file from twitter.oauth_dance import oauth_dance from twitter.util import printNicely -from dateutil import parser from .colors import * from .config import * @@ -37,6 +41,7 @@ cmdset = [ 'q' ] + def draw(t, keyword=None): """ Draw the rainbow @@ -191,6 +196,7 @@ def tweet(): t.statuses.update(status=g['stuff']) g['prefix'] = False + def retweet(): """ ReTweet @@ -199,7 +205,7 @@ def retweet(): try: id = int(g['stuff'].split()[0]) tid = db.rainbow_query(id)[0].tweet_id - t.statuses.retweet(id=tid,include_entities=False,trim_user=True) + t.statuses.retweet(id=tid, include_entities=False, trim_user=True) except: print(red('Sorry I can\'t retweet for you.')) g['prefix'] = False @@ -252,7 +258,7 @@ def search(): print(red('A keyword should be a hashtag (like \'#AKB48\')')) except: print(red('Sorry I can\'t understand.')) - + def friend(): """ @@ -316,7 +322,7 @@ def quit(): """ Exit all """ - db.truncate() + db.truncate() os.kill(g['stream_pid'], signal.SIGKILL) sys.exit() @@ -334,14 +340,27 @@ def process(cmd): """ return dict(zip( cmdset, - [home,view,tweet,retweet,reply,delete,search,friend,follower,help,clear,quit] + [ + home, + view, + tweet, + retweet, + reply, + delete, + search, + friend, + follower, + help, + clear, + quit + ] )).get(cmd, reset) def listen(): init_interactive_shell(cmdset) - first = True - while True: + first = True + while True: if g['prefix'] and not first: line = raw_input(g['decorated_name']) else: diff --git a/rainbowstream/table_def.py b/rainbowstream/table_def.py index f8597f6..c312bde 100644 --- a/rainbowstream/table_def.py +++ b/rainbowstream/table_def.py @@ -4,6 +4,7 @@ from sqlalchemy.ext.declarative import declarative_base engine = create_engine('sqlite:///rainbow.db', echo=False) Base = declarative_base() + class Map(Base): __tablename__ = "map" @@ -14,5 +15,6 @@ class Map(Base): def __init__(self, tweet_id): self.tweet_id = tweet_id + def init_db(): - Base.metadata.create_all(engine) \ No newline at end of file + Base.metadata.create_all(engine) -- 2.25.1