Created
September 24, 2010 13:10
-
-
Save tototoshi/595333 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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