From fb05754af5941734236d9a62978888fad93bf261 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 4 Nov 2016 14:35:19 +0100 Subject: Gracefully handle mentions without user ID Encountered a retweet where the ID is null, but the screen_name is at least given and matches the user: "user_mentions": [{ "screen_name": "(username)", "name": null, "id": null, "id_str": null, "indices": [3, 16] --- src/data/Tweet.java | 4 ++-- src/main/DataFiller.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/data/Tweet.java b/src/data/Tweet.java index 6ee89f4..bd5d352 100644 --- a/src/data/Tweet.java +++ b/src/data/Tweet.java @@ -59,7 +59,7 @@ public class Tweet { public Hashtag[] hashtags; //@ValidatingJsonDeserializer.Validator public Url[] urls; - @ValidatingJsonDeserializer.Validator + //@ValidatingJsonDeserializer.Validator public Mention[] user_mentions; } @@ -79,6 +79,6 @@ public class Tweet { public long id; // user ID //public String name; // display name - //public String screen_name; // Screen name (at-name) + public String screen_name; // Screen name (at-name) } } diff --git a/src/main/DataFiller.java b/src/main/DataFiller.java index 2a06026..3a19f37 100644 --- a/src/main/DataFiller.java +++ b/src/main/DataFiller.java @@ -122,7 +122,19 @@ public class DataFiller { } for (Tweet.Mention mention : tweet.entities.user_mentions) { m_insertMentions.setLong("tweetid", tweet.id); - m_insertMentions.setLong("userid", mention.id); + if (mention.id == 0) { + Tweet rt = tweet.retweeted_status; + if (rt != null && rt.user.screen_name != null && + rt.user.screen_name.equals(mention.screen_name)) { + m_insertMentions.setLong("userid", rt.user.id); + } else { + System.err.println("Unknown mention in tweet, skipping metadata!"); + System.err.println(tweet); + continue; + } + } else { + m_insertMentions.setLong("userid", mention.id); + } m_insertMentions.executeUpdate(); } -- cgit v1.2.1