Skip to content

Instantly share code, notes, and snippets.

@mattyb149
Created September 22, 2014 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattyb149/08a22c944d9e53db0237 to your computer and use it in GitHub Desktop.
Save mattyb149/08a22c944d9e53db0237 to your computer and use it in GitHub Desktop.
"Get Pentaho Tweets" scripted datasource in Groovy for Pentaho Report Designer
@Grab(group="org.twitter4j", module="twitter4j-core", version="4.0.2")
import twitter4j.*
import twitter4j.api.*
import twitter4j.conf.*
import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;
colNames = ['Screen Name', 'Tweet Date', 'Text'] as String[]
colTypes = [String, Date, String] as Class[]
model = new TypedTableModel(colNames, colTypes);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(System.getenv('TWITTER_CONSUMER_TOKEN'))
.setOAuthConsumerSecret(System.getenv('TWITTER_CONSUMER_TOKEN_SECRET'))
.setOAuthAccessToken(System.getenv('TWITTER_ACCESS_TOKEN'))
.setOAuthAccessTokenSecret(System.getenv('TWITTER_ACCESS_TOKEN_SECRET'));
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
def query = new Query('#pentaho')
def result = twitter.search(query)
result?.tweets.each { tweet ->
model.addRow( [tweet.user.screenName, tweet.createdAt, tweet.text] as Object[] )
}
return model;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment