Exemplo n.º 1
0
def list_twitter_status(request, limitnumber=0, maxnumber=150):

    #Dev
    client = MongoClient(server, port)

    #Prod
    #client = MongoClient('127.0.0.1', 27017)

    limitnumber = int(limitnumber)
    maxnumber = int(maxnumber)

    data = client.SilverEye.twitterPolitical.find()[limitnumber:maxnumber]

    dataSend = []

    for tweet in data:

        text = tweet['text'].encode('utf8')

        sentiment = opener.analyze_text(text)
        #print sentiment
        color = get_color_by_sentiment(sentiment)
        entities = get_entities(text)
        relevantTweet = {'tweet': tweet['text'], 'sentiment': sentiment, 'place': tweet['place'], 'color':color, 'entities': entities}

        dataSend.append(relevantTweet)

    return render(request, 'listStatusTwitter.html', {'status': dataSend})
Exemplo n.º 2
0
def text_analysis(request):

    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = AnalysisForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            results = opener.analyze_text(form.data['data'])

            return render(request, 'sentimentQuery.html', {'form': form, 'results': results, 'text': form.data['data']})

    # if a GET (or any other method) we'll create a blank form
    else:
        form = AnalysisForm()

    return render(request, 'sentimentQuery.html', {'form': form})