Skip to content

Instantly share code, notes, and snippets.

@eiryu
Last active February 6, 2020 04:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eiryu/10021378 to your computer and use it in GitHub Desktop.
Save eiryu/10021378 to your computer and use it in GitHub Desktop.
Twitter CLI
// 'twitter4j.properties' must specify on classpath
@Grab('org.twitter4j:twitter4j-core:4.0.1')
import twitter4j.Twitter
import twitter4j.TwitterFactory
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.IOException
def tw= TwitterFactory.getSingleton()
def input
def br= new BufferedReader(new InputStreamReader(System.in))
while(true) {
try {
print '> '
input= br.readLine()
def tweets
switch(input) {
case 't':
tweets= tw.getHomeTimeline()
break
case 'u':
tweets= tw.getUserTimeline()
break
case 'r':
tweets= tw.getMentionsTimeline()
break
case 'f':
tweets= tw.getFavorites()
break
// tweet
default:
if(input) {
tw.updateStatus(input)
}
continue
}
// ascending by statusId
Collections.reverse(tweets)
// display
tweets.each{ println "${it.user.screenName}\t${it.text.replaceAll('\r\n|\n', ' ')}" }
} catch(Exception e) {
println "ERROR: ${e}"
}
}
@maopd265
Copy link

What does Collections.reverse (tweets) do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment