) return g if __name__ == "__main__": # Your query Q = " ".join(sys.argv[1]) # How many batches of data to grab for the search results MAX_BATCHES = 2 # How many search results per page COUNT = 100 # Get some search results for a query t = oauth_login() search_results = search(t, q=Q, max_batches=MAX_BATCHES, count=COUNT) g = create_rt_graph(search_results) # Print out some stats print >>sys.stderr, "Number nodes:", g.number_of_nodes() print >>sys.stderr, "Num edges:", g.number_of_edges() print >>sys.stderr, "Num connected components:", len(nx.connected_components(g.to_undirected())) print >>sys.stderr, "Node degrees:", sorted(nx.degree(g))
if TIMELINE_NAME == 'user': USER = sys.argv[3] KW['screen_name'] = USER if TIMELINE_NAME == 'home' and MAX_PAGES > 4: MAX_PAGES = 4 if TIMELINE_NAME == 'user' and MAX_PAGES > 16: MAX_PAGES = 16 if TIMELINE_NAME == 'public': MAX_PAGES = 1 # Authentication is needed for harvesting home timelines. # Don't forget to add keyword parameters to the oauth_login call below # if you don't have a token file on disk. t = oauth_login() # Establish a connection to a CouchDB database server = couchdb.Server('http://localhost:5984') DB = 'tweets-%s-timeline' % (TIMELINE_NAME, ) if USER: DB = '%s-%s' % (DB, USER) try: db = server.create(DB) except couchdb.http.PreconditionFailed, e: # Already exists, so append to it, keeping in mind that duplicates could occur
# -*- coding: utf-8 -*- import sys import twitter import webbrowser from recipe__oauth_login import oauth_login # Query terms Q = ','.join(sys.argv[1:]) print >> sys.stderr, 'Filtering the public timeline for track="%s"' % (Q,) t = oauth_login() # Returns an instance of twitter.Twitter twitter_stream = twitter.TwitterStream(auth=t.auth) # Reference the self.auth parameter # See https://dev.twitter.com/docs/streaming-apis stream = twitter_stream.statuses.filter(track=Q) # For illustrative purposes, when all else fails, search for Justin Bieber # and something is sure to turn up (at least, on Twitter) for tweet in stream: print tweet['text']