Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

投稿する場合用の条件を追加

  • Loading branch information...
commit 956dc331ce3734809de7ca49c639d3dae3a446e5 1 parent 68a2daa
tkdysk authored
2  2012/TwitterBot/src/main/java/bot/curator/app/collect/Collector.groovy
View
@@ -5,7 +5,7 @@ import bot.curator.common.bean.Item
import org.cyberneko.html.parsers.DOMParser
interface Collector {
- List<Item> getItems()
+ List<Item> getItems(String queryString)
}
12 2012/TwitterBot/src/main/java/bot/curator/app/collect/impl/TwitterCollector.groovy
View
@@ -15,8 +15,7 @@ import bot.curator.common.bean.Service;
class TwitterCollector extends AbstarctCollector {
- List<Item> getItems(){
- String queryString = "hatena"
+ List<Item> getItems(String queryString){
Twitter twitter = new TwitterFactory().getInstance()
List<Tweet> tweets
@@ -24,7 +23,7 @@ class TwitterCollector extends AbstarctCollector {
Query query = new Query()
query.setQuery(queryString)
query.setLang("ja")
- query.setResultType(Query.MIXED)
+ query.setResultType(Query.POPULAR)
query.setPage(1)
query.rpp(1)
@@ -39,14 +38,17 @@ class TwitterCollector extends AbstarctCollector {
private List<Item> tweets2Items(List<Tweet> tweets){
List<Item> items = []
- tweets.each { items << tweet2Item(it) }
+ tweets.each {
+ Item item = tweet2Item(it)
+ if(item) items << item
+ }
return items
}
private Item tweet2Item(Tweet tweet){
if(!tweet) return null
-
+
def item = new Item()
item.setService(Service.Twitter)
item.setFqdn("twitter.com")
16 2012/TwitterBot/src/main/java/bot/curator/app/main/Main.groovy
View
@@ -11,13 +11,15 @@ import bot.curator.app.output.Tweet
class Main {
static main(args) {
- Collector collector = new TwitterCollector()
- List<Item> items = collector.getItems()
- items.each {
- //println "---------" //+it.toString()
- Result result = new KuromojiAnalyzer(it).analyze()
- new Tweet().tweet(result)
+ def keywords = ["groovy", "java", "android", "music"]
+ keywords.each {
+ Collector collector = new TwitterCollector()
+ List<Item> items = collector.getItems(it)
+ items.each {
+ //println "---------" //+it.toString()
+ Result result = new KuromojiAnalyzer(it).analyze()
+ new Tweet().tweet(result)
+ }
}
}
-
}
21 2012/TwitterBot/src/main/java/bot/curator/app/output/Tweet.groovy
View
@@ -9,26 +9,31 @@ class Tweet {
Item item = result.getItem()
String tweet = "["+String.valueOf(item.getService())+"] "
tweet += new GoogleUrlShortener().shortener(item.getUrl())
-
+
Map countMap = [:]
result.getTags().each {
- countMap.put(it,
- (countMap.containsKey(it)?countMap.get(it):0) +1)
+ countMap.put(it,
+ (countMap.containsKey(it)?countMap.get(it):0) +1)
}
-
+
countMap.remove("twitter")
countMap.remove("Twitter")
-
+
countMap.sort{it.value}.reverseEach {key, value ->
String tag = value+":"+key
if(tweet.length()<100){
tweet += " "+tag
}
}
-
- // 書き込みさせない。
+
+
println tweet
- tweet = ""
+
+ println "tweetする場合は、「t」を入力してください。"
+ String line = System.in.newReader().readLine()
+ if("t"!=line) {
+ tweet = "" // 書き込みさせない。
+ }
return new UpdateStatus().update(tweet)
}
}
4 2012/TwitterBot/src/test/java/test/SytemInTest.groovy
View
@@ -0,0 +1,4 @@
+package test
+
+String line = System.in.newReader().readLine()
+if("t"==line) println "tweet"
Please sign in to comment.
Something went wrong with that request. Please try again.