Skip to content

Instantly share code, notes, and snippets.

@hakobe
Last active December 25, 2015 06:39
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 hakobe/6934200 to your computer and use it in GitHub Desktop.
Save hakobe/6934200 to your computer and use it in GitHub Desktop.
10分以内に放送開始になるアニメの番組情報をツイートします config.txtにkeyを書いておく
import com.ning.http.client.oauth.{RequestToken, ConsumerKey}
import dispatch._, dispatch.Defaults._, dispatch.oauth._
import org.joda.time.{DateTimeZone, DateTime}
import org.joda.time.format.ISODateTimeFormat
import scala.io.Source
object AnimeKansai {
def main( args : Array[String] ) : Unit =
comingTitles() foreach( titles => titles foreach( title => {
tweet(title)
}) )
def comingTitles(): Future[Seq[String]] =
Http( syoboiRequest OK as.xml.Elem ).map( r => {
r \\ "item" filter( elem => {
ISODateTimeFormat.dateTimeNoMillis().parseDateTime(
(elem \\ "date").text
).compareTo(tenMinutesAfter) < 0
}) map ( elem => {
(elem \\ "title").text
})
} )
val syoboiRequest : Req =
url("http://cal.syoboi.jp/rss.php") <<? Map(
"filter" -> "0",
"usr" -> "hakobe",
"titlefmt" -> "$(Mark) $(StTime) [$(ChName)] $(Title) $(SubTitleB)"
)
val tenMinutesAfter: DateTime =
DateTime.now( DateTimeZone.forID("Asia/Tokyo")).plusMinutes(10)
val config: Array[String] = Source.fromFile("config.txt").getLines().toArray
val consumerKey : ConsumerKey = new ConsumerKey(config(0),config(1))
val accessToken : RequestToken = new RequestToken(config(2),config(3))
def tweet(message:String): Future[String] =
Http( tweetRequest(message) OK as.String )
def tweetRequest(message : String) : Req =
url(
"https://api.twitter.com/1.1/statuses/update.json"
).POST << Map("status" -> message) <@ (consumerKey, accessToken)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment