Use bokeh

On Nov 9, 2017 1:44 PM, "Derek" <gamesb...@gmail.com> wrote:

> Hi
>
> Its unlikely anyone on this list will write your code - but the good news
> is that are lots of helpful tutorials from which you can learn to do this;
> for example:
>
> * https://docs.djangoproject.com/en/1.11/intro/tutorial04/
> * https://tutorial.djangogirls.org/en/django_forms/
> * https://www.simplifiedpython.net/django-forms-tutorial-working-forms/
>
> Its likely though, that you might need to work through some of the other
> material so you can understand how and where forms fit into the overall
> Django approach.
>
> Hope this helps
> Derek
>
>
> On Friday, 3 November 2017 18:08:58 UTC+2, Rizal M. wrote:
>>
>> I have custom python script for twitter sentiment analysis, let's call it
>> sentiment.py
>> it has two inputs, topic query and number of tweets.
>>
>> this is the full code
>>
>> import sys
>> import csv
>> import tweepy
>> import matplotlib.pyplot as plt
>>
>> from collections import Counter
>> from aylienapiclient import textapi
>>
>> if sys.version_info[0] < 3:
>>    input = raw_input()
>>
>> ## Twitter credentials
>> consumer_key = "xxx"
>> consumer_secret = "xxx"
>> access_token = "xxx"
>> access_token_secret = "xxx"
>>
>> ## AYLIEN credentials
>> application_id = "xxx"
>> application_key = "xxx"
>>
>> ## set up an instance of Tweepy
>> auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
>> auth.set_access_token(access_token, access_token_secret)
>> api = tweepy.API(auth)
>>
>> ## set up an instance of the AYLIEN Text API
>> client = textapi.Client(application_id, application_key)
>>
>> ## search Twitter for something that interests you
>> query = input("topic? \n")
>> number = input("number of tweets? \n")
>>
>> results = api.search(
>>    lang="en",
>>    q=query + " -rt",
>>    count=number,
>>    result_type="recent"
>> )
>>
>> print("--- Gathered Tweets \n")
>>
>> ## open a csv file to store the Tweets and their sentiment
>> file_name = 'Sentiment_Analysis_of_{}_Tweets_About_{}.csv'.format(number, 
>> query)
>>
>> with open(file_name, 'w', newline='') as csvfile:
>>    csv_writer = csv.DictWriter(
>>        f=csvfile,
>>        fieldnames=["Tweet", "Sentiment"]
>>    )
>>    csv_writer.writeheader()
>>
>>    print("--- Opened a CSV file to store the results of your sentiment 
>> analysis... \n")
>>
>> ## tidy up the Tweets and send each to the AYLIEN Text API
>>    for c, result in enumerate(results, start=1):
>>        tweet = result.text
>>        tidy_tweet = tweet.strip().encode('ascii', 'ignore')
>>
>>        if len(tweet) == 0:
>>            print('Empty Tweet')
>>            continue
>>
>>        response = client.Sentiment({'text': tidy_tweet})
>>        csv_writer.writerow({
>>            'Tweet': response['text'],
>>            'Sentiment': response['polarity']
>>        })
>>
>>        print("Analyzed Tweet {}".format(c))
>>
>> ## count the data in the Sentiment column of the CSV file
>> with open(file_name, 'r') as data:
>>    counter = Counter()
>>    for row in csv.DictReader(data):
>>        counter[row['Sentiment']] += 1
>>
>>    positive = counter['positive']
>>    negative = counter['negative']
>>    neutral = counter['neutral']
>>
>> ## declare the variables for the pie chart, using the Counter variables for 
>> "sizes"
>> colors = ['limegreen', 'dodgerblue', 'darkorchid']
>> sizes = [positive, negative, neutral]
>> labels = 'Positif', 'Negatif', 'Netral'
>> explode = (0.1, 0, 0)
>>
>> ## use matplotlib to plot the chart
>> plt.pie(
>>     x=sizes,
>>     shadow=False,
>>     colors=colors,
>>     labels=labels,
>>     startangle=90,
>>     explode=explode,
>>     autopct='%1.0f%%'
>> )
>> plt.axis('equal')
>> plt.title("Sentiment of {} Tweets about {}".format(number, query))
>> plt.show()
>>
>>
>> how to execute that file in html web page.
>> let's say in the web page, there are two input texts, topic and number,
>> and when I press the submit button, it executes the python script.
>>
>> I'm new to this Django so please explain it with detail,
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/bb4e6be3-5e89-4c9a-bdb2-80fe24bb2a22%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/bb4e6be3-5e89-4c9a-bdb2-80fe24bb2a22%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAcanssCQR%2BaYbDdELJs8dp-gQ4VpJGj8gmmJNND9yhiWO1LhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to