Created
February 8, 2013 07:11
-
-
Save yusuke/4737226 to your computer and use it in GitHub Desktop.
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 sandbox; | |
import twitter4j.*; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
public class Test { | |
public static void main(String[] args) throws TwitterException, ParseException { | |
Twitter twitter = TwitterFactory.getSingleton(); | |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | |
Date since = format.parse("2006-03-01"); | |
Date until = monthLater(since); | |
Date now = new Date(); | |
while (since.before(now)) { | |
String sinceStr = format.format(since); | |
String untilStr = format.format(until); | |
Query query = new Query("now"); | |
query.since(sinceStr).until(untilStr); | |
QueryResult result = twitter.search(query); | |
System.out.printf("%s-%s %d\n", sinceStr, untilStr, result.getTweets().size()); | |
since = until; | |
until = monthLater(since); | |
} | |
} | |
static Date monthLater(Date date) { | |
Calendar calendar = Calendar.getInstance(); | |
calendar.setTime(date); | |
calendar.add(Calendar.MONTH, 1); | |
return calendar.getTime(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment