Exemplo n.º 1
0
def all_search():
    all_form = AllCongSearchForm()
    if all_form.is_submitted():
        dynamic = all_form.scope_search.data
        time_delta = all_form.allcong_time_delta.data
        flash('Your request({0}) has been submitted, with delta(days)={1}'.format(dynamic, \
        time_delta))
        return redirect(
            url_for('overview', dynamic=dynamic, time_delta=time_delta))
    return render_template('index.html', title ='Home', all_form=all_form, \
    h_form=HashtagSearchForm(), p_form=PhraseSearchForm(), d_form=DistrictForm(),\
    botform=BotSearchForm(), sen_form=SenForm())
Exemplo n.º 2
0
def index():
    url = request.path
    feed = blogfeed()

    return render_template('index_withblog.html', title ='Home', d_form=DistrictForm(), \
    h_form=HashtagSearchForm(), p_form=PhraseSearchForm(), all_form=AllCongSearchForm(),\
    botform=BotSearchForm(), sen_form=SenForm(), url=url, feed=feed)
Exemplo n.º 3
0
def phrase_search():
    p_form = PhraseSearchForm()
    if p_form.validate_on_submit():
        flash('Your request has been submitted')
        return redirect(url_for('index'))

    return render_template('index.html', title ='Home', p_form=p_form, \
    all_form=AllCongSearchForm(), d_form=DistrictForm(), \
    h_form=HashtagSearchForm(), sen_form=SenForm())
Exemplo n.º 4
0
def bot_search():
    botform = BotSearchForm()
    if botform.is_submitted():
        dynamic = botform.scope_search.data
        time_delta = botform.botform_time_delta.data

        return redirect(
            url_for('botspy', dynamic=dynamic, time_delta=time_delta))
    return render_template('index.html', title ='Home', all_form=AllCongSearchForm(), \
    h_form=HashtagSearchForm(), p_form=PhraseSearchForm(), d_form=DistrictForm(),\
    botform=botform, sen_form=SenForm())
Exemplo n.º 5
0
def hashtag_search():
    h_form = HashtagSearchForm(meta={'csrf': False})
    if h_form.validate_on_submit():
        dynamic = h_form.hashtag_search.data
        time_delta = h_form.hashtag_time_delta.data
        flash('Your hashtag({0}) has been submitted, with delta(days)={1}'.format(dynamic, \
        time_delta))

        dynamic = dynamic.lstrip('#').lower()

        if db.session.query(Hashtag).filter(
                Hashtag.hashtag == dynamic).first():
            return redirect(
                url_for('hashtag', dynamic=dynamic, time_delta=time_delta))
        else:
            return redirect(url_for('doesnt_exist', dynamic=dynamic))

    return render_template('index.html', title ='Home', h_form=h_form, \
    p_form=PhraseSearchForm(), d_form=DistrictForm(), all_form=AllCongSearchForm(),\
    botform=BotSearchForm(), sen_form=SenForm())
Exemplo n.º 6
0
def select_district():
    d_form = DistrictForm()
    sen_form = SenForm()
    #    if request.method == 'POST':
    if d_form.is_submitted():
        dynamic = d_form.select_district.data
        time_delta = d_form.district_time_delta.data
        flash('Your request({0}) has been submitted, with delta(days)={1}'.format(dynamic, \
        time_delta))
        return redirect(
            url_for('district', dynamic=dynamic, time_delta=time_delta))

    if sen_form.is_submitted():
        dynamic = sen_form.select_district.data
        time_delta = sen_form.district_time_delta.data
        flash('Your request({0}) has been submitted, with delta(days)={1}'.format(dynamic, \
        time_delta))
        return redirect(
            url_for('district', dynamic=dynamic, time_delta=time_delta))

    return render_template('index.html', title='Home', d_form=d_form, \
    p_form=PhraseSearchForm(), h_form=HashtagSearchForm(), all_form=AllCongSearchForm(),\
    botform=BotSearchForm(), sen_form=SenForm())
Exemplo n.º 7
0
def overview(dynamic):

    print('starting district group {}'.format(dynamic))
    time_delta = request.args.get('time_delta')
    url = request.path
    str_time_range = stringtime(time_delta)

    today = datetime.combine(
        date.today(), datetime.min.time())  #datetime object for midnight
    str_today = today.strftime(
        "%Y-%m-%d %H:%M:%S")  # string version of midnight

    conn = db.engine.connect()

    # GET 10-day table data for hashtag chart from graph_functions module
    # RETURN THIS TO TEMPLATE

    # Get a desc-ordered list of all hashtags being used in all districts
    # Object returns (hashtag, count)
    all_hashes_result = conn.execute('SELECT hashtag, count FROM hash_activity_{0}_{1};'.\
    format(dynamic, time_delta)).fetchall()

    #RETURN THIS TO TEMPLATE
    all_hashes = []

    for item in all_hashes_result:
        all_hashes.append(item)

    print("got all_hashes")

    #Get a list of tophashtags without district names
    # RETURN THIS TO TEMPLATE
    hashes_no_dists = []
    counter = 0
    for item in all_hashes:
        if item[0] not in distlist:
            hashes_no_dists.append(item)
            counter += 1
        if counter == 20:
            break

    # RETURN THIS TO TEMPLATE
    all_tweets = db.session.query(func.count(Post.post_id)).\
    filter(Post.created_at_dt >= str_time_range).first()

    print("got all tweets")

    #Get list of most active districts

    active_dists_result = conn.execute('SELECT district_name, count FROM dist_activity_{0}_{1};'.\
    format(dynamic, time_delta)).fetchall()

    # RETURN THIS TO TEMPLATE
    most_active = []

    for item in active_dists_result:
        most_active.append(item)

    print("got most_active")

    # Get a desc-ordered list of top-volume Tweeters
    top_tweeters_result = conn.execute('SELECT user_scrname, count, user_cap_perc FROM top_tweeters_{0}_{1};'.\
    format(dynamic, time_delta)).fetchall()

    # RETURN THIS TO TEMPLATE
    top_tweeters = []

    for item in top_tweeters_result:
        new_row = []
        new_row.append(item[0])
        new_row.append(item[1])
        if item[2] == -1.0:
            new_row.append("Not yet in database")
        else:
            new_row.append(item[2])
        top_tweeters.append(new_row)

    print("got top_tweeters")

    retweeted_users_result = conn.execute('SELECT original_author_scrname, count FROM retweeted_users_{0}_{1};'.\
    format(dynamic, time_delta)).fetchall()

    # RETURN THIS TO TEMPLATE
    retweeted_users = []

    for item in retweeted_users_result:
        retweeted_users.append(item)

    print("got retweeted users")

    retweeted_tweets_result = conn.execute('SELECT post_id, original_poster, retweet_count, botscore FROM retweeted_tweets_{0}_{1};'.\
    format(dynamic, time_delta)).fetchall()

    # RETURN THIS TO TEMPLATE
    most_retweeted_tweet_list = []
    tweet_count = 0
    # Each item (tuple) is post_id, poster, count, botscore. Still need HTML
    for item in retweeted_tweets_result:

        # if original_author_scrname is in skip list, skip it
        if item[1].lower() in skip_list:
            continue

        #create list with attributes
        holding_list = []
        for attribute in item:
            holding_list.append(attribute)

        # Get Tweet HTML, add to list
        try:
            tweet_text = get_tweet(item[0])
            holding_list.append(tweet_text)
        except:
            holding_list.append("Can't retrieve tweet")

        most_retweeted_tweet_list.append(holding_list)
        tweet_count += 1
        if tweet_count == 5:
            break

    print("got most retweeted tweets")




    hash_pickled = db.session.query(District_graphs.chart_rows).\
    filter(District_graphs.reference_date==str_today).\
    filter(District_graphs.district_name==dynamic).first()

    if hash_pickled != None:
        hashtable_all = pickle.loads(hash_pickled[0])
    else:
        hashtable_all = gf.get_hashrows_overview(dynamic)

    print("got hashtable")

    conn.close()

    return render_template('overview.html', t_form=ChangeTimeForm(), \
    all_form=AllCongSearchForm(), dynamic=dynamic, time_delta=time_delta, \
    url=url, all_hashes=all_hashes,  hashes_no_dists=hashes_no_dists, \
    hashtable_all=hashtable_all, all_tweets=all_tweets,\
    most_retweeted_tweet_list=most_retweeted_tweet_list,\
    top_tweeters=top_tweeters, retweeted_users=retweeted_users,
    most_active=most_active\
    )