示例#1
0
def _connect(connect_url=None, config_path=None):
    if connect_url is None:
        connect_url, cfg_path = read_db(config_path)
        if connect_url is None:
            raise IOError(
                'Couldn\'t read config file in "{0}"'.format(cfg_path))
    return create_engine(connect_url)
示例#2
0
def list_users(tracked):
    conf, err = read_db()
    with db.session(conf) as s:
        for u in s.query(db.User):
            if tracked and not u.is_tracking:
                continue
            click.echo('{team} {name}'.format(team=u.team, name=u.screen_name))
示例#3
0
def list_users(tracked):
    conf, err = read_db()
    with db.session(conf) as s:
        for u in s.query(db.User):
            if tracked and not u.is_tracking:
                continue
            click.echo('{team} {name}'.format(team=u.team,
                                              name=u.screen_name))
示例#4
0
def add_user(team, users):
    if len(team) != 3:
        raise IOError()
    conf, err = read_db()
    with db.session(conf) as s:
        for u in users:
            twit_user = listener.get_api().get_user(u)
            if not twit_user:
                continue
            db_user = listener.get_user(s, twit_user)
            db_user.team = team
            db_user.is_tracking = True
            s.merge(db_user)
            click.echo('Added {name}'.format(name=db_user.screen_name))
示例#5
0
def add_user(team, users):
    if len(team) != 3:
        raise IOError()
    conf, err = read_db()
    with db.session(conf) as s:
        for u in users:
            twit_user = listener.get_api().get_user(u)
            if not twit_user:
                continue
            db_user = listener.get_user(s, twit_user)
            db_user.team = team
            db_user.is_tracking = True
            s.merge(db_user)
            click.echo('Added {name}'.format(name=db_user.screen_name))
示例#6
0
def _connect(connect_url=None, config_path=None):
    if connect_url is None:
        connect_url, cfg_path = read_db(config_path)
        if connect_url is None:
            raise IOError('Couldn\'t read config file in "{0}"'.format(cfg_path))
    return create_engine(connect_url)
示例#7
0
        retweet.count += 1
    else:
        retweet = db.Retweet(user=get_user(session, user),
                             tweet=add_get_tweet(session, status),
                             count=1)
    session.merge(retweet)


def get_user_id(api, user):
    u = api.get_user(user)
    return u.id_str


def get_api():
    twitter_config, cfg_path = read_twitter()
    if twitter_config is None:
        raise IOError('Couldn\'t read config file in "{0}"'.format(cfg_path))
    auth = tweepy.OAuthHandler(twitter_config['consumer_key'],
                               twitter_config['consumer_secret'])
    auth.set_access_token(twitter_config['access_token'],
                          twitter_config['access_token_secret'])
    return tweepy.API(auth)


def run(users, async=False):
    api = get_api()
    conf, err = read_db()
    stream = tweepy.Stream(api.auth, DreadListener(api, conf))
    follow = [get_user_id(api, u) for u in users]
    stream.filter(follow=follow, languages=['en'], async=async)
示例#8
0
def add_retweet(session, user, status):
    retweet = session.query(db.Retweet).filter_by(user_id=user.id, tweet_id=status.id).one_or_none()
    if retweet:
        retweet.count += 1
    else:
        retweet = db.Retweet(user=get_user(session, user), tweet=add_get_tweet(session, status), count=1)
    session.merge(retweet)


def get_user_id(api, user):
    u = api.get_user(user)
    return u.id_str


def get_api():
    twitter_config, cfg_path = read_twitter()
    if twitter_config is None:
        raise IOError('Couldn\'t read config file in "{0}"'.format(cfg_path))
    auth = tweepy.OAuthHandler(twitter_config['consumer_key'], twitter_config['consumer_secret'])
    auth.set_access_token(twitter_config['access_token'], twitter_config['access_token_secret'])
    return tweepy.API(auth)


def run(users, async=False):
    api = get_api()
    conf, err = read_db()
    stream = tweepy.Stream(api.auth, DreadListener(api, conf))
    follow = [get_user_id(api, u) for u in users]
    stream.filter(follow=follow, languages=['en'], async=async)