This script will use the Twitter API to search for tweets.
Since we will be using JSON for this, don't forget to import that module. The screen name in Twitter, is the screen name of the user for whom to return results for. Open the twitter search URL, the result will be shown in json format. We can get the number of tweets using the length function. At the end of the script, we parse the tweet from the result and print it to screen.
#Importing the modules import urllib2 import json screen_name = "wordpress" url = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=" + screen_name data = json.load(urllib2.urlopen(url)) print len(data), "tweets" for tweet in data: print tweet['text']
To make it more interactive, you can ask the user for which tweet to search for: screen = raw_input("Which tweet do you want to search? ")
Share this article
Recommended Python Training – DataCamp
For Python training, our top recommendation is DataCamp.
Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.
Datacamp has beginner to advanced Python training that programmers of all levels benefit from.
Read more about: