Created
June 17, 2014 13:22
-
-
Save sh4869/823914c18a422e81bdbc to your computer and use it in GitHub Desktop.
雨やめbot made in Java
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
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