Skip to content

Instantly share code, notes, and snippets.

@ywindish
Created September 22, 2014 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ywindish/ac4929aa96125b88bfdf to your computer and use it in GitHub Desktop.
Save ywindish/ac4929aa96125b88bfdf to your computer and use it in GitHub Desktop.
DajarebotのScala版
/*
Scala勉強中
同じディレクトリに以下を置きます
twitter4j-core-x.x.x.jar
twitter4j.properties
dajare.txt
以下で実行します
$ scala -cp .;twitter4j-core-x.x.x.jar dajarebot.scala
*/
import scala.io.Source
import scala.util.Random
import twitter4j._
import twitter4j.conf._
object Main {
def main(args: Array[String]): Unit = {
run()
}
def run(): Unit = {
val f = Source.fromFile("dajare.txt", "utf-8")
val words = try f.getLines.toList finally f.close
val tweet = words(Random.nextInt(words.size)) + " #dajare"
val twitter = new TwitterFactory().getInstance()
twitter.updateStatus(tweet)
println(tweet)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment