From 125d8d251de88d2522a849e02b92071177ba00ae Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 2 May 2014 13:35:43 +0200 Subject: Basic stats for tweets --- src/main/TweetCounter.java | 28 ++++++++++++++++++++++++++++ src/main/TweetShell.java | 11 +++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/main/TweetCounter.java 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; -- cgit v1.2.1