Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Last active November 1, 2017 21:07
Show Gist options
  • Save msonnabaum/9e854b664aa376b2aa8828113f01fd29 to your computer and use it in GitHub Desktop.
Save msonnabaum/9e854b664aa376b2aa8828113f01fd29 to your computer and use it in GitHub Desktop.
// Download the twitter4j jar:
// wget http://twitter4j.org/maven2/org/twitter4j/twitter4j-core/4.0.4/twitter4j-core-4.0.4.jar
// Fill out the key/token/secrets
// Run the script
// kotlinc -script -classpath ./twitter4j-core-4.0.4.jar who_posts_the_most.kts|sort -n
import twitter4j.Status
import twitter4j.Twitter
import twitter4j.TwitterException
import twitter4j.TwitterFactory
import twitter4j.Paging
import twitter4j.conf.ConfigurationBuilder
val TWITTER_CONSUMER_KEY = ""
val TWITTER_CONSUMER_SECRET = ""
val TWITTER_ACCESS_TOKEN = ""
val TWITTER_ACCESS_TOKEN_SECRET = ""
val cb = ConfigurationBuilder()
.setDebugEnabled(true)
.setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET)
.setOAuthAccessToken(TWITTER_ACCESS_TOKEN)
.setOAuthAccessTokenSecret(TWITTER_ACCESS_TOKEN_SECRET)
val twitter = TwitterFactory(cb.build()).getInstance()
val names = mutableListOf<String>()
for (i in 1..10) {
val statuses = twitter.getHomeTimeline(Paging(i, 200))
for (status in statuses) {
names.add(status.getUser().getScreenName())
}
}
names.groupBy({it}).mapValues {
println("${it.value.size} ${it.key}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment