t = Table(rows=[ [uid(), "broccoli", "vegetable"], [uid(), "turnip", "vegetable"], [uid(), "asparagus", "vegetable"], [uid(), "banana", "fruit" ], ]) print t.rows[0] # A list of rows. print t.columns[1] # A list of columns, where each column is a list of values. print # Columns can be manipulated directly like any other Python list. # This can be slow for large tables. If you need a fast way to do matrix math, # use numpy (http://numpy.scipy.org/) instead. # The purpose of Table is data storage. t.columns.append([ "green", "purple", "white", "yellow" ]) # Save as a comma-separated (unicode) text file. t.save("food.txt") # Load a table from file. t = Table.load("food.txt") pprint(t, truncate=50, padding=" ", fill=".")
engine = Twitter() # With cached=False, a live request is sent to Twitter, # so we get the latest results for the query instead of those in the local cache. for tweet in engine.search("is cooler than", count=25, cached=False): print tweet.description print tweet.author print tweet.date print hashtags(tweet.description) # Keywords in tweets start with a #. print # Create a unique ID based on the tweet content and author. id = hash(tweet.author + tweet.description) # Only add the tweet to the table if it doesn't already contain this ID. if len(table) == 0 or id not in index: table.append([id, tweet.description]) index[id] = True table.save("cool.txt") print "Total results:", len(table) print # Print all the rows in the table. # Since it is stored as a file it can grow comfortably each time the script runs. # We can also open the table later on, in other scripts, for further analysis. #pprint(table) # Note: you can also search tweets by author: # Twitter().search("from:tom_de_smedt")
engine = Twitter() # With cached=False, a live request is sent to Twitter, # so we get the latest results for the query instead of those in the local cache. for tweet in engine.search("is cooler than", count=25, cached=False): print tweet.description print tweet.author print tweet.date print hashtags(tweet.description) # Keywords in tweets start with a #. print # Create a unique ID based on the tweet content and author. id = hash(tweet.author + tweet.description) # Only add the tweet to the table if it doesn't already contain this ID. if len(table) == 0 or id not in index: table.append([id, tweet.description]) index[id] = True table.save("cool.txt") print "Total results:", len(table) print # Print all the rows in the table. # Since it is stored as a file it can grow comfortably each time the script runs. # We can also open the table later on, in other scripts, for further analysis. # pprint(table) # Note: you can also search tweets by author: # Twitter().search("from:tom_de_smedt")
# It can be saved as a CSV text file that is both human/machine readable. # See also: examples/01-web/03-twitter.py # Supported values that are imported and exported correctly: # str, unicode, int, float, bool, None # For other data types, custom encoder and decoder functions can be used. t = Table(rows=[ [uid(), "broccoli", "vegetable"], [uid(), "turnip", "vegetable"], [uid(), "asparagus", "vegetable"], [uid(), "banana", "fruit"], ]) print t.rows[0] # A list of rows. print t.columns[1] # A list of columns, where each column is a list of values. print # Columns can be manipulated directly like any other Python list. # This can be slow for large tables. If you need a fast way to do matrix math, # use numpy (http://numpy.scipy.org/) instead. # The purpose of Table is data storage. t.columns.append(["green", "purple", "white", "yellow"]) # Save as a comma-separated (unicode) text file. t.save("food.txt") # Load a table from file. t = Table.load("food.txt") pprint(t, truncate=50, padding=" ", fill=".")