OSDN Git Service

複数路線
[traindelaybot/source.git] / workspace / .metadata / .plugins / org.eclipse.core.resources / .history / 97 / d0086a6c116b001115b7b82f2f4ce01a
@@ -16,14 +16,14 @@ import twitter4j.TwitterFactory;
 import twitter4j.auth.AccessToken;\r
 import twitter4j.conf.ConfigurationBuilder;\r
 \r
-import com.yuji.tdb.TrainDelayBotServlet;\r
 import com.yuji.tdb.common.CommonUtil;\r
+import com.yuji.tdb.utility.StringUtility;\r
 \r
 public class TwitterUtil {\r
-       private static TwitterUtil instance = null;\r
-       private static Object obj = new Object();\r
        private static final Logger log = Logger\r
                        .getLogger(TwitterUtil.class.getName());\r
+       private static TwitterUtil instance = null;\r
+       private static Object obj = new Object();\r
 \r
        public static TwitterUtil getInstance() {\r
                if (instance == null) {\r
@@ -56,7 +56,7 @@ public class TwitterUtil {
                        long cur = date.getTime();\r
                        \r
                        Query query = new Query();\r
-                       query.setRpp(100); // TODO\r
+                       //query.setRpp(1000); // TODO\r
                        query.setQuery(text);\r
                        QueryResult result = twitter.search(query);\r
                        List<Tweet> tweets = result.getTweets();\r
@@ -73,9 +73,12 @@ public class TwitterUtil {
                                \r
                                Date at = tweet.getCreatedAt();\r
                                long t = at.getTime();\r
+                               \r
                                String message = tweet.getText();\r
                                \r
                                if (t < cur - 30 * 60 * 1000){\r
+                                       System.out.println("\81~" + tweet.getFromUser() + " - "\r
+                                                       + tweet.getText() + at);\r
                                        continue;\r
                                }\r
                                hit = filter(message);\r
@@ -98,15 +101,14 @@ public class TwitterUtil {
                                message = "\92x\89\84\82È\82µ " + date.toString();                        \r
                        }\r
                        else {\r
-                               int N = 50;\r
+                               int N = 100;\r
                                \r
                                String sample = tweets.get(mindex).getText();\r
-                               if (sample.length() > N){\r
-                                       sample = sample.substring(0, N);\r
-                               }\r
                                sample = CommonUtil.replaceString(sample, "@", "(a)");\r
+                               sample = StringUtility.parseSubstring(sample, N);\r
                                message = sample + " " + date.toString() + " count=" + count;                                                   \r
                        }\r
+                       System.out.println(message);\r
                        Status status = twitter.updateStatus(message);\r
                } catch (TwitterException e) {\r
                        // TODO Auto-generated catch block\r
@@ -123,7 +125,9 @@ public class TwitterUtil {
                        keywords.add("\92x\89\84");\r
                        keywords.add("\92x\82ê");\r
                        keywords.add("\90U\82è\91Ö\82¦");\r
-                       keywords.add("\8bÙ\8b}\92â\8e~");\r
+                       keywords.add("\90U\91Ö");\r
+                       keywords.add("\92â\8e~");\r
+                       keywords.add("\8e\96\8cÌ");\r
                }\r
 \r
                int count = 0;\r