Skip to content

Instantly share code, notes, and snippets.

@ericacm ericacm/MyTweets.scala
Last active Aug 29, 2015

Embed
What would you like to do?
My Tweets
import java.text.SimpleDateFormat
import twitter4j.{Paging, TwitterFactory}
import collection.JavaConverters._
object MyTweets extends App {
val twitter = TwitterFactory.getSingleton
val sdf = new SimpleDateFormat("yyyy-MM-dd")
var maxId = Long.MaxValue
(1 to 6) foreach { i =>
val paging = new Paging
if (i > 1) paging.setMaxId(maxId - 1)
val statuses = twitter.getUserTimeline(paging)
statuses.asScala filterNot (_.getText.head == '@') foreach { status =>
val text = if (status.isRetweet) {
val rtStatus = status.getRetweetedStatus
rtStatus.getText + " (@" + rtStatus.getUser.getScreenName + ")"
} else status.getText
val cleanText = text.replace("\n", " ")
val created = sdf.format(status.getCreatedAt)
println(created + " " + cleanText)
if (status.getId < maxId) maxId = status.getId
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.