Skip to content

Instantly share code, notes, and snippets.

@zaltoprofen
Created April 21, 2015 11:03
Show Gist options
  • Save zaltoprofen/c063e24b286d36894b15 to your computer and use it in GitHub Desktop.
Save zaltoprofen/c063e24b286d36894b15 to your computer and use it in GitHub Desktop.
import twitter4j._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
object Main{
def open(url: String): Unit = {
import scala.sys.process.Process
Future { Process("open", Seq(url)).! }
}
def main(args: Array[String]): Unit = {
val t = new TwitterStreamFactory().getInstance
t.addListener(new UserStreamAdapter {
override def onStatus(status: Status): Unit = {
val urls = status.getMediaEntities().collect { case e:MediaEntity if e.getType == "photo" => e.getMediaURL }
val eurls = status.getExtendedMediaEntities().collect { case e:ExtendedMediaEntity if e.getType == "photo" => e.getMediaURL }
(urls ++ eurls).distinct.foreach(open)
}
})
val q = new FilterQuery().track(Array[String]("寿司", "ラーメン"))
t.filter(q)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment