Skip to content

Instantly share code, notes, and snippets.

@eiryu
Last active Feb 6, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@maopd265 maopd265 commented Oct 15, 2019

What does Collections.reverse (tweets) do?

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