コード例 #1
0
    def test_get(self):
        conf1 = TwitterConfig.update(self.u, self.key, self.secret)
        conf2 = TwitterConfig.get_by_user(self.u)

        self.assertEquals(conf1, conf2)
        self.assertEqual(self.key, conf2.token_key)
        self.assertEqual(self.secret, conf2.token_secret)
        self.assertEqual(self.u.id, conf2.user_id)
コード例 #2
0
    def test_update(self):
        conf = TwitterConfig.update(self.u, self.key, self.secret)

        self.key = 'new_key'
        self.secret = 'new_secret'
        conf = TwitterConfig.update(self.u, self.key, self.secret)

        self.assertEqual(self.key, conf.token_key)
        self.assertEqual(self.secret, conf.token_secret)
コード例 #3
0
def config():
    config = None

    if request.method == 'POST':
        form = ConfigForm()
        if form.validate_on_submit():
            config = TwitterConfig.update(login.current_user,
                                          form.token_key.data,
                                          form.token_secret.data)

    if config is None:
        config = TwitterConfig.get_by_user(login.current_user)

    return render_template('config.html',
                           current_page='Twitter Configuration',
                           twitter_config=config)
コード例 #4
0
    def setUp(self):
        super(IndexTestCase, self).setUp()

        self.username = '******'
        self.email = '*****@*****.**'
        self.password = '******'

        self.u = User.register(self.username, self.email, self.password)
        self.key = 'key'
        self.token = 'token'
        self.conf = TwitterConfig.update(self.u, self.key, self.token)
コード例 #5
0
    def setUp(self):
        super(IndexTestCase, self).setUp()

        self.username = '******'
        self.email = '*****@*****.**'
        self.password = '******'

        self.u = User.register(self.username,
                               self.email,
                               self.password)
        self.key = 'key'
        self.token = 'token'
        self.conf = TwitterConfig.update(self.u, self.key, self.token)
コード例 #6
0
def index():
    search_results = []
    search_query = None

    if flask.request.method == 'POST':
        form = SearchForm()
        if not form.validate_on_submit():
            # Form is not valid, just return to edit page.
            return render_template('index.html',
                                   current_page='Main',
                                   search_results=search_results,
                                   search_query=search_query)

        search_query = form.search_query.data

        app_key = flask.current_app.config.get('TWITTER_TOKEN_KEY', '')
        app_secret = flask.current_app.config.get('TWITTER_TOKEN_SECRET', '')
        twitter_conf = TwitterConfig.get_by_user(login.current_user)

        if twitter_conf is None:
            log.warn('Cannot get twitter config for %s' % login.current_user)
            return flask.redirect(flask.url_for('config'))

        twitter_api = auth.get_authorized_api(twitter_conf.token_key,
                                              twitter_conf.token_secret,
                                              app_key, app_secret)
        if twitter_api is None:
            log.warn('Cannot get authorized twitter API for %s' %
                     login.current_user)
            return flask.redirect(flask.url_for('config'))

        search_results = search.search(twitter_api,
                                       search_query,
                                       count=flask.current_app.config.get(
                                           'TWEETS_IN_RESULT', 50))

        for tweet in search_results:
            sent_score = sentiment_score(tweet['text'], word_scores)
            tweet[
                'sent_score'] = 'Neutral' if not sent_score else 'Positive' if sent_score > 0 else 'Negative'

    return render_template('index.html',
                           current_page='Main',
                           search_results=search_results,
                           search_query=search_query)
コード例 #7
0
def index():
    search_results = []
    search_query = None

    if flask.request.method == "POST":
        form = SearchForm()
        if not form.validate_on_submit():
            # Form is not valid, just return to edit page.
            return render_template(
                "index.html", current_page="Main", search_results=search_results, search_query=search_query
            )

        search_query = form.search_query.data

        app_key = flask.current_app.config.get("TWITTER_TOKEN_KEY", "")
        app_secret = flask.current_app.config.get("TWITTER_TOKEN_SECRET", "")
        twitter_conf = TwitterConfig.get_by_user(login.current_user)

        if twitter_conf is None:
            log.warn("Cannot get twitter config for %s" % login.current_user)
            return flask.redirect(flask.url_for("config"))

        twitter_api = auth.get_authorized_api(twitter_conf.token_key, twitter_conf.token_secret, app_key, app_secret)
        if twitter_api is None:
            log.warn("Cannot get authorized twitter API for %s" % login.current_user)
            return flask.redirect(flask.url_for("config"))

        search_results = search.search(
            twitter_api, search_query, count=flask.current_app.config.get("TWEETS_IN_RESULT", 50)
        )

        for tweet in search_results:
            sent_score = sentiment_score(tweet["text"], word_scores)
            tweet["sent_score"] = "Neutral" if not sent_score else "Positive" if sent_score > 0 else "Negative"

    return render_template("index.html", current_page="Main", search_results=search_results, search_query=search_query)
コード例 #8
0
    def test_create(self):
        conf = TwitterConfig.update(self.u, self.key, self.secret)

        self.assertEqual(self.key, conf.token_key)
        self.assertEqual(self.secret, conf.token_secret)
コード例 #9
0
 def test_get_no_existing(self):
     self.assertIsNone(TwitterConfig.get_by_user(self.u))