<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Twitter_Sentiment_Analysis_with_NLTK</id>
	<title>Twitter Sentiment Analysis with NLTK - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Twitter_Sentiment_Analysis_with_NLTK"/>
	<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Twitter_Sentiment_Analysis_with_NLTK&amp;action=history"/>
	<updated>2026-04-20T09:09:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=Twitter_Sentiment_Analysis_with_NLTK&amp;diff=46830&amp;oldid=prev</id>
		<title>Onnowpurbo: Created page with &quot;Now that we have a sentiment analysis module, we can apply it to just about any text, but preferrably short bits of text, like from Twitter! To do this, we&#039;re going to combine...&quot;</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=Twitter_Sentiment_Analysis_with_NLTK&amp;diff=46830&amp;oldid=prev"/>
		<updated>2017-01-31T10:39:42Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Now that we have a sentiment analysis module, we can apply it to just about any text, but preferrably short bits of text, like from Twitter! To do this, we&amp;#039;re going to combine...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Now that we have a sentiment analysis module, we can apply it to just about any text, but preferrably short bits of text, like from Twitter! To do this, we&amp;#039;re going to combine this tutorial with the Twitter streaming API tutorial.&lt;br /&gt;
&lt;br /&gt;
The initial code from that tutorial is:&lt;br /&gt;
&lt;br /&gt;
from tweepy import Stream&lt;br /&gt;
from tweepy import OAuthHandler&lt;br /&gt;
from tweepy.streaming import StreamListener&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#consumer key, consumer secret, access token, access secret.&lt;br /&gt;
ckey=&amp;quot;fsdfasdfsafsffa&amp;quot;&lt;br /&gt;
csecret=&amp;quot;asdfsadfsadfsadf&amp;quot;&lt;br /&gt;
atoken=&amp;quot;asdf-aassdfs&amp;quot;&lt;br /&gt;
asecret=&amp;quot;asdfsadfsdafsdafs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class listener(StreamListener):&lt;br /&gt;
&lt;br /&gt;
    def on_data(self, data):&lt;br /&gt;
        print(data)&lt;br /&gt;
        return(True)&lt;br /&gt;
&lt;br /&gt;
    def on_error(self, status):&lt;br /&gt;
        print status&lt;br /&gt;
&lt;br /&gt;
auth = OAuthHandler(ckey, csecret)&lt;br /&gt;
auth.set_access_token(atoken, asecret)&lt;br /&gt;
&lt;br /&gt;
twitterStream = Stream(auth, listener())&lt;br /&gt;
twitterStream.filter(track=[&amp;quot;car&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
That is enough to print out all of the data for the streaming live tweets that contain the term &amp;quot;car.&amp;quot; We can use the json module to load the data var with json.loads(data), and then we can reference the tweet specifically with:&lt;br /&gt;
&lt;br /&gt;
tweet = all_data[&amp;quot;text&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
Now that we have a tweet, we can easily pass this through our sentiment_mod module!&lt;br /&gt;
&lt;br /&gt;
from tweepy import Stream&lt;br /&gt;
from tweepy import OAuthHandler&lt;br /&gt;
from tweepy.streaming import StreamListener&lt;br /&gt;
import json&lt;br /&gt;
import sentiment_mod as s&lt;br /&gt;
&lt;br /&gt;
#consumer key, consumer secret, access token, access secret.&lt;br /&gt;
ckey=&amp;quot;asdfsafsafsaf&amp;quot;&lt;br /&gt;
csecret=&amp;quot;asdfasdfsadfsa&amp;quot;&lt;br /&gt;
atoken=&amp;quot;asdfsadfsafsaf-asdfsaf&amp;quot;&lt;br /&gt;
asecret=&amp;quot;asdfsadfsadfsadfsadfsad&amp;quot;&lt;br /&gt;
&lt;br /&gt;
from twitterapistuff import *&lt;br /&gt;
&lt;br /&gt;
class listener(StreamListener):&lt;br /&gt;
&lt;br /&gt;
    def on_data(self, data):&lt;br /&gt;
&lt;br /&gt;
		all_data = json.loads(data)&lt;br /&gt;
&lt;br /&gt;
		tweet = all_data[&amp;quot;text&amp;quot;]&lt;br /&gt;
		sentiment_value, confidence = s.sentiment(tweet)&lt;br /&gt;
		print(tweet, sentiment_value, confidence)&lt;br /&gt;
&lt;br /&gt;
		if confidence*100 &amp;gt;= 80:&lt;br /&gt;
			output = open(&amp;quot;twitter-out.txt&amp;quot;,&amp;quot;a&amp;quot;)&lt;br /&gt;
			output.write(sentiment_value)&lt;br /&gt;
			output.write(&amp;#039;\n&amp;#039;)&lt;br /&gt;
			output.close()&lt;br /&gt;
&lt;br /&gt;
		return True&lt;br /&gt;
&lt;br /&gt;
    def on_error(self, status):&lt;br /&gt;
        print(status)&lt;br /&gt;
&lt;br /&gt;
auth = OAuthHandler(ckey, csecret)&lt;br /&gt;
auth.set_access_token(atoken, asecret)&lt;br /&gt;
&lt;br /&gt;
twitterStream = Stream(auth, listener())&lt;br /&gt;
twitterStream.filter(track=[&amp;quot;happy&amp;quot;])&lt;br /&gt;
&lt;br /&gt;
Along with that, we&amp;#039;re also saving the results to an output file, twitter-out.txt.&lt;br /&gt;
&lt;br /&gt;
Next, what data analysis would be complete without graphs? Let&amp;#039;s combine yet another tutorial with this one to make a live streaming graph from the sentiment analysis on the Twitter API!&lt;br /&gt;
&lt;br /&gt;
The next tutorial: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Referensi==&lt;br /&gt;
&lt;br /&gt;
* https://pythonprogramming.net/twitter-sentiment-analysis-nltk-tutorial/&lt;/div&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
</feed>