Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created September 24, 2010 13:10
Show Gist options
  • Save tototoshi/595333 to your computer and use it in GitHub Desktop.
Save tototoshi/595333 to your computer and use it in GitHub Desktop.
import scala.collection.JavaConversions._
import java.util.List
import twitter4j.{TwitterFactory, Twitter, Tweet, QueryResult, Query}
object SimpleTwitterSearchApp {
def search(word: String = "#rpscala"): List[Tweet] = {
val query = new Query
query.setQuery(word)
val twitter = new TwitterFactory().getInstance()
val results = twitter.search(query)
val tweets = results.getTweets
tweets
}
def printTweets(tweets: List[Tweet]) = {
for (tweet <- tweets) {
print("@" + tweet.getFromUser + ": ")
println(tweet.getText)
}
}
def main(args: Array[String]){
val tweets = args.length match {
case 0 => search()
case _ => search(args(0))
}
printTweets(tweets)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment