Skip to content

Instantly share code, notes, and snippets.

@ericacm
Last active August 29, 2015 14:04
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 ericacm/85b449b66ebd9dd4c999 to your computer and use it in GitHub Desktop.
Save ericacm/85b449b66ebd9dd4c999 to your computer and use it in GitHub Desktop.
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