Last active
August 29, 2015 14:04
-
-
Save ericacm/85b449b66ebd9dd4c999 to your computer and use it in GitHub Desktop.
My Tweets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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