Пример #1
0
def getSentiment():
    print('in server getSentiment')

    vQueries = request.args.get("Queries")
    print(vQueries)

    vQueryTerms = []
    for x in vQueries.split(';'):
        vQueryTerms.append(x.strip())
    print(vQueryTerms)

    vTweetCount = request.args.get("TweetCount")
    print(vTweetCount)

    vTimeout = request.args.get("Timeout")
    print(vTimeout)

    vFilename = request.args.get("Filename")
    vFilename = str(vFilename) + ".csv"
    print(vFilename)

    print('fetching tweets...')
    ft.streamTweets(vQueryTerms, vFilename, vTweetCount, vTimeout)
    print('all tweets fetched!!!')

    print('processing tweets...')
    pt.processTweets(vFilename)
    print('all tweets processed!!!')

    df = pd.read_csv(os.path.join(tmpFilePath, vFilename), header=None)

    print("analyzing sentiment...")
    df = sa.analyzeSentiment(df)

    # print(df)

    msg = {
        'mnb_pos_count': int((df[4] == 4).sum()),
        'mnb_neg_count': int((df[4] == 0).sum()),
        'mnb_tweets': (df.groupby([4], as_index=True).apply(lambda x: x[[0, 1]].to_dict('r')).reset_index().rename(columns={0: 'Data'}).to_json(orient='records')),

        'svm_pos_count': int((df[3] == 4).sum()),
        'svm_neg_count': int((df[3] == 0).sum()),
        'svm_tweets': (df.groupby([3], as_index=True).apply(lambda x: x[[0, 1]].to_dict('r')).reset_index().rename(columns={0: 'Data'}).to_json(orient='records')),

        'lr_pos_count': int((df[5] == 4).sum()),
        'lr_neg_count': int((df[5] == 0).sum()),
        'lr_tweets': (df.groupby([5], as_index=True).apply(lambda x: x[[0, 1]].to_dict('r')).reset_index().rename(columns={0: 'Data'}).to_json(orient='records'))
    }

    print('removing file : ' + str(vFilename))
    os.remove(os.path.join(tmpFilePath, vFilename))

    return jsonify(msg)
Пример #2
0
def TwELEC():

    # Fetch form values
    # and replace the default values
    if request.method == 'POST':

        mandatory_keywords=request.form['mkw'].split(" ")

        try:
           passd=request.form['mdp']
           if passd != s_password:
              return(render_template("error.html",cause="Echec authentification"))
        except KeyError:
              return(render_template("error.html",cause="Echec authentification"))
        
        try:
           optional_keywords=request.form['okw'].split(" ")
        except KeyError:
           optional_keywords=[]

        try:
            hours_before=request.form['hbf']
            if hours_before == '':
                hours_before=-1
            else:
                try:
                    hours_before=int(hours_before)
                except ValueError:
                    hours_before=-1
        except KeyError:
            hours_before=-1

        try:
            max_search_hits=request.form['shts']
            if max_search_hits == '':
                max_search_hits=35
            else:
                try:
                    max_search_hits=int(max_search_hits)
                except ValueError:
                    max_search_hits=35
        except KeyError:
            max_search_hits=35
            
    else:
        return(render_template("error.html",cause="Wrong method"))
        
    createDB.createDB()
    fetchTweets.fetchTweets(a_token,
                            a_secret,
                            c_key,
                            c_secret,
                            session_name,
                            mandatory_keywords,
                            optional_keywords,
                            hours_before,
                            language_string,
                            hits_page_size,
                            max_search_hits)
    processTweets.processTweets()
    return(displayToStr.displayToStr())
Пример #3
0
# Maximum number of search hits
# may be more depending on
# next multiple of hits_page_size
max_search_hits=35


# Keys to access the twitter API
c_key = ''
c_secret = ''
a_token = ''
a_secret = ''


#####################################################

createDB.createDB()
fetchTweets.fetchTweets(a_token,
                        a_secret,
                        c_key,
                        c_secret,
                        session_name,
                        mandatory_keywords,
                        optional_keywords,
                        hours_before,
                        language_string,
                        hits_page_size,
                        max_search_hits)

processTweets.processTweets()
displayToHTML.displayToHTML()