diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-05-02 13:35:43 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-05-02 13:35:43 +0200 |
commit | 125d8d251de88d2522a849e02b92071177ba00ae (patch) | |
tree | 83070ae337ee66556a3c908590bec29bee299a90 /src | |
parent | db80ae2107b658923ef894adb3679ea2fe4cab63 (diff) | |
download | TwitterDataAnalytics-125d8d251de88d2522a849e02b92071177ba00ae.tar.gz |
Basic stats for tweets
Diffstat (limited to 'src')
-rw-r--r-- | src/main/TweetCounter.java | 28 | ||||
-rw-r--r-- | src/main/TweetShell.java | 11 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/main/TweetCounter.java b/src/main/TweetCounter.java new file mode 100644 index 0000000..19838e7 --- /dev/null +++ b/src/main/TweetCounter.java @@ -0,0 +1,28 @@ +package main; + +import org.json.JSONObject; +import provider.ResultListener; + +/** + * Calculates statistic about the received tweets. + * + * @author Peter Wu + */ +public class TweetCounter implements ResultListener { + + private int tweetCount = 0; + + @Override + public void tweetGenerated(JSONObject obj) { + tweetCount++; + } + + @Override + public void profileGenerated(JSONObject obj) { + // ignored + } + + public int getTweetCount() { + return tweetCount; + } +} diff --git a/src/main/TweetShell.java b/src/main/TweetShell.java index 12814b0..3ab1397 100644 --- a/src/main/TweetShell.java +++ b/src/main/TweetShell.java @@ -168,6 +168,7 @@ public class TweetShell implements TwitterApi.PinSupplier { del("Deletes a keyword from search", 1), keywords("Display currently active keywords"), commit("Activate the stream or apply the stream keyword changes"), + status("Show some status and statistics"), close("Close the stream"), exit("Returns to shell"), help("Get help"), @@ -253,6 +254,16 @@ public class TweetShell implements TwitterApi.PinSupplier { case commit: getStream().commit(); break; + case status: + TweetCounter tc; + tc = (TweetCounter) resultListeners.findListener(TweetCounter.class); + if (stream_cached != null && getStream().isValid()) { + System.out.println("Streaming is active."); + } else { + System.out.println("Streaming is inactive."); + } + System.out.println("Received tweets in session: " + tc.getTweetCount()); + break; case close: getStream().close(); break; |