public
Created

  • Download Gist
TwitterStream.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
package bcomposes.twitter
 
import twitter4j._
 
object StatusStreamer {
def main(args: Array[String]) {
val twitterStream = new TwitterStreamFactory(Util.config).getInstance
twitterStream.addListener(Util.simpleStatusListener)
twitterStream.sample
Thread.sleep(2000)
twitterStream.cleanUp
twitterStream.shutdown
}
}
 
object FollowIdsStreamer {
def main(args: Array[String]) {
val twitterStream = new TwitterStreamFactory(Util.config).getInstance
twitterStream.addListener(Util.simpleStatusListener)
twitterStream.filter(new FilterQuery(Array(1344951,5988062,807095,3108351)))
Thread.sleep(10000)
twitterStream.cleanUp
twitterStream.shutdown
}
}
 
object SearchStreamer {
def main(args: Array[String]) {
val twitterStream = new TwitterStreamFactory(Util.config).getInstance
twitterStream.addListener(Util.simpleStatusListener)
twitterStream.filter(new FilterQuery().track(args))
Thread.sleep(10000)
twitterStream.cleanUp
twitterStream.shutdown
}
}
 
object AustinStreamer {
def main(args: Array[String]) {
val twitterStream = new TwitterStreamFactory(Util.config).getInstance
twitterStream.addListener(Util.simpleStatusListener)
val austinBox = Array(Array(-97.8,30.25),Array(-97.65,30.35))
twitterStream.filter(new FilterQuery().locations(austinBox))
Thread.sleep(10000)
twitterStream.cleanUp
twitterStream.shutdown
}
}
 
object LocationStreamer {
def main(args: Array[String]) {
val boundingBoxes = args.map(_.toDouble).grouped(2).toArray
val twitterStream = new TwitterStreamFactory(Util.config).getInstance
twitterStream.addListener(Util.simpleStatusListener)
twitterStream.filter(new FilterQuery().locations(boundingBoxes))
Thread.sleep(10000)
twitterStream.cleanUp
twitterStream.shutdown
}
}
 
object Util {
 
val config = new twitter4j.conf.ConfigurationBuilder()
.setOAuthConsumerKey("[your consumer key here]")
.setOAuthConsumerSecret("[your consumer secret here]")
.setOAuthAccessToken("[your access token here]")
.setOAuthAccessTokenSecret("[your access token secret here]")
.build
 
def simpleStatusListener = new StatusListener() {
def onStatus(status: Status) { println(status.getText) }
def onDeletionNotice(statusDeletionNotice: StatusDeletionNotice) {}
def onTrackLimitationNotice(numberOfLimitedStatuses: Int) {}
def onException(ex: Exception) { ex.printStackTrace }
def onScrubGeo(arg0: Long, arg1: Long) {}
def onStallWarning(warning: StallWarning) {}
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.