Ejemplo n.º 1
0
def index():
    oauth_token, oauth_token_secret = session.get('twitter_token',
                                                  (None, None))
    form = AnalyzeForm(request.form)
    if session.get('lists'):
        form.lst.choices = ([('none', 'No list')] +
                            [(str(l['id']), l['name'])
                             for l in session['lists']])
    else:
        del form.lst

    results = {}
    list_name = list_id = error = None
    if request.method == 'POST' and form.validate() and form.user_id.data:
        # Don't show auth'ed user's lists in results for another user.
        if (hasattr(form, 'lst')
                and form.user_id.data != session.get('twitter_user')):
            del form.lst

        if app.config['DRY_RUN']:
            list_name = None
            friends, followers, timeline = dry_run_analysis()
            results = {
                'friends': friends,
                'followers': followers,
                'timeline': timeline
            }
        else:
            if session.get('lists') and form.lst and form.lst.data != 'none':
                list_id = int(form.lst.data)
                list_name = [
                    l['name'] for l in session['lists']
                    if int(l['id']) == list_id
                ][0]

            try:
                api = get_twitter_api(CONSUMER_KEY, CONSUMER_SECRET,
                                      oauth_token, oauth_token_secret)
                cache = Cache()
                results = {
                    'friends':
                    analyze_friends(form.user_id.data, list_id, api, cache),
                    'followers':
                    analyze_followers(form.user_id.data, api, cache),
                    'timeline':
                    analyze_timeline(form.user_id.data, list_id, api, cache)
                }
            except Exception as exc:
                import traceback
                traceback.print_exc()
                error = exc

    return render_template('index.html',
                           form=form,
                           results=results,
                           error=error,
                           div=div,
                           list_name=list_name,
                           TRACKING_ID=TRACKING_ID)
Ejemplo n.º 2
0
def index():
    oauth_token, oauth_token_secret = session.get('twitter_token',
                                                  (None, None))
    form = AnalyzeForm(request.form)
    results = {}
    error = None
    if request.method == 'POST' and form.validate() and form.user_id.data:
        if app.config['DRY_RUN']:
            time.sleep(2)
            results = {
                'friends': {
                    'ids_fetched': 0,
                    'ids_sampled': 500,
                    'nonbinary': 10,
                    'men': 200,
                    'women': 40,
                    'andy': 250
                },
                'followers': {
                    'ids_fetched': 0,
                    'ids_sampled': 500,
                    'nonbinary': 10,
                    'men': 200,
                    'women': 40,
                    'andy': 250
                }
            }
        else:
            try:
                results = {
                    'friends':
                    analyze_friends(form.user_id.data, CONSUMER_KEY,
                                    CONSUMER_SECRET, oauth_token,
                                    oauth_token_secret),
                    'followers':
                    analyze_followers(form.user_id.data, CONSUMER_KEY,
                                      CONSUMER_SECRET, oauth_token,
                                      oauth_token_secret)
                }
            except Exception as exc:
                import traceback
                traceback.print_exc()
                error = exc

    return render_template('index.html',
                           form=form,
                           results=results,
                           error=error,
                           div=div,
                           TRACKING_ID=TRACKING_ID)
Ejemplo n.º 3
0
def index():
    oauth_token, oauth_token_secret = session.get('twitter_token', (None, None))
    form = AnalyzeForm(request.form)
    if session.get('lists'):
        form.lst.choices = (
            [('none', 'No list')]
            + [(unicode(l['id']), l['name']) for l in session['lists']]
        )
    else:
        del form.lst

    results = {}
    list_name = list_id = error = None
    if request.method == 'POST' and form.validate() and form.user_id.data:
        # Don't show auth'ed user's lists in results for another user.
        if (hasattr(form, 'lst')
            and form.user_id.data != session.get('twitter_user')):
            del form.lst

        if app.config['DRY_RUN']:
            list_name = None
            friends, followers, timeline = dry_run_analysis()
            results = {'friends': friends,
                       'followers': followers,
                       'timeline': timeline}
        else:
            if session.get('lists') and form.lst and form.lst.data != 'none':
                list_id = int(form.lst.data)
                list_name = [l['name'] for l in session['lists'] if
                             int(l['id']) == list_id][0]

            try:
                api = get_twitter_api(CONSUMER_KEY, CONSUMER_SECRET,
                                      oauth_token, oauth_token_secret)
                cache = Cache()
                results = {
                    'friends': analyze_friends(
                        form.user_id.data, list_id, api, cache),
                    'followers': analyze_followers(
                        form.user_id.data, api, cache),
                    'timeline': analyze_timeline(
                        list_id, api, cache)}
            except Exception as exc:
                import traceback
                traceback.print_exc()
                error = exc

    return render_template('index.html',
                           form=form, results=results, error=error, div=div,
                           list_name=list_name, TRACKING_ID=TRACKING_ID)
Ejemplo n.º 4
0
def index():
    oauth_token, oauth_token_secret = session.get('twitter_token',
                                                  (None, None))
    form = AnalyzeForm(request.form)
    if session.get('lists'):
        form.lst.choices = [('none', 'No list')] + [
            (unicode(l['id']), l['name']) for l in session['lists']
        ]
    else:
        del form.lst

    results = {}
    list_name = list_id = error = None
    if request.method == 'POST' and form.validate() and form.user_id.data:
        # Don't show auth'ed user's lists in results for another user.
        if (hasattr(form, 'lst')
                and form.user_id.data != session.get('twitter_user')):
            del form.lst

        if app.config['DRY_RUN']:
            time.sleep(2)
            list_name = list_id = None
            results = {
                'friends': {
                    'ids_fetched': 0,
                    'ids_sampled': 500,
                    'nonbinary': 10,
                    'men': 200,
                    'women': 40,
                    'andy': 250
                },
                'followers': {
                    'ids_fetched': 0,
                    'ids_sampled': 500,
                    'nonbinary': 10,
                    'men': 200,
                    'women': 40,
                    'andy': 250
                }
            }
        else:
            if session.get('lists') and form.lst and form.lst.data != 'none':
                list_id = int(form.lst.data)
                list_name = [
                    l['name'] for l in session['lists']
                    if int(l['id']) == list_id
                ][0]

            try:
                results = {
                    'friends':
                    analyze_friends(form.user_id.data, list_id, CONSUMER_KEY,
                                    CONSUMER_SECRET, oauth_token,
                                    oauth_token_secret),
                    'followers':
                    analyze_followers(form.user_id.data, CONSUMER_KEY,
                                      CONSUMER_SECRET, oauth_token,
                                      oauth_token_secret)
                }
            except Exception as exc:
                import traceback
                traceback.print_exc()
                error = exc

    return render_template('index.html',
                           form=form,
                           results=results,
                           error=error,
                           div=div,
                           list_name=list_name,
                           TRACKING_ID=TRACKING_ID)