Exemplo n.º 1
0
def index():
    form1 = GetTwitterHandle(request.form)
    returnval = ''
    if request.method == 'POST' and form1.validate():
        user=form1.username.data
        user=user.strip("@").replace(" ", "")
        PATH='./static/img/broken_twitter.jpg'
        width = 204
        height = 248
        PATH1='./static/img/twitclouds/' + str(user) + '.png'
        # imgaddr = "{{ url_for('static', filename='img/broken_twitter.jpg') }}"
        # print PATH
        # print os.path.isfile(PATH)
        # print os.access(PATH, os.R_OK)
        if os.path.isfile(PATH1) and os.access(PATH1, os.R_OK):
            returnval = user
            print 'updated path1'
            PATH='./static/img/twitclouds/' + str(user) + '.png'
            width = 800
            height = 400
        else:
            status, code = get_data(user)
            status1, code1 = load_data(user)
            # print status
            # print str(code)
            if code > 0:
                returnval = status
                PATH='./static/img/broken_twitter.jpg'
            if code1 > 0:
                returnval = status1
                PATH='./static/img/broken_twitter.jpg'
            if code == 0 and code1 == 0:
                print get_topics(user)
                print get_cloud(user)
                print 'updated path2'
                PATH='./static/img/twitclouds/' + str(user) + '.png'
                width = 800
                height = 400
                returnval = form1.username.data
        return render_template('thanks.html', notes='@'+returnval, imagesrc=PATH, w=width, h=height)

    return render_template('index.html', form1=form1)
Exemplo n.º 2
0
def index():
    form1 = GetTwitterHandle(request.form)
    returnval = ''
    polarity=0
    subject=0
    col='#000000'
    formt = "%B %d, %Y %H:%M:%S"


    if request.method == 'POST' and form1.validate():
        user=form1.username.data
        user=user.strip("@").replace(" ", "")
        PATH='./static/img/broken_twitter.jpg'
        width = 204
        height = 248

        status, code = get_data(user)
        status1, code1 = load_data(user)

        if code > 0:
            returnval = status
            PATH='./static/img/broken_twitter.jpg'
        if code1 > 0:
            returnval = status1
            PATH='./static/img/broken_twitter.jpg'
        if code == 0 and code1 == 0:
            status2, df, pol, sub = get_top_favorites(user)
            returnval = status2

            name = df['name'][0]
            polarity = float(pol)*100
            subject = float(sub)*100

            df['date'] = pd.to_datetime(df.date)

            df1 = df.sort_values('date')
            df2 = df.sort_values('favorites', ascending=False)[:50]

            df2.drop(['numfoll', 'num', 'name'], axis=1, inplace=True)
            df2.reset_index(drop=True, inplace=True)

            dates = df1['date'].dt.strftime(formt)
            faves = df1['favorites'].tolist()
            text = [t.replace('amp;','') for t in df1['text'].tolist()]

            dates2 = df2['date'].tolist()
            faves2 = df2['favorites'].tolist()
            text1 = df2['text']
            text2 = [t.replace('amp;','') for t in text1]

            dataout = pd.DataFrame(zip(dates, faves, text), columns=['date', 'favorites', 'txt'])
            jsonout = './static/data/'+ str(user) + '.csv'
            f = open(jsonout, 'wb+')
            dataout.to_csv(f)
            returnval = '@' + str(user)

            df2_list = zip(dates2, faves2, text2)

            if len(df2_list) > 0:
                items = [Item(d,"{:,}".format(f),t) for d,f,t in df2_list]
                table1 = ItemTable(items)

            if polarity > 0:
                col='#00FF00'
            if polarity < 0:
                col='#FF0000'

        return render_template('thanks.html', user=name, notes=returnval, jsonloc=jsonout, w=width, h=height, pol=polarity, sub=subject, color=col, table1=table1)

    return render_template('index.html', form1=form1, list=listc)