Sentiment140 is on GoogleApp Engine, so you can bet they are using Python to do the task. Python is really good for this and has great libraries for Sentiment Analysis (NLTK) and consume the twitter APIs. There are also great tutorials out there. You could follow this steps:
- Grab the last N tweets for your keyword (with tweepy lib) Example provided.
- Store them in an array
- Pass the array to a Bayesian Classifier built with Python's NLTK [see links]
- Get the result of the analysis in near real-time
- Present them to the user if you want (in a Django/Flask template, etc)
Getting N tweets from the twitter API
Example with tweepy (returns the last 10 tweet with the keyword 'Lionel Messi')
#!/usr/bin/env python
import tweepy
ckey = 'xxx'
csecret = 'xxx'
atoken = 'xxx'
asecret = 'xxx'
auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
api = tweepy.API(auth)
tweets = [] # You pass this array to the Bayesian Classifier
for tweet in tweepy.Cursor(api.search,
q="Lionel Messi",
result_type="recent",
include_entities=True,
lang="en").items(10):
print tweet.created_at, tweet.text
tweets.append(tweet.text) # Store the tweets in your array
Building a Naive Bayes Classifier
Examples about how to build your classifier and nice resources:
http://ravikiranj.net/drupal/201205/code/machine-learning/how-build-twitter-sentiment-analyzer
https://github.com/ravikiranj/twitter-sentiment-analyzer
Please bear in mind that you'll have to train and fine-tune your bots/classifiers. You've got more info and boilerplate code in these resources.
PS: Alternatively you can pass your array/dict of tweets to services like a text-processing.com's API and they'll do the Sentiment Analysis for you...
http://text-processing.com/demo/sentiment/
https://www.mashape.com/japerk/text-processing/pricing#!documentation
Showing the results in a simple website
For this task you can use flask-tweepy. Just read their demo and you'll see how easy is to incorporate above's scripts inside flask and render the results in a view.
Hope it helps!