Skip to content

Instantly share code, notes, and snippets.

@sh4869
Created June 17, 2014 13:22
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 sh4869/823914c18a422e81bdbc to your computer and use it in GitHub Desktop.
Save sh4869/823914c18a422e81bdbc to your computer and use it in GitHub Desktop.
雨やめbot made in Java
package ame_yame_java;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import org.atilika.kuromoji.Token;
import org.atilika.kuromoji.Tokenizer;
public class ame_yame {
public static void main( String[] args ) throws TwitterException
{
Twitter twitter = new TwitterFactory().getInstance();
Tokenizer tokenizer = Tokenizer.builder().build();
ArrayList<String> list = new ArrayList<String>();
String word;
Random rnd =new Random();
Twitter timeline = TwitterFactory.getSingleton();
List<Status> statuses = timeline.getHomeTimeline();
for (Status status : statuses) {
for (Token token : tokenizer.tokenize(status.getText())) {
// System.out.println(token.getPartOfSpeech());
if(token.getPartOfSpeech().indexOf("名詞") != -1){
word = token.getSurfaceForm();
list.add(word);
}
}
}
int num = list.size();
int index = rnd.nextInt(num);
String stop = list.get(index);
twitter.updateStatus(stop + "やめー!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment