From: Yuji Konishi Date: Wed, 14 Mar 2012 16:13:05 +0000 (+0900) Subject: aaa X-Git-Url: http://git.osdn.net/view?p=traindelaybot%2Fsource.git;a=commitdiff_plain;h=9be7d50b45c555b120e4ec8fa8b5928afa3cc942 aaa --- diff --git a/memo.txt b/memo.txt index 1eccaa6..ccdb56a 100644 --- a/memo.txt +++ b/memo.txt @@ -37,6 +37,9 @@ http://1.latest.traindelaybot.appspot.com/traindelaybot?key=j9Nq0PPfoQxKbU2GUI2h http://1.latest.traindelaybot.appspot.com/traindelaybot +[‹ž•l‹}sü] 00:27 + ’x‰„‚È‚µ 2012/03/15 :08 + ›BigTable http://www.atmarkit.co.jp/fjava/rensai4/gaej02/gaej02_3.html diff --git a/workspace/.metadata/.log b/workspace/.metadata/.log index a74b337..63e6494 100644 --- a/workspace/.metadata/.log +++ b/workspace/.metadata/.log @@ -3072,3 +3072,31 @@ Command-line arguments: -os macosx -ws cocoa -arch x86_64 -product org.eclipse. !ENTRY com.google.appengine.eclipse.core 1 0 2012-03-11 20:03:35.906 !MESSAGE TrainDelayBot successfully deployed to Google App Engine +!SESSION 2012-03-15 00:19:48.352 ----------------------------------------------- +eclipse.buildId=I20110613-1736 +java.version=1.6.0_29 +java.vendor=Apple Inc. +BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=ja_JP +Framework arguments: -product org.eclipse.epp.package.java.product -keyring /Users/yuji/.eclipse_keyring -showlocation +Command-line arguments: -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/yuji/.eclipse_keyring -showlocation + +!ENTRY org.eclipse.core.net 1 0 2012-03-15 00:19:54.582 +!MESSAGE System property http.nonProxyHosts has been set to local|*.local|169.254/16|*.169.254/16 by an external source. This value will be overwritten using the values from the preferences + +!ENTRY com.google.gwt.eclipse.core 2 0 2012-03-15 00:19:59.747 +!MESSAGE Could not check whether the launch configuration "Test" needs the -XstartOnFirstThread argument, assuming it does + +!ENTRY com.google.gwt.eclipse.core 2 0 2012-03-15 00:19:59.782 +!MESSAGE Could not check whether the launch configuration "Test" needs the -XstartOnFirstThread argument, assuming it does + +!ENTRY com.google.gwt.eclipse.core 2 0 2012-03-15 00:19:59.802 +!MESSAGE Could not check whether the launch configuration "TrainDelayBot" needs the -XstartOnFirstThread argument, assuming it does + +!ENTRY com.google.gwt.eclipse.core 2 0 2012-03-15 00:19:59.814 +!MESSAGE Could not check whether the launch configuration "TrainDelayBot" needs the -XstartOnFirstThread argument, assuming it does + +!ENTRY com.google.appengine.eclipse.core 1 0 2012-03-15 00:36:56.145 +!MESSAGE TrainDelayBot successfully deployed to Google App Engine + +!ENTRY com.google.appengine.eclipse.core 1 0 2012-03-15 00:42:14.961 +!MESSAGE TrainDelayBot successfully deployed to Google App Engine diff --git a/workspace/.metadata/.mylyn/.tasks.xml.zip b/workspace/.metadata/.mylyn/.tasks.xml.zip index 6173663..b590d06 100644 Binary files a/workspace/.metadata/.mylyn/.tasks.xml.zip and b/workspace/.metadata/.mylyn/.tasks.xml.zip differ diff --git a/workspace/.metadata/.mylyn/tasks.xml.zip b/workspace/.metadata/.mylyn/tasks.xml.zip index bc70ade..26d0c60 100644 Binary files a/workspace/.metadata/.mylyn/tasks.xml.zip and b/workspace/.metadata/.mylyn/tasks.xml.zip differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp20808907331581361121331738399321038000 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp20808907331581361121331738399321038000 new file mode 100644 index 0000000..48dcedf Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp20808907331581361121331738399321038000 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_0 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_0 new file mode 100644 index 0000000..13aecfe Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_0 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_1 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_1 new file mode 100644 index 0000000..f2f07a9 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_1 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_10 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_10 new file mode 100644 index 0000000..37c41f7 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_10 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_11 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_11 new file mode 100644 index 0000000..6b3e065 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_11 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_12 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_12 new file mode 100644 index 0000000..3deba90 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_12 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_13 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_13 new file mode 100644 index 0000000..6b3e065 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_13 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_14 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_14 new file mode 100644 index 0000000..6bdf8d1 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_14 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_15 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_15 new file mode 100644 index 0000000..6b3e065 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_15 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_2 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_2 new file mode 100644 index 0000000..6b3e065 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_2 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_3 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_3 new file mode 100644 index 0000000..9abf6f2 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_3 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_4 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_4 new file mode 100644 index 0000000..8269661 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_4 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_5 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_5 new file mode 100644 index 0000000..6b3e065 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_5 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_6 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_6 new file mode 100644 index 0000000..10a6dc5 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_6 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_7 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_7 new file mode 100644 index 0000000..b82ebfc Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_7 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_8 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_8 new file mode 100644 index 0000000..b834758 Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_8 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_9 b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_9 new file mode 100644 index 0000000..0c9aa8a Binary files /dev/null and b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/cache_9 differ diff --git a/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/icon_bundle_map b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/icon_bundle_map new file mode 100644 index 0000000..042c74a --- /dev/null +++ b/workspace/.metadata/.plugins/com.google.gdt.eclipse.managedapis/icon_caches/temp50807651823440362971331738401163307000/icon_bundle_map @@ -0,0 +1 @@ +{"http://www.google.com/images/icons/product/moderator-32.png":"cache_12","http://api-directory.googleapis.com/icons/gdata-webmaster-32.png":"cache_10","http://api-directory.googleapis.com/icons/gdata-books-32.png":"cache_3","http://www.google.com/images/icons/product/analytics-32.png":"cache_1","http://www.google.com/images/icons/product/customsearch-32.png":"cache_0","http://api-directory.googleapis.com/icons/gdata-spreadsheet-32.png":"cache_9","http://api-directory.googleapis.com/icons/google_calendar_data_lb32.png":"cache_4","http://api-directory.googleapis.com/icons/search-32.png":"cache_15","http://www.google.com/images/icons/product/translate-32.png":"cache_14","http://api-directory.googleapis.com/icons/gdata-contacts-32.png":"cache_6","http://www.google.com/images/icons/product/projecthosting-32.png":"cache_8","http://api-directory.googleapis.com/icons/gdata-finance-32.png":"cache_7"} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/29/e064390fea6d001110a188bae663c898 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/29/e064390fea6d001110a188bae663c898 new file mode 100644 index 0000000..e285c2a --- /dev/null +++ b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/29/e064390fea6d001110a188bae663c898 @@ -0,0 +1,169 @@ +package com.yuji.tdb.twitter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.logging.Logger; + +import twitter4j.Query; +import twitter4j.QueryResult; +import twitter4j.Status; +import twitter4j.Tweet; +import twitter4j.Twitter; +import twitter4j.TwitterException; +import twitter4j.TwitterFactory; +import twitter4j.auth.AccessToken; +import twitter4j.conf.ConfigurationBuilder; + +import com.yuji.tdb.common.CommonUtil; +import com.yuji.tdb.db.Train; +import com.yuji.tdb.db.TrainDao; +import com.yuji.tdb.utility.StringUtility; + +public class TwitterUtil { + private static final Logger log = Logger + .getLogger(TwitterUtil.class.getName()); + private static TwitterUtil instance = null; + private static Object obj = new Object(); + private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + + public static TwitterUtil getInstance() { + if (instance == null) { + synchronized (obj) { + if (instance == null) { + instance = new TwitterUtil(); + } + } + } + return instance; + } + + private TwitterUtil() { + //TimeZone.setDefault(TimeZone.getTimeZone("JST")); // TODO êŠ + } + + public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { + try { + ConfigurationBuilder confBuilder = new ConfigurationBuilder(); + confBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) + .setOAuthConsumerSecret(consumerSecret); + TwitterFactory factory = new TwitterFactory(confBuilder.build()); + Twitter twitter = factory.getInstance(accessToken); + + List list = getTrainList(); + for (Train train : list){ + twite(twitter, train); + } + } catch (TwitterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + log.severe(e.toString()); + } + } + + private void twite(Twitter twitter, Train train) throws TwitterException { + Query query = new Query(); + //query.setRpp(1000); // TODO + query.setQuery(train.getSearchWord()); + QueryResult result = twitter.search(query); + List tweets = result.getTweets(); + + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + + int count = 0; + int hit = 0; + int mhit = 0; + + int index; + int mindex = 0; + int size = tweets.size(); + for (index = 0; index < size; index++) { + Tweet tweet = tweets.get(index); + + Date at = tweet.getCreatedAt(); + long t = at.getTime(); + + String message = tweet.getText(); + + if (t < cur - 30 * 60 * 1000){ + System.out.println("~" + tweet.getFromUser() + " - " + + tweet.getText() + at); + continue; + } + hit = filter(message); + if (hit <= 0) { + System.out.println("¢" + tweet.getFromUser() + " - " + + tweet.getText() + at); + // ’x‰„ˆÈŠO‚̏‘‚«ž‚Ý + continue; + } + if (hit > mhit){ + hit = mhit; + mindex = index; + } + + System.out.println("@" + tweet.getFromUser() + " - " + + tweet.getText() + at); + count++; + } + + String message = "[" + train.getName() + "] "; + if (count < train.getCount()){ + message += "’x‰„‚È‚µ " + df.format(date); + } + else { + int N = 100; + + String sample = tweets.get(mindex).getText(); + sample = CommonUtil.replaceString(sample, "@", "(a)"); + sample = StringUtility.parseSubstring(sample, N); + message += sample + " " + df.format(date) + " count=" + count; + } + System.out.println(message); //TODO + Status status = twitter.updateStatus(message); //TODO + } + + private List getTrainList(){ + TrainDao dao = TrainDao.getInstance(); + List list = dao.search(); + if (list.size() <= 0){ + Train train; + + train = new Train("‹ž•l“Œ–kü", "‹ž•l“Œ–k", 5); + dao.put(train); + train = new Train("“ŒŠC“¹ü", "“ŒŠC“¹", 5); + dao.put(train); + train = new Train("‹ž•l‹}sü", "‹ž‹}", 5); + dao.put(train); + list = dao.search(); + } + return list; + } + + private static List keywords = null; + + public int filter(String text) { + if (keywords == null) { + keywords = new ArrayList(); + keywords.add("’x‰„"); + keywords.add("’x‚ê"); + keywords.add("U‚è‘Ö‚¦"); + keywords.add("U‘Ö"); + keywords.add("’âŽ~"); + keywords.add("Ž–ŒÌ"); + } + + int count = 0; + for (String keyword : keywords) { + if (text.indexOf(keyword) >= 0) { + count++; + } + } + return count; + } +} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/2b/902157bbea6d001110a188bae663c898 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/2b/902157bbea6d001110a188bae663c898 new file mode 100644 index 0000000..c955df6 --- /dev/null +++ b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/2b/902157bbea6d001110a188bae663c898 @@ -0,0 +1,171 @@ +package com.yuji.tdb.twitter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.logging.Logger; + +import twitter4j.Query; +import twitter4j.QueryResult; +import twitter4j.Status; +import twitter4j.Tweet; +import twitter4j.Twitter; +import twitter4j.TwitterException; +import twitter4j.TwitterFactory; +import twitter4j.auth.AccessToken; +import twitter4j.conf.ConfigurationBuilder; + +import com.yuji.tdb.common.CommonUtil; +import com.yuji.tdb.db.Train; +import com.yuji.tdb.db.TrainDao; +import com.yuji.tdb.utility.StringUtility; + +public class TwitterUtil { + private static final Logger log = Logger + .getLogger(TwitterUtil.class.getName()); + private static TwitterUtil instance = null; + private static Object obj = new Object(); + //private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + private DateFormat df = new SimpleDateFormat("HH:mm"); + + public static TwitterUtil getInstance() { + if (instance == null) { + synchronized (obj) { + if (instance == null) { + instance = new TwitterUtil(); + } + } + } + return instance; + } + + private TwitterUtil() { + df.setTimeZone(TimeZone.getTimeZone("JST")); + } + + public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { + try { + ConfigurationBuilder confBuilder = new ConfigurationBuilder(); + confBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) + .setOAuthConsumerSecret(consumerSecret); + TwitterFactory factory = new TwitterFactory(confBuilder.build()); + Twitter twitter = factory.getInstance(accessToken); + + List list = getTrainList(); + for (Train train : list){ + twite(twitter, train); + } + } catch (TwitterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + log.severe(e.toString()); + } + } + + private void twite(Twitter twitter, Train train) throws TwitterException { + Query query = new Query(); + //query.setRpp(1000); // TODO + query.setQuery(train.getSearchWord()); + QueryResult result = twitter.search(query); + List tweets = result.getTweets(); + + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + + int count = 0; + int hit = 0; + int mhit = 0; + + int index; + int mindex = 0; + int size = tweets.size(); + for (index = 0; index < size; index++) { + Tweet tweet = tweets.get(index); + + Date at = tweet.getCreatedAt(); + long t = at.getTime(); + + String message = tweet.getText(); + + if (t < cur - 30 * 60 * 1000){ + System.out.println("~" + tweet.getFromUser() + " - " + + tweet.getText() + at); + continue; + } + hit = filter(message); + if (hit <= 0) { + System.out.println("¢" + tweet.getFromUser() + " - " + + tweet.getText() + at); + // ’x‰„ˆÈŠO‚̏‘‚«ž‚Ý + continue; + } + if (hit > mhit){ + hit = mhit; + mindex = index; + } + + System.out.println("@" + tweet.getFromUser() + " - " + + tweet.getText() + at); + count++; + } + + String message = "[" + train.getName() + "] "; + if (count < train.getCount()){ + message += " " + df.format(date) + " ’x‰„‚È‚µ"; + } + else { + int N = 100; + + String sample = tweets.get(mindex).getText(); + sample = CommonUtil.replaceString(sample, "@", "(a)"); + sample = StringUtility.parseSubstring(sample, N); + message += " " + df.format(date) + " " + sample + " count=" + count; + } + System.out.println(message); //TODO + Status status = twitter.updateStatus(message); //TODO + } + + private List getTrainList(){ + TrainDao dao = TrainDao.getInstance(); + List list = dao.search(); + if (list.size() <= 0){ + Train train; + + train = new Train("‹ž•l“Œ–kü", "‹ž•l“Œ–k", 5); + dao.put(train); + train = new Train("“ŒŠC“¹ü", "“ŒŠC“¹", 5); + dao.put(train); + train = new Train("‹ž•l‹}sü", "‹ž‹}", 5); + dao.put(train); + list = dao.search(); + } + return list; + } + + private static List keywords = null; + + public int filter(String text) { + if (keywords == null) { + keywords = new ArrayList(); + keywords.add("’x‰„"); + keywords.add("’x‚ê"); + keywords.add("U‚è‘Ö‚¦"); + keywords.add("U‘Ö"); + keywords.add("’âŽ~"); + keywords.add("Ž–ŒÌ"); + } + + int count = 0; + for (String keyword : keywords) { + if (text.indexOf(keyword) >= 0) { + count++; + } + } + return count; + } +} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/38/20c52514ea6d001110a188bae663c898 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/38/20c52514ea6d001110a188bae663c898 new file mode 100644 index 0000000..5bee032 --- /dev/null +++ b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/38/20c52514ea6d001110a188bae663c898 @@ -0,0 +1,169 @@ +package com.yuji.tdb.twitter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.logging.Logger; + +import twitter4j.Query; +import twitter4j.QueryResult; +import twitter4j.Status; +import twitter4j.Tweet; +import twitter4j.Twitter; +import twitter4j.TwitterException; +import twitter4j.TwitterFactory; +import twitter4j.auth.AccessToken; +import twitter4j.conf.ConfigurationBuilder; + +import com.yuji.tdb.common.CommonUtil; +import com.yuji.tdb.db.Train; +import com.yuji.tdb.db.TrainDao; +import com.yuji.tdb.utility.StringUtility; + +public class TwitterUtil { + private static final Logger log = Logger + .getLogger(TwitterUtil.class.getName()); + private static TwitterUtil instance = null; + private static Object obj = new Object(); + private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + + public static TwitterUtil getInstance() { + if (instance == null) { + synchronized (obj) { + if (instance == null) { + instance = new TwitterUtil(); + } + } + } + return instance; + } + + private TwitterUtil() { + df.setTimeZone(TimeZone.getTimeZone("JST")); + } + + public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { + try { + ConfigurationBuilder confBuilder = new ConfigurationBuilder(); + confBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) + .setOAuthConsumerSecret(consumerSecret); + TwitterFactory factory = new TwitterFactory(confBuilder.build()); + Twitter twitter = factory.getInstance(accessToken); + + List list = getTrainList(); + for (Train train : list){ + twite(twitter, train); + } + } catch (TwitterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + log.severe(e.toString()); + } + } + + private void twite(Twitter twitter, Train train) throws TwitterException { + Query query = new Query(); + //query.setRpp(1000); // TODO + query.setQuery(train.getSearchWord()); + QueryResult result = twitter.search(query); + List tweets = result.getTweets(); + + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + + int count = 0; + int hit = 0; + int mhit = 0; + + int index; + int mindex = 0; + int size = tweets.size(); + for (index = 0; index < size; index++) { + Tweet tweet = tweets.get(index); + + Date at = tweet.getCreatedAt(); + long t = at.getTime(); + + String message = tweet.getText(); + + if (t < cur - 30 * 60 * 1000){ + System.out.println("~" + tweet.getFromUser() + " - " + + tweet.getText() + at); + continue; + } + hit = filter(message); + if (hit <= 0) { + System.out.println("¢" + tweet.getFromUser() + " - " + + tweet.getText() + at); + // ’x‰„ˆÈŠO‚̏‘‚«ž‚Ý + continue; + } + if (hit > mhit){ + hit = mhit; + mindex = index; + } + + System.out.println("@" + tweet.getFromUser() + " - " + + tweet.getText() + at); + count++; + } + + String message = "[" + train.getName() + "] "; + if (count < train.getCount()){ + message += "’x‰„‚È‚µ " + df.format(date); + } + else { + int N = 100; + + String sample = tweets.get(mindex).getText(); + sample = CommonUtil.replaceString(sample, "@", "(a)"); + sample = StringUtility.parseSubstring(sample, N); + message += sample + " " + df.format(date) + " count=" + count; + } + System.out.println(message); //TODO + Status status = twitter.updateStatus(message); //TODO + } + + private List getTrainList(){ + TrainDao dao = TrainDao.getInstance(); + List list = dao.search(); + if (list.size() <= 0){ + Train train; + + train = new Train("‹ž•l“Œ–kü", "‹ž•l“Œ–k", 5); + dao.put(train); + train = new Train("“ŒŠC“¹ü", "“ŒŠC“¹", 5); + dao.put(train); + train = new Train("‹ž•l‹}sü", "‹ž‹}", 5); + dao.put(train); + list = dao.search(); + } + return list; + } + + private static List keywords = null; + + public int filter(String text) { + if (keywords == null) { + keywords = new ArrayList(); + keywords.add("’x‰„"); + keywords.add("’x‚ê"); + keywords.add("U‚è‘Ö‚¦"); + keywords.add("U‘Ö"); + keywords.add("’âŽ~"); + keywords.add("Ž–ŒÌ"); + } + + int count = 0; + for (String keyword : keywords) { + if (text.indexOf(keyword) >= 0) { + count++; + } + } + return count; + } +} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/56/50c41d65ea6d001110a188bae663c898 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/56/50c41d65ea6d001110a188bae663c898 new file mode 100644 index 0000000..a37830c --- /dev/null +++ b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/56/50c41d65ea6d001110a188bae663c898 @@ -0,0 +1,170 @@ +package com.yuji.tdb.twitter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.logging.Logger; + +import twitter4j.Query; +import twitter4j.QueryResult; +import twitter4j.Status; +import twitter4j.Tweet; +import twitter4j.Twitter; +import twitter4j.TwitterException; +import twitter4j.TwitterFactory; +import twitter4j.auth.AccessToken; +import twitter4j.conf.ConfigurationBuilder; + +import com.yuji.tdb.common.CommonUtil; +import com.yuji.tdb.db.Train; +import com.yuji.tdb.db.TrainDao; +import com.yuji.tdb.utility.StringUtility; + +public class TwitterUtil { + private static final Logger log = Logger + .getLogger(TwitterUtil.class.getName()); + private static TwitterUtil instance = null; + private static Object obj = new Object(); + private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + + public static TwitterUtil getInstance() { + if (instance == null) { + synchronized (obj) { + if (instance == null) { + instance = new TwitterUtil(); + } + } + } + return instance; + } + + private TwitterUtil() { + df.setTimeZone(TimeZone.getTimeZone("JST")); + } + + public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { + try { + ConfigurationBuilder confBuilder = new ConfigurationBuilder(); + confBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) + .setOAuthConsumerSecret(consumerSecret); + TwitterFactory factory = new TwitterFactory(confBuilder.build()); + Twitter twitter = factory.getInstance(accessToken); + + List list = getTrainList(); + for (Train train : list){ + twite(twitter, train); + } + } catch (TwitterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + log.severe(e.toString()); + } + } + + private void twite(Twitter twitter, Train train) throws TwitterException { + Query query = new Query(); + //query.setRpp(1000); // TODO + query.setQuery(train.getSearchWord()); + QueryResult result = twitter.search(query); + List tweets = result.getTweets(); + + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + + int count = 0; + int hit = 0; + int mhit = 0; + + int index; + int mindex = 0; + int size = tweets.size(); + for (index = 0; index < size; index++) { + Tweet tweet = tweets.get(index); + + Date at = tweet.getCreatedAt(); + long t = at.getTime(); + + String message = tweet.getText(); + + if (t < cur - 30 * 60 * 1000){ + System.out.println("~" + tweet.getFromUser() + " - " + + tweet.getText() + at); + continue; + } + hit = filter(message); + if (hit <= 0) { + System.out.println("¢" + tweet.getFromUser() + " - " + + tweet.getText() + at); + // ’x‰„ˆÈŠO‚̏‘‚«ž‚Ý + continue; + } + if (hit > mhit){ + hit = mhit; + mindex = index; + } + + System.out.println("@" + tweet.getFromUser() + " - " + + tweet.getText() + at); + count++; + } + + String message = "[" + train.getName() + "] "; + if (count < train.getCount()){ + message += "’x‰„‚È‚µ " + df.format(date); + } + else { + int N = 100; + + String sample = tweets.get(mindex).getText(); + sample = CommonUtil.replaceString(sample, "@", "(a)"); + sample = StringUtility.parseSubstring(sample, N); + message += sample + " " + df.format(date) + " count=" + count; + } + System.out.println(message); //TODO + Status status = twitter.updateStatus(message); //TODO + } + + private List getTrainList(){ + TrainDao dao = TrainDao.getInstance(); + List list = dao.search(); + if (list.size() <= 0){ + Train train; + + train = new Train("‹ž•l“Œ–kü", "‹ž•l“Œ–k", 5); + dao.put(train); + train = new Train("“ŒŠC“¹ü", "“ŒŠC“¹", 5); + dao.put(train); + train = new Train("‹ž•l‹}sü", "‹ž‹}", 5); + dao.put(train); + list = dao.search(); + } + return list; + } + + private static List keywords = null; + + public int filter(String text) { + if (keywords == null) { + keywords = new ArrayList(); + keywords.add("’x‰„"); + keywords.add("’x‚ê"); + keywords.add("U‚è‘Ö‚¦"); + keywords.add("U‘Ö"); + keywords.add("’âŽ~"); + keywords.add("Ž–ŒÌ"); + } + + int count = 0; + for (String keyword : keywords) { + if (text.indexOf(keyword) >= 0) { + count++; + } + } + return count; + } +} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/76/10fec63be96d001110a188bae663c898 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/76/10fec63be96d001110a188bae663c898 new file mode 100644 index 0000000..9ea526e --- /dev/null +++ b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/76/10fec63be96d001110a188bae663c898 @@ -0,0 +1,169 @@ +package com.yuji.tdb.twitter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.logging.Logger; + +import twitter4j.Query; +import twitter4j.QueryResult; +import twitter4j.Status; +import twitter4j.Tweet; +import twitter4j.Twitter; +import twitter4j.TwitterException; +import twitter4j.TwitterFactory; +import twitter4j.auth.AccessToken; +import twitter4j.conf.ConfigurationBuilder; + +import com.yuji.tdb.common.CommonUtil; +import com.yuji.tdb.db.Train; +import com.yuji.tdb.db.TrainDao; +import com.yuji.tdb.utility.StringUtility; + +public class TwitterUtil { + private static final Logger log = Logger + .getLogger(TwitterUtil.class.getName()); + private static TwitterUtil instance = null; + private static Object obj = new Object(); + private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + + public static TwitterUtil getInstance() { + if (instance == null) { + synchronized (obj) { + if (instance == null) { + instance = new TwitterUtil(); + } + } + } + return instance; + } + + private TwitterUtil() { + //TimeZone.setDefault(TimeZone.getTimeZone("JST")); // TODO êŠ + } + + public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { + try { + ConfigurationBuilder confBuilder = new ConfigurationBuilder(); + confBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) + .setOAuthConsumerSecret(consumerSecret); + TwitterFactory factory = new TwitterFactory(confBuilder.build()); + Twitter twitter = factory.getInstance(accessToken); + + List list = getTrainList(); + for (Train train : list){ + twite(twitter, train); + } + } catch (TwitterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + log.severe(e.toString()); + } + } + + private void twite(Twitter twitter, Train train) throws TwitterException { + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + + Query query = new Query(); + //query.setRpp(1000); // TODO + query.setQuery(train.getSearchWord()); + QueryResult result = twitter.search(query); + List tweets = result.getTweets(); + + int count = 0; + int hit = 0; + int mhit = 0; + + int index; + int mindex = 0; + int size = tweets.size(); + for (index = 0; index < size; index++) { + Tweet tweet = tweets.get(index); + + Date at = tweet.getCreatedAt(); + long t = at.getTime(); + + String message = tweet.getText(); + + if (t < cur - 30 * 60 * 1000){ + System.out.println("~" + tweet.getFromUser() + " - " + + tweet.getText() + at); + continue; + } + hit = filter(message); + if (hit <= 0) { + System.out.println("¢" + tweet.getFromUser() + " - " + + tweet.getText() + at); + // ’x‰„ˆÈŠO‚̏‘‚«ž‚Ý + continue; + } + if (hit > mhit){ + hit = mhit; + mindex = index; + } + + System.out.println("@" + tweet.getFromUser() + " - " + + tweet.getText() + at); + count++; + } + + String message = "[" + train.getName() + "] "; + if (count < train.getCount()){ + message += "’x‰„‚È‚µ " + df.format(date); + } + else { + int N = 100; + + String sample = tweets.get(mindex).getText(); + sample = CommonUtil.replaceString(sample, "@", "(a)"); + sample = StringUtility.parseSubstring(sample, N); + message += sample + " " + df.format(date) + " count=" + count; + } + System.out.println(message); //TODO + Status status = twitter.updateStatus(message); //TODO + } + + private List getTrainList(){ + TrainDao dao = TrainDao.getInstance(); + List list = dao.search(); + if (list.size() <= 0){ + Train train; + + train = new Train("‹ž•l“Œ–kü", "‹ž•l“Œ–k", 5); + dao.put(train); + train = new Train("“ŒŠC“¹ü", "“ŒŠC“¹", 5); + dao.put(train); + train = new Train("‹ž•l‹}sü", "‹ž‹}", 5); + dao.put(train); + list = dao.search(); + } + return list; + } + + private static List keywords = null; + + public int filter(String text) { + if (keywords == null) { + keywords = new ArrayList(); + keywords.add("’x‰„"); + keywords.add("’x‚ê"); + keywords.add("U‚è‘Ö‚¦"); + keywords.add("U‘Ö"); + keywords.add("’âŽ~"); + keywords.add("Ž–ŒÌ"); + } + + int count = 0; + for (String keyword : keywords) { + if (text.indexOf(keyword) >= 0) { + count++; + } + } + return count; + } +} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/9/b07f0731ec6d001110a188bae663c898 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/9/b07f0731ec6d001110a188bae663c898 new file mode 100644 index 0000000..9ab9f11 --- /dev/null +++ b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/9/b07f0731ec6d001110a188bae663c898 @@ -0,0 +1,171 @@ +package com.yuji.tdb.twitter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.logging.Logger; + +import twitter4j.Query; +import twitter4j.QueryResult; +import twitter4j.Status; +import twitter4j.Tweet; +import twitter4j.Twitter; +import twitter4j.TwitterException; +import twitter4j.TwitterFactory; +import twitter4j.auth.AccessToken; +import twitter4j.conf.ConfigurationBuilder; + +import com.yuji.tdb.common.CommonUtil; +import com.yuji.tdb.db.Train; +import com.yuji.tdb.db.TrainDao; +import com.yuji.tdb.utility.StringUtility; + +public class TwitterUtil { + private static final Logger log = Logger + .getLogger(TwitterUtil.class.getName()); + private static TwitterUtil instance = null; + private static Object obj = new Object(); + //private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + private DateFormat df = new SimpleDateFormat("HH:mm"); + + public static TwitterUtil getInstance() { + if (instance == null) { + synchronized (obj) { + if (instance == null) { + instance = new TwitterUtil(); + } + } + } + return instance; + } + + private TwitterUtil() { + df.setTimeZone(TimeZone.getTimeZone("JST")); + } + + public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { + try { + ConfigurationBuilder confBuilder = new ConfigurationBuilder(); + confBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) + .setOAuthConsumerSecret(consumerSecret); + TwitterFactory factory = new TwitterFactory(confBuilder.build()); + Twitter twitter = factory.getInstance(accessToken); + + List list = getTrainList(); + for (Train train : list){ + twite(twitter, train); + } + } catch (TwitterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + log.severe(e.toString()); + } + } + + private void twite(Twitter twitter, Train train) throws TwitterException { + Query query = new Query(); + //query.setRpp(1000); // TODO + query.setQuery(train.getSearchWord()); + QueryResult result = twitter.search(query); + List tweets = result.getTweets(); + + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + + int count = 0; + int hit = 0; + int mhit = 0; + + int index; + int mindex = 0; + int size = tweets.size(); + for (index = 0; index < size; index++) { + Tweet tweet = tweets.get(index); + + Date at = tweet.getCreatedAt(); + long t = at.getTime(); + + String message = tweet.getText(); + + if (t < cur - 30 * 60 * 1000){ + System.out.println("~" + tweet.getFromUser() + " - " + + tweet.getText() + at); + continue; + } + hit = filter(message); + if (hit <= 0) { + System.out.println("¢" + tweet.getFromUser() + " - " + + tweet.getText() + at); + // ’x‰„ˆÈŠO‚̏‘‚«ž‚Ý + continue; + } + if (hit > mhit){ + hit = mhit; + mindex = index; + } + + System.out.println("@" + tweet.getFromUser() + " - " + + tweet.getText() + at); + count++; + } + + String message = "[" + train.getName() + "] "; + if (count < train.getCount()){ + message += df.format(date) + " ’x‰„‚È‚µ"; + } + else { + int N = 100; + + String sample = tweets.get(mindex).getText(); + sample = CommonUtil.replaceString(sample, "@", "(a)"); + sample = StringUtility.parseSubstring(sample, N); + message += df.format(date) + " " + sample + " count=" + count; + } + System.out.println(message); //TODO + Status status = twitter.updateStatus(message); //TODO + } + + private List getTrainList(){ + TrainDao dao = TrainDao.getInstance(); + List list = dao.search(); + if (list.size() <= 0){ + Train train; + + train = new Train("‹ž•l“Œ–kü", "‹ž•l“Œ–k", 5); + dao.put(train); + train = new Train("“ŒŠC“¹ü", "“ŒŠC“¹", 5); + dao.put(train); + train = new Train("‹ž•l‹}sü", "‹ž‹}", 5); + dao.put(train); + list = dao.search(); + } + return list; + } + + private static List keywords = null; + + public int filter(String text) { + if (keywords == null) { + keywords = new ArrayList(); + keywords.add("’x‰„"); + keywords.add("’x‚ê"); + keywords.add("U‚è‘Ö‚¦"); + keywords.add("U‘Ö"); + keywords.add("’âŽ~"); + keywords.add("Ž–ŒÌ"); + } + + int count = 0; + for (String keyword : keywords) { + if (text.indexOf(keyword) >= 0) { + count++; + } + } + return count; + } +} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/a4/90e96797ea6d001110a188bae663c898 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/a4/90e96797ea6d001110a188bae663c898 new file mode 100644 index 0000000..f80abf3 --- /dev/null +++ b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/a4/90e96797ea6d001110a188bae663c898 @@ -0,0 +1,171 @@ +package com.yuji.tdb.twitter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.logging.Logger; + +import twitter4j.Query; +import twitter4j.QueryResult; +import twitter4j.Status; +import twitter4j.Tweet; +import twitter4j.Twitter; +import twitter4j.TwitterException; +import twitter4j.TwitterFactory; +import twitter4j.auth.AccessToken; +import twitter4j.conf.ConfigurationBuilder; + +import com.yuji.tdb.common.CommonUtil; +import com.yuji.tdb.db.Train; +import com.yuji.tdb.db.TrainDao; +import com.yuji.tdb.utility.StringUtility; + +public class TwitterUtil { + private static final Logger log = Logger + .getLogger(TwitterUtil.class.getName()); + private static TwitterUtil instance = null; + private static Object obj = new Object(); + //private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + private DateFormat df = new SimpleDateFormat("HH:mm"); + + public static TwitterUtil getInstance() { + if (instance == null) { + synchronized (obj) { + if (instance == null) { + instance = new TwitterUtil(); + } + } + } + return instance; + } + + private TwitterUtil() { + df.setTimeZone(TimeZone.getTimeZone("JST")); + } + + public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { + try { + ConfigurationBuilder confBuilder = new ConfigurationBuilder(); + confBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) + .setOAuthConsumerSecret(consumerSecret); + TwitterFactory factory = new TwitterFactory(confBuilder.build()); + Twitter twitter = factory.getInstance(accessToken); + + List list = getTrainList(); + for (Train train : list){ + twite(twitter, train); + } + } catch (TwitterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + log.severe(e.toString()); + } + } + + private void twite(Twitter twitter, Train train) throws TwitterException { + Query query = new Query(); + //query.setRpp(1000); // TODO + query.setQuery(train.getSearchWord()); + QueryResult result = twitter.search(query); + List tweets = result.getTweets(); + + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + + int count = 0; + int hit = 0; + int mhit = 0; + + int index; + int mindex = 0; + int size = tweets.size(); + for (index = 0; index < size; index++) { + Tweet tweet = tweets.get(index); + + Date at = tweet.getCreatedAt(); + long t = at.getTime(); + + String message = tweet.getText(); + + if (t < cur - 30 * 60 * 1000){ + System.out.println("~" + tweet.getFromUser() + " - " + + tweet.getText() + at); + continue; + } + hit = filter(message); + if (hit <= 0) { + System.out.println("¢" + tweet.getFromUser() + " - " + + tweet.getText() + at); + // ’x‰„ˆÈŠO‚̏‘‚«ž‚Ý + continue; + } + if (hit > mhit){ + hit = mhit; + mindex = index; + } + + System.out.println("@" + tweet.getFromUser() + " - " + + tweet.getText() + at); + count++; + } + + String message = "[" + train.getName() + "] "; + if (count < train.getCount()){ + message += " " + df.format(date) + " ’x‰„‚È‚µ"; + } + else { + int N = 100; + + String sample = tweets.get(mindex).getText(); + sample = CommonUtil.replaceString(sample, "@", "(a)"); + sample = StringUtility.parseSubstring(sample, N); + message += " " + df.format(date) + sample + " count=" + count; + } + System.out.println(message); //TODO + Status status = twitter.updateStatus(message); //TODO + } + + private List getTrainList(){ + TrainDao dao = TrainDao.getInstance(); + List list = dao.search(); + if (list.size() <= 0){ + Train train; + + train = new Train("‹ž•l“Œ–kü", "‹ž•l“Œ–k", 5); + dao.put(train); + train = new Train("“ŒŠC“¹ü", "“ŒŠC“¹", 5); + dao.put(train); + train = new Train("‹ž•l‹}sü", "‹ž‹}", 5); + dao.put(train); + list = dao.search(); + } + return list; + } + + private static List keywords = null; + + public int filter(String text) { + if (keywords == null) { + keywords = new ArrayList(); + keywords.add("’x‰„"); + keywords.add("’x‚ê"); + keywords.add("U‚è‘Ö‚¦"); + keywords.add("U‘Ö"); + keywords.add("’âŽ~"); + keywords.add("Ž–ŒÌ"); + } + + int count = 0; + for (String keyword : keywords) { + if (text.indexOf(keyword) >= 0) { + count++; + } + } + return count; + } +} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a068b38fea6d001110a188bae663c898 b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a068b38fea6d001110a188bae663c898 new file mode 100644 index 0000000..02244b0 --- /dev/null +++ b/workspace/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a068b38fea6d001110a188bae663c898 @@ -0,0 +1,171 @@ +package com.yuji.tdb.twitter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; +import java.util.logging.Logger; + +import twitter4j.Query; +import twitter4j.QueryResult; +import twitter4j.Status; +import twitter4j.Tweet; +import twitter4j.Twitter; +import twitter4j.TwitterException; +import twitter4j.TwitterFactory; +import twitter4j.auth.AccessToken; +import twitter4j.conf.ConfigurationBuilder; + +import com.yuji.tdb.common.CommonUtil; +import com.yuji.tdb.db.Train; +import com.yuji.tdb.db.TrainDao; +import com.yuji.tdb.utility.StringUtility; + +public class TwitterUtil { + private static final Logger log = Logger + .getLogger(TwitterUtil.class.getName()); + private static TwitterUtil instance = null; + private static Object obj = new Object(); + //private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + private DateFormat df = new SimpleDateFormat("HH:mm"); + + public static TwitterUtil getInstance() { + if (instance == null) { + synchronized (obj) { + if (instance == null) { + instance = new TwitterUtil(); + } + } + } + return instance; + } + + private TwitterUtil() { + df.setTimeZone(TimeZone.getTimeZone("JST")); + } + + public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { + try { + ConfigurationBuilder confBuilder = new ConfigurationBuilder(); + confBuilder.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) + .setOAuthConsumerSecret(consumerSecret); + TwitterFactory factory = new TwitterFactory(confBuilder.build()); + Twitter twitter = factory.getInstance(accessToken); + + List list = getTrainList(); + for (Train train : list){ + twite(twitter, train); + } + } catch (TwitterException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + log.severe(e.toString()); + } + } + + private void twite(Twitter twitter, Train train) throws TwitterException { + Query query = new Query(); + //query.setRpp(1000); // TODO + query.setQuery(train.getSearchWord()); + QueryResult result = twitter.search(query); + List tweets = result.getTweets(); + + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + + int count = 0; + int hit = 0; + int mhit = 0; + + int index; + int mindex = 0; + int size = tweets.size(); + for (index = 0; index < size; index++) { + Tweet tweet = tweets.get(index); + + Date at = tweet.getCreatedAt(); + long t = at.getTime(); + + String message = tweet.getText(); + + if (t < cur - 30 * 60 * 1000){ + System.out.println("~" + tweet.getFromUser() + " - " + + tweet.getText() + at); + continue; + } + hit = filter(message); + if (hit <= 0) { + System.out.println("¢" + tweet.getFromUser() + " - " + + tweet.getText() + at); + // ’x‰„ˆÈŠO‚̏‘‚«ž‚Ý + continue; + } + if (hit > mhit){ + hit = mhit; + mindex = index; + } + + System.out.println("@" + tweet.getFromUser() + " - " + + tweet.getText() + at); + count++; + } + + String message = "[" + train.getName() + "] "; + if (count < train.getCount()){ + message += "’x‰„‚È‚µ " + df.format(date); + } + else { + int N = 100; + + String sample = tweets.get(mindex).getText(); + sample = CommonUtil.replaceString(sample, "@", "(a)"); + sample = StringUtility.parseSubstring(sample, N); + message += sample + " " + df.format(date) + " count=" + count; + } + System.out.println(message); //TODO + Status status = twitter.updateStatus(message); //TODO + } + + private List getTrainList(){ + TrainDao dao = TrainDao.getInstance(); + List list = dao.search(); + if (list.size() <= 0){ + Train train; + + train = new Train("‹ž•l“Œ–kü", "‹ž•l“Œ–k", 5); + dao.put(train); + train = new Train("“ŒŠC“¹ü", "“ŒŠC“¹", 5); + dao.put(train); + train = new Train("‹ž•l‹}sü", "‹ž‹}", 5); + dao.put(train); + list = dao.search(); + } + return list; + } + + private static List keywords = null; + + public int filter(String text) { + if (keywords == null) { + keywords = new ArrayList(); + keywords.add("’x‰„"); + keywords.add("’x‚ê"); + keywords.add("U‚è‘Ö‚¦"); + keywords.add("U‘Ö"); + keywords.add("’âŽ~"); + keywords.add("Ž–ŒÌ"); + } + + int count = 0; + for (String keyword : keywords) { + if (text.indexOf(keyword) >= 0) { + count++; + } + } + return count; + } +} diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Test/.markers.snap b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Test/.markers.snap new file mode 100644 index 0000000..1253ec8 Binary files /dev/null and b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Test/.markers.snap differ diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Test/.syncinfo.snap b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Test/.syncinfo.snap new file mode 100644 index 0000000..1253ec8 Binary files /dev/null and b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Test/.syncinfo.snap differ diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.indexes/properties.index b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.indexes/properties.index index 8f33548..451abdc 100644 Binary files a/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.indexes/properties.index and b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.indexes/properties.index differ diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.markers.snap b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.markers.snap new file mode 100644 index 0000000..1211b93 Binary files /dev/null and b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.markers.snap differ diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.syncinfo.snap b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.syncinfo.snap new file mode 100644 index 0000000..1253ec8 Binary files /dev/null and b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/.syncinfo.snap differ diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/org.eclipse.jdt.core/state.dat b/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/org.eclipse.jdt.core/state.dat deleted file mode 100644 index 72f4fc5..0000000 Binary files a/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/TrainDelayBot/org.eclipse.jdt.core/state.dat and /dev/null differ diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap b/workspace/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap new file mode 100644 index 0000000..8cc51e1 Binary files /dev/null and b/workspace/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap differ diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/workspace/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources index 9cb41d1..8b50b3d 100644 Binary files a/workspace/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources and b/workspace/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources differ diff --git a/workspace/.metadata/.plugins/org.eclipse.core.resources/.snap b/workspace/.metadata/.plugins/org.eclipse.core.resources/.snap new file mode 100644 index 0000000..5893e32 Binary files /dev/null and b/workspace/.metadata/.plugins/org.eclipse.core.resources/.snap differ diff --git a/workspace/.metadata/.plugins/org.eclipse.epp.usagedata.recording/usagedata.csv b/workspace/.metadata/.plugins/org.eclipse.epp.usagedata.recording/usagedata.csv index 18ea982..cfd0217 100644 --- a/workspace/.metadata/.plugins/org.eclipse.epp.usagedata.recording/usagedata.csv +++ b/workspace/.metadata/.plugins/org.eclipse.epp.usagedata.recording/usagedata.csv @@ -44,3 +44,178 @@ stopped,bundle,org.eclipse.ui.workbench.texteditor,3.7.0.v20110505-0800,"org.ecl stopped,bundle,org.eclipse.compare.core,3.5.200.I20110208-0800,"org.eclipse.compare.core",1331464966280 stopped,bundle,org.eclipse.emf.edit.ui,2.7.0.v20110606-0949,"org.eclipse.emf.edit.ui",1331464966280 stopped,bundle,org.eclipse.gef,3.7.0.v20110407-2050,"org.eclipse.gef",1331464966280 +activated,perspective,org.eclipse.jdt.ui,,"org.eclipse.jdt.ui.JavaPerspective",1331738400402 +started,bundle,org.eclipse.osgi,3.7.0.v20110613,"org.eclipse.osgi",1331738400403 +started,bundle,org.eclipse.equinox.simpleconfigurator,1.0.200.v20110502-1955,"org.eclipse.equinox.simpleconfigurator",1331738400403 +started,bundle,com.ibm.icu,4.4.2.v20110208,"com.ibm.icu",1331738400403 +started,bundle,org.eclipse.compare.core,3.5.200.I20110208-0800,"org.eclipse.compare.core",1331738400403 +started,bundle,org.eclipse.core.contenttype,3.4.100.v20110423-0524,"org.eclipse.core.contenttype",1331738400403 +started,bundle,org.eclipse.core.databinding.observable,1.4.0.I20110222-0800,"org.eclipse.core.databinding.observable",1331738400403 +started,bundle,org.eclipse.core.expressions,3.4.300.v20110228,"org.eclipse.core.expressions",1331738400403 +started,bundle,org.eclipse.core.filebuffers,3.5.200.v20110505-0800,"org.eclipse.core.filebuffers",1331738400403 +started,bundle,org.eclipse.core.filesystem,1.3.100.v20110423-0524,"org.eclipse.core.filesystem",1331738400403 +started,bundle,org.eclipse.core.jobs,3.5.100.v20110404,"org.eclipse.core.jobs",1331738400403 +started,bundle,org.eclipse.core.net,1.2.100.I20110511-0800,"org.eclipse.core.net",1331738400403 +started,bundle,org.eclipse.core.resources,3.7.100.v20110510-0712,"org.eclipse.core.resources",1331738400403 +started,bundle,org.eclipse.core.runtime,3.7.0.v20110110,"org.eclipse.core.runtime",1331738400403 +started,bundle,org.eclipse.core.runtime.compatibility,3.2.100.v20100505,"org.eclipse.core.runtime.compatibility",1331738400403 +started,bundle,org.eclipse.core.runtime.compatibility.auth,3.2.200.v20110110,"org.eclipse.core.runtime.compatibility.auth",1331738400403 +started,bundle,org.eclipse.core.variables,3.2.500.v20110511,"org.eclipse.core.variables",1331738400403 +started,bundle,org.eclipse.debug.core,3.7.0.v20110518,"org.eclipse.debug.core",1331738400403 +started,bundle,org.eclipse.epp.mpc.ui,1.1.0.I20110525-0742,"org.eclipse.epp.mpc.ui",1331738400403 +started,bundle,org.eclipse.epp.usagedata.gathering,1.3.1.R201106061540,"org.eclipse.epp.usagedata.gathering",1331738400403 +started,bundle,org.eclipse.epp.usagedata.recording,1.3.1.R201106061540,"org.eclipse.epp.usagedata.recording",1331738400403 +started,bundle,org.eclipse.equinox.app,1.3.100.v20110321,"org.eclipse.equinox.app",1331738400403 +started,bundle,org.eclipse.equinox.common,3.6.0.v20110523,"org.eclipse.equinox.common",1331738400403 +started,bundle,org.eclipse.equinox.ds,1.3.0.v20110502,"org.eclipse.equinox.ds",1331738400403 +started,bundle,org.eclipse.equinox.event,1.2.100.v20110502,"org.eclipse.equinox.event",1331738400403 +started,bundle,org.eclipse.equinox.p2.core,2.1.0.v20110502-1955,"org.eclipse.equinox.p2.core",1331738400403 +started,bundle,org.eclipse.equinox.p2.directorywatcher,1.0.300.v20110502-1955,"org.eclipse.equinox.p2.directorywatcher",1331738400403 +started,bundle,org.eclipse.equinox.p2.engine,2.1.0.v20110511,"org.eclipse.equinox.p2.engine",1331738400403 +started,bundle,org.eclipse.equinox.p2.metadata,2.1.0.v20110510,"org.eclipse.equinox.p2.metadata",1331738400403 +started,bundle,org.eclipse.equinox.p2.metadata.repository,1.2.0.v20110511-1359,"org.eclipse.equinox.p2.metadata.repository",1331738400403 +started,bundle,org.eclipse.equinox.p2.operations,2.1.0.v20110511-1821,"org.eclipse.equinox.p2.operations",1331738400403 +started,bundle,org.eclipse.equinox.p2.reconciler.dropins,1.1.100.v20110510,"org.eclipse.equinox.p2.reconciler.dropins",1331738400403 +started,bundle,org.eclipse.equinox.p2.repository,2.1.0.v20110601,"org.eclipse.equinox.p2.repository",1331738400403 +started,bundle,org.eclipse.equinox.p2.ui.sdk.scheduler,1.0.100.v20110502-1955,"org.eclipse.equinox.p2.ui.sdk.scheduler",1331738400403 +started,bundle,org.eclipse.equinox.p2.updatechecker,1.1.200.v20110502-1955,"org.eclipse.equinox.p2.updatechecker",1331738400403 +started,bundle,org.eclipse.equinox.preferences,3.4.0.v20110502,"org.eclipse.equinox.preferences",1331738400403 +started,bundle,org.eclipse.equinox.registry,3.5.100.v20110502,"org.eclipse.equinox.registry",1331738400403 +started,bundle,org.eclipse.equinox.security,1.1.0.v20110502,"org.eclipse.equinox.security",1331738400403 +started,bundle,org.eclipse.equinox.util,1.0.300.v20110502,"org.eclipse.equinox.util",1331738400403 +started,bundle,org.eclipse.help,3.5.100.v20110426,"org.eclipse.help",1331738400403 +started,bundle,org.eclipse.jdt.apt.core,3.3.500.v20110420-1015,"org.eclipse.jdt.apt.core",1331738400403 +started,bundle,org.eclipse.jdt.apt.pluggable.core,1.0.400.v20110305-1450,"org.eclipse.jdt.apt.pluggable.core",1331738400403 +started,bundle,org.eclipse.jdt.core,3.7.0.v_B61,"org.eclipse.jdt.core",1331738400403 +started,bundle,org.eclipse.jdt.core.manipulation,1.4.0.v20110505-0800,"org.eclipse.jdt.core.manipulation",1331738400403 +started,bundle,org.eclipse.jdt.launching,3.6.0.v20110509,"org.eclipse.jdt.launching",1331738400403 +started,bundle,org.eclipse.jdt.launching.macosx,3.2.100.v20110509,"org.eclipse.jdt.launching.macosx",1331738400403 +started,bundle,org.eclipse.jdt.ui,3.7.0.v20110531-1200,"org.eclipse.jdt.ui",1331738400403 +started,bundle,org.eclipse.jface,3.7.0.I20110522-1430,"org.eclipse.jface",1331738400403 +started,bundle,org.eclipse.jsch.core,1.1.300.I20110514-0800,"org.eclipse.jsch.core",1331738400403 +started,bundle,org.eclipse.ltk.core.refactoring,3.5.200.v20110505-0800,"org.eclipse.ltk.core.refactoring",1331738400403 +started,bundle,org.eclipse.ltk.ui.refactoring,3.6.0.v20110505-0800,"org.eclipse.ltk.ui.refactoring",1331738400403 +started,bundle,org.eclipse.m2e.logback.configuration,1.0.0.20110607-2117,"org.eclipse.m2e.logback.configuration",1331738400403 +started,bundle,org.eclipse.mylyn.bugzilla.core,3.6.0.v20110608-1400,"org.eclipse.mylyn.bugzilla.core",1331738400403 +started,bundle,org.eclipse.mylyn.bugzilla.ui,3.6.0.v20110608-1400,"org.eclipse.mylyn.bugzilla.ui",1331738400403 +started,bundle,org.eclipse.mylyn.commons.identity,0.8.0.v20110608-1400,"org.eclipse.mylyn.commons.identity",1331738400403 +started,bundle,org.eclipse.mylyn.commons.net,3.6.0.v20110608-1400,"org.eclipse.mylyn.commons.net",1331738400403 +started,bundle,org.eclipse.mylyn.context.core,3.6.0.v20110608-1400,"org.eclipse.mylyn.context.core",1331738400403 +started,bundle,org.eclipse.mylyn.context.ui,3.6.0.v20110608-1400,"org.eclipse.mylyn.context.ui",1331738400403 +started,bundle,org.eclipse.mylyn.monitor.ui,3.6.0.v20110608-1400,"org.eclipse.mylyn.monitor.ui",1331738400403 +started,bundle,org.eclipse.mylyn.tasks.ui,3.6.0.v20110608-1400,"org.eclipse.mylyn.tasks.ui",1331738400403 +started,bundle,org.eclipse.mylyn.team.ui,3.6.0.v20110608-1400,"org.eclipse.mylyn.team.ui",1331738400403 +started,bundle,org.eclipse.search,3.7.0.v20110505-0800,"org.eclipse.search",1331738400403 +started,bundle,org.eclipse.team.core,3.6.0.I20110525-0800,"org.eclipse.team.core",1331738400403 +started,bundle,org.eclipse.team.cvs.core,3.3.400.I20110510-0800,"org.eclipse.team.cvs.core",1331738400403 +started,bundle,org.eclipse.team.cvs.ui,3.3.400.I20110510-0800,"org.eclipse.team.cvs.ui",1331738400403 +started,bundle,org.eclipse.team.ui,3.6.100.I20110525-0800,"org.eclipse.team.ui",1331738400403 +started,bundle,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui",1331738400403 +started,bundle,org.eclipse.ui.console,3.5.100.v20110511,"org.eclipse.ui.console",1331738400403 +started,bundle,org.eclipse.ui.editors,3.7.0.v20110517-0800,"org.eclipse.ui.editors",1331738400403 +started,bundle,org.eclipse.ui.forms,3.5.100.v20110425,"org.eclipse.ui.forms",1331738400403 +started,bundle,org.eclipse.ui.ide,3.7.0.I20110519-0100,"org.eclipse.ui.ide",1331738400403 +started,bundle,org.eclipse.ui.net,1.2.100.I20110511-0800,"org.eclipse.ui.net",1331738400403 +started,bundle,org.eclipse.ui.views,3.6.0.I20110412-0800,"org.eclipse.ui.views",1331738400403 +started,bundle,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"org.eclipse.ui.workbench",1331738400403 +started,bundle,org.eclipse.ui.workbench.texteditor,3.7.0.v20110505-0800,"org.eclipse.ui.workbench.texteditor",1331738400403 +started,bundle,org.eclipse.update.configurator,3.3.100.v20100512,"org.eclipse.update.configurator",1331738400403 +started,bundle,org.eclipse.update.core,3.2.500.v20110330,"org.eclipse.update.core",1331738400403 +started,bundle,org.eclipse.update.scheduler,3.2.300.v20100512,"org.eclipse.update.scheduler",1331738400403 +started,bundle,org.eclipse.wb.discovery.core,1.0.0.r37x201106081733,"org.eclipse.wb.discovery.core",1331738400403 +started,bundle,com.google.appengine.eclipse.core,2.5.2.v201202290255-rel-r37,"com.google.appengine.eclipse.core",1331738400403 +started,bundle,com.google.gdt.eclipse.appengine.rpc,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.appengine.rpc",1331738400403 +started,bundle,com.google.gdt.eclipse.core,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.core",1331738400403 +started,bundle,com.google.gdt.eclipse.designer,2.5.0.r37x201112291029,"com.google.gdt.eclipse.designer",1331738400403 +started,bundle,com.google.gdt.eclipse.login,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.login",1331738400403 +started,bundle,com.google.gdt.eclipse.managedapis,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.managedapis",1331738400404 +started,bundle,com.google.gdt.eclipse.maven,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.maven",1331738400404 +started,bundle,com.google.gdt.eclipse.platform.e37,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.platform.e37",1331738400404 +started,bundle,com.google.gdt.eclipse.platform.shared,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.platform.shared",1331738400404 +started,bundle,com.google.gdt.eclipse.suite,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.suite",1331738400404 +started,bundle,com.google.gdt.eclipse.suite.ext,2.5.2.v201202290255-rel-r37,"com.google.gdt.eclipse.suite.ext",1331738400404 +started,bundle,com.google.gwt.eclipse.core,2.5.2.v201202290255-rel-r37,"com.google.gwt.eclipse.core",1331738400404 +started,bundle,org.eclipse.mylyn.commons.ui,3.6.1.v20110720-0100,"org.eclipse.mylyn.commons.ui",1331738400404 +started,bundle,org.eclipse.wb.core,1.2.0.r37x201112290923,"org.eclipse.wb.core",1331738400404 +started,bundle,org.eclipse.wb.core.lib,1.2.0.r37x201112290923,"org.eclipse.wb.core.lib",1331738400404 +os,sysinfo,,,"macosx",1331738400406 +arch,sysinfo,,,"x86_64",1331738400406 +ws,sysinfo,,,"cocoa",1331738400406 +locale,sysinfo,,,"ja_JP",1331738400406 +processors,sysinfo,,,"8",1331738400406 +java.runtime.name,sysinfo,,,"Java(TM) SE Runtime Environment",1331738400406 +java.runtime.version,sysinfo,,,"1.6.0_29-b11-402-11D50d",1331738400406 +java.specification.name,sysinfo,,,"Java Platform API Specification",1331738400406 +java.specification.vendor,sysinfo,,,"Sun Microsystems Inc.",1331738400406 +java.specification.version,sysinfo,,,"1.6",1331738400406 +java.vendor,sysinfo,,,"Apple Inc.",1331738400406 +java.version,sysinfo,,,"1.6.0_29",1331738400406 +java.vm.info,sysinfo,,,"mixed mode",1331738400406 +java.vm.name,sysinfo,,,"Java HotSpot(TM) 64-Bit Server VM",1331738400406 +java.vm.specification.name,sysinfo,,,"Java Virtual Machine Specification",1331738400406 +java.vm.specification.vendor,sysinfo,,,"Sun Microsystems Inc.",1331738400406 +java.vm.specification.version,sysinfo,,,"1.0",1331738400406 +java.vm.vendor,sysinfo,,,"Apple Inc.",1331738400406 +java.vm.version,sysinfo,,,"20.4-b02-402",1331738400406 +started,bundle,org.eclipse.m2e.usagedata,1.0.200.20111228-1245,"org.eclipse.m2e.usagedata",1331738400408 +started,bundle,org.eclipse.wb.discovery.ui,1.0.0.r37x201106081733,"org.eclipse.wb.discovery.ui",1331738400545 +started,bundle,com.google.gdt.eclipse.designer.hosted,2.5.0.r37x201112291019,"com.google.gdt.eclipse.designer.hosted",1331738400557 +started,bundle,com.google.gdt.eclipse.designer.UiBinder,2.5.0.r37x201112291029,"com.google.gdt.eclipse.designer.UiBinder",1331738400562 +opened,view,org.eclipse.ui.ide,3.7.0.I20110519-0100,"org.eclipse.ui.views.ProblemView",1331738401833 +started,bundle,org.eclipse.jdt.junit,3.7.0.v20110505-0800,"org.eclipse.jdt.junit",1331738402120 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.cut",1331738426543 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.paste",1331738428362 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.file.save",1331738429693 +started,bundle,org.eclipse.debug.ui,3.7.0.v20110518,"org.eclipse.debug.ui",1331738430056 +started,bundle,org.eclipse.jdt.debug,3.7.0.v20110509,"org.eclipse.jdt.debug",1331738430247 +started,bundle,org.eclipse.jdt.debug.ui,3.6.0.v20110512,"org.eclipse.jdt.debug.ui",1331738430323 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738433885 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738476975 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738482636 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738669880 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738683989 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738726127 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.paste",1331738757932 +started,bundle,org.eclipse.mylyn.ide.ui,3.6.0.v20110608-1400,"org.eclipse.mylyn.ide.ui",1331738783599 +started,bundle,org.eclipse.mylyn.java.ui,3.6.0.v20110608-1400,"org.eclipse.mylyn.java.ui",1331738783645 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.file.save",1331738784315 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738786028 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738787875 +executed,command,org.eclipse.jdt.ui,3.7.0.v20110531-1200,"org.eclipse.jdt.ui.edit.text.java.organize.imports",1331738788060 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.file.save",1331738792578 +started,bundle,org.eclipse.m2e.launching,1.0.200.20111228-1245,"org.eclipse.m2e.launching",1331738798107 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738801274 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738857703 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738868027 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738906501 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.copy",1331738915982 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.paste",1331738917026 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.file.save",1331738928422 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.cut",1331738941950 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.paste",1331738953538 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.cut",1331738977322 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.edit.paste",1331738980503 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738989422 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331738999064 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.file.save",1331738999901 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.file.save",1331739012835 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739027622 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739034209 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739039621 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739047097 +executed,command,org.eclipse.ui,3.7.0.I20110602-0100,"org.eclipse.ui.file.save",1331739073080 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739078472 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739090944 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739106285 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739166384 +executed,command,,,"AUTOGEN:::org.eclipse.jdt.debug.CompilationUnitEditor.BreakpointRulerActions/org.eclipse.jdt.debug.ui.actions.ManageBreakpointRulerAction",1331739221884 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739224199 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739224275 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739226473 +opened,view,org.eclipse.debug.ui,3.7.0.v20110518,"org.eclipse.debug.ui.DebugView",1331739231758 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739231799 +executed,command,org.eclipse.debug.ui,3.7.0.v20110518,"org.eclipse.debug.ui.commands.StepOver",1331739241940 +executed,command,org.eclipse.debug.ui,3.7.0.v20110518,"org.eclipse.debug.ui.commands.StepOver",1331739244108 +deactivated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739259167 +activated,workbench,org.eclipse.ui.workbench,3.7.0.I20110519-0100,"",1331739267527 +executed,command,org.eclipse.debug.ui,3.7.0.v20110518,"org.eclipse.debug.ui.commands.Resume",1331739268741 diff --git a/workspace/.metadata/.plugins/org.eclipse.jdt.core/471433581.index b/workspace/.metadata/.plugins/org.eclipse.jdt.core/471433581.index index 40255f3..352860d 100644 Binary files a/workspace/.metadata/.plugins/org.eclipse.jdt.core/471433581.index and b/workspace/.metadata/.plugins/org.eclipse.jdt.core/471433581.index differ diff --git a/workspace/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps b/workspace/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps index f022912..e301f37 100644 Binary files a/workspace/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps and b/workspace/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps differ diff --git a/workspace/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt b/workspace/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt index a716814..9d21d8c 100644 --- a/workspace/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt +++ b/workspace/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt @@ -14,8 +14,8 @@ INDEX VERSION 1.126+/Users/yuji/prog/workspaces/TrainDelayBot/source/workspace/. 4286473667.index 156905802.index 3712507179.index -272178059.index 4210253391.index +272178059.index 2487942853.index 545044415.index 3954040986.index diff --git a/workspace/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat b/workspace/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat index 36d8da0..fcb683b 100644 Binary files a/workspace/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat and b/workspace/.metadata/.plugins/org.eclipse.jdt.core/variablesAndContainers.dat differ diff --git a/workspace/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png b/workspace/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png new file mode 100644 index 0000000..db80ee8 Binary files /dev/null and b/workspace/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png differ diff --git a/workspace/.metadata/.plugins/org.eclipse.m2e.logback.configuration/0.log b/workspace/.metadata/.plugins/org.eclipse.m2e.logback.configuration/0.log index a214979..08c9edd 100644 --- a/workspace/.metadata/.plugins/org.eclipse.m2e.logback.configuration/0.log +++ b/workspace/.metadata/.plugins/org.eclipse.m2e.logback.configuration/0.log @@ -14,3 +14,4 @@ 2012-03-11 00:50:50,092 [org.eclipse.jdt.internal.ui.text.JavaReconciler] INFO org.mortbay.log - Logging to Logger[org.mortbay.log] via org.mortbay.log.Slf4jLog 2012-03-11 02:09:03,359 [org.eclipse.jdt.internal.ui.text.JavaReconciler] INFO org.mortbay.log - Logging to Logger[org.mortbay.log] via org.mortbay.log.Slf4jLog 2012-03-11 09:07:32,089 [org.eclipse.jdt.internal.ui.text.JavaReconciler] INFO org.mortbay.log - Logging to Logger[org.mortbay.log] via org.mortbay.log.Slf4jLog +2012-03-15 00:19:58,936 [org.eclipse.jdt.internal.ui.text.JavaReconciler] INFO org.mortbay.log - Logging to Logger[org.mortbay.log] via org.mortbay.log.Slf4jLog diff --git a/workspace/.metadata/.plugins/org.eclipse.team.cvs.core/.running b/workspace/.metadata/.plugins/org.eclipse.team.cvs.core/.running new file mode 100644 index 0000000..e69de29 diff --git a/workspace/TrainDelayBot/src/com/yuji/tdb/twitter/TwitterUtil.java b/workspace/TrainDelayBot/src/com/yuji/tdb/twitter/TwitterUtil.java index 9ea526e..854280b 100644 --- a/workspace/TrainDelayBot/src/com/yuji/tdb/twitter/TwitterUtil.java +++ b/workspace/TrainDelayBot/src/com/yuji/tdb/twitter/TwitterUtil.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.TimeZone; import java.util.logging.Logger; import twitter4j.Query; @@ -28,7 +29,8 @@ public class TwitterUtil { .getLogger(TwitterUtil.class.getName()); private static TwitterUtil instance = null; private static Object obj = new Object(); - private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + //private DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + private DateFormat df = new SimpleDateFormat("HH:mm"); public static TwitterUtil getInstance() { if (instance == null) { @@ -42,7 +44,7 @@ public class TwitterUtil { } private TwitterUtil() { - //TimeZone.setDefault(TimeZone.getTimeZone("JST")); // TODO êŠ + df.setTimeZone(TimeZone.getTimeZone("JST")); } public void main(String consumerKey, String consumerSecret, AccessToken accessToken) { @@ -65,16 +67,16 @@ public class TwitterUtil { } private void twite(Twitter twitter, Train train) throws TwitterException { - Calendar cal = Calendar.getInstance(); - Date date = cal.getTime(); - long cur = date.getTime(); - Query query = new Query(); //query.setRpp(1000); // TODO query.setQuery(train.getSearchWord()); QueryResult result = twitter.search(query); List tweets = result.getTweets(); + Calendar cal = Calendar.getInstance(); + Date date = cal.getTime(); + long cur = date.getTime(); + int count = 0; int hit = 0; int mhit = 0; @@ -90,7 +92,7 @@ public class TwitterUtil { String message = tweet.getText(); - if (t < cur - 30 * 60 * 1000){ + if (t < cur - 5 * 60 * 1000){ System.out.println("~" + tweet.getFromUser() + " - " + tweet.getText() + at); continue; @@ -114,7 +116,7 @@ public class TwitterUtil { String message = "[" + train.getName() + "] "; if (count < train.getCount()){ - message += "’x‰„‚È‚µ " + df.format(date); + message += df.format(date) + " ’x‰„‚È‚µ"; } else { int N = 100; @@ -122,7 +124,7 @@ public class TwitterUtil { String sample = tweets.get(mindex).getText(); sample = CommonUtil.replaceString(sample, "@", "(a)"); sample = StringUtility.parseSubstring(sample, N); - message += sample + " " + df.format(date) + " count=" + count; + message += df.format(date) + " " + sample + " count=" + count; } System.out.println(message); //TODO Status status = twitter.updateStatus(message); //TODO diff --git a/workspace/TrainDelayBot/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml b/workspace/TrainDelayBot/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml index c58b291..dbefad8 100644 --- a/workspace/TrainDelayBot/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml +++ b/workspace/TrainDelayBot/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml @@ -1,4 +1,4 @@ - + diff --git a/workspace/TrainDelayBot/war/WEB-INF/appengine-generated/local_db.bin b/workspace/TrainDelayBot/war/WEB-INF/appengine-generated/local_db.bin index 732a460..d0f3dc5 100644 Binary files a/workspace/TrainDelayBot/war/WEB-INF/appengine-generated/local_db.bin and b/workspace/TrainDelayBot/war/WEB-INF/appengine-generated/local_db.bin differ