Message Boards Message Boards

[WSS17] Playing with Wolfram's Twitter Capabilities: Big-T

Posted 7 years ago

Status as of July 1, 2017.

Let's look at some basic info:

twitter = ServiceConnect["Twitter", "New"];
twitter["UserData", "Username" -> "realDonaldTrump"]

{<|"ID" -> 25073877, "Name" -> "Donald J. Trump", 
  "ScreenName" -> "realDonaldTrump", "Location" -> "Washington, DC", 
  "FollowersCount" -> 33179562, "FriendsCount" -> 45, 
  "FavouritesCount" -> 24|>}

33 MILLION PEOPLE

What are his favorite words?

getTweetStrings[username_, number_: 4000] := Block[{text, tweetsDT},
  tweetsDT = 
   twitter["TweetList", "Username" -> username, MaxItems -> number];
  text = Flatten[StringSplit[Normal[tweetsDT[All, "Text"]]], 1];
  StringDelete[
   DeleteStopwords[text], {"&amp", ";", ".", ",", "-", "_", "\"", "(",
     ")", "RT"}]]
WordCloud@getTweetStrings["realDonaldTrump"]

enter image description here

dttweetsstrings = getTweetStrings["realDonaldTrump"];
Total@StringCount[dttweetsstrings, {"Great", "great", "GREAT"}]

556

Looks GREAT

Bigly Positive

posneg = Classify["Sentiment", dttweetsstrings];
tallied = Transpose@Tally@posneg

{{"Negative", "Neutral", "Positive", Indeterminate}, {6608, 6245, 
  21606, 224}}

BarChart[tallied[[2]], ChartLabels -> Placed[tallied[[1]], Above], 
 ColorFunction -> "ThermometerColors"]

enter image description here

The ~15,000 difference is yuge.

Who's his posse?

posse = twitter["Friends", "Username" -> "realDonaldTrump"]

{"Tucker Carlson", "Jesse Watters", "The White House", "Dan Scavino Jr.", "Kellyanne Conway", "Reince Priebus", "Roma Downey", "Trump Organization", "Trump Golf", "Tiffany Ariana Trump", "Laura Ingraham", "Mike Pence", "Official Team Trump", "DRUDGE REPORT", "Vanessa Trump", "Lara Trump", "Sean Hannity", "Fox Nation", "Corey R. Lewandowski", "Ann Coulter", "Diamond and Silk®", "KATRINA CAMPINS", "Katrina Pierson", "Michael Cohen", "FOX & friends", "MELANIA TRUMP", "Geraldo Rivera", "Eric Bolling", "Mark Burnett", "Gary Player", "Vince McMahon", "Dan Scavino Jr.", "Trump Waikiki", "Trump National Doral", "Trump Charlotte", "Trump Vegas Hotel", "Trump Hotel Chicago", "Trump Washington DC", "Trump Los Angeles", "Eric Trump", "Bill O'Reilly", "Greta Van Susteren", "Piers Morgan", "Donald Trump Jr.", "Ivanka Trump"}

possegraph = 
  twitter["FriendNetwork", "Username" -> "realDonaldTrump"];

enter image description here

Three big clumps. He's one of the red ones, can you guess which? Unfortunately, I wasn't able to get the vertex names to show on the graph without hovering over each one since the vertex list and friend list aren't in the same order.

First@VertexList[possegraph]

25073877

Note that Big-T's ID is 25073877 whereas Tucker's is 22703645.

How much do his friends reply?

twitter["FriendReplyToNetwork", "Username" -> "realDonaldTrump"]

enter image description here

None of his friends reply to him or each other apparently.

twitter["FriendMentionNetwork", "Username" -> "realDonaldTrump"]

enter image description here

They do like to gossip about one another though. Big-T's node in this graph is fairly obvious.

When does he use Twitter?

dteventseries = 
 twitter["TweetEventSeries", "Username" -> "realDonaldTrump", 
  MaxItems -> 5000];

datediff = 
 DateDifference[DateObject[{2016, 5, 21}], DateObject[{2017, 7, 2}]]

407 days

He's had the account since 2009, however Twitter seems to delete tweets after a certain number or time frame. We can only get about 3,200 but the real number of tweets is upwards of 35,000.

N[Quantity[Length@dteventseries["Times"], "tweets"]/datediff]

7.90909 tweets/day

Eight a day is too many for anyone.

hourlypercents = 
 DateHistogram[dteventseries["Dates"], "Hour", "Probability", 
  DateReduction -> "Day", ColorFunction -> "ThermometerColors"]

enter image description here

He sure does like his morning and night tweet sessions

weekcounts = 
 DateHistogram[dteventseries["Dates"], "Day", DateReduction -> "Week",
   ColorFunction -> "ThermometerColors", LabelingFunction -> Above]

enter image description here

Tuesday's tweet hustle day. In all honesty though, he's pretty consistent.

And finally, we have the tweet count chart going back to about May 2016.

alltimecounts = 
 DateHistogram[dteventseries["Dates"], "Month", 
  ColorFunction -> "ThermometerColors", LabelingFunction -> Above]

enter image description here

The election season spike was expected, but wow that's a lot.

I regret that I couldn't look at more of the data since Twitter caps the request amount, although I still had fun with the ~3,200 tweets to which I did have access.

Github link to notebook

POSTED BY: Z D
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract