summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-02 17:12:05 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-02 17:12:05 +0200
commit42bc583b80535affa5b1235d4c534984a738c958 (patch)
tree1d819bb3229a85e7c3b37345196320484ba14167
parentc112dcf584048d7f94c9cf6136105b9f6dc83215 (diff)
downloadTwitterDataAnalytics-42bc583b80535affa5b1235d4c534984a738c958.tar.gz
Track number of unique users for status reporting
-rw-r--r--src/main/TweetCounter.java27
-rw-r--r--src/main/TweetShell.java1
2 files changed, 27 insertions, 1 deletions
diff --git a/src/main/TweetCounter.java b/src/main/TweetCounter.java
index 19838e7..4c348b3 100644
--- a/src/main/TweetCounter.java
+++ b/src/main/TweetCounter.java
@@ -1,5 +1,10 @@
package main;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.json.JSONException;
import org.json.JSONObject;
import provider.ResultListener;
@@ -10,7 +15,15 @@ import provider.ResultListener;
*/
public class TweetCounter implements ResultListener {
+ private final static Logger LOGGER
+ = Logger.getLogger(TweetCounter.class.getName());
+
private int tweetCount = 0;
+ private final Set<String> users;
+
+ public TweetCounter() {
+ this.users = new HashSet<>();
+ }
@Override
public void tweetGenerated(JSONObject obj) {
@@ -19,10 +32,22 @@ public class TweetCounter implements ResultListener {
@Override
public void profileGenerated(JSONObject obj) {
- // ignored
+ try {
+ String screen_name = obj.getString("screen_name");
+ users.add(screen_name);
+ } catch (JSONException ex) {
+ LOGGER.log(Level.WARNING, "Profile is missing data", ex);
+ }
}
public int getTweetCount() {
return tweetCount;
}
+
+ /**
+ * @return The set of users who tweeted. Do not modify its contents!
+ */
+ public Set<String> getUsers() {
+ return users;
+ }
}
diff --git a/src/main/TweetShell.java b/src/main/TweetShell.java
index a5114e2..a7738d5 100644
--- a/src/main/TweetShell.java
+++ b/src/main/TweetShell.java
@@ -263,6 +263,7 @@ public class TweetShell implements TwitterApi.PinSupplier {
System.out.println("Streaming is inactive.");
}
System.out.println("Received tweets in session: " + tc.getTweetCount());
+ System.out.println("Unique users: " + tc.getUsers().size());
break;
case close:
getStream().close();