CITE THIS NOTEBOOK: Exploring tweets using SQL operators paclet by Damian Calin. Wolfram Community NOV 29 2022.
The objective of this post is to explore and analyse user twitter replies using SQL tables.
Basically I create a wrapper on Twitter service connector ( documented at:https://reference.wolfram.com/language/ref/service/Twitter.html )
using SQL package presented on previous posts and available to download as repository paclet (https://resources.wolframcloud.com/PacletRepository/resources/DamianCalin/SQLOperators)

Load SQL paclet

Load the last version of SQLOperators paclet.
​https://resources.wolframcloud.com/PacletRepository/resources/DamianCalin/SQLOperators/
PacletInstall["DamianCalin/SQLOperators"];​​Needs["DamianCalin`SQLOperators`"]

Connect to Twitter service

In[]:=
twitter=ServiceConnect["Twitter","New"];
You should be redirected to authentication web page , and click “Authorise App”​
Now you’re connected.
Check if successfully connected by getting replies from by far most popular twitter user :
In[]:=
twitter​​twitter["UserData","Username"->"elonmusk"]
Out[]=
ServiceObject
Twitter
Not Connected

Out[]=
ID44196397,ScreenNameelonmusk,NameElon Musk,LocationMissing[NotAvailable],FavouritesCount15404,FollowersCount119423978,FriendsCount130,TweetsCount20856,CreationDate
Tue 2 Jun 2009 20:12:29GMT


Create a SQL table wrapper on service request

twRepliesSQL function gets twitter connector and options as input and returns sql table.
Does some data cleansing by separating text and users replied to.
ClearAll[twRepliesSQL];​​twRepliesSQL[connector_,opt__Rule]:=Block[{twreplies=connector["UserReplies",opt],​​cols={"id","text","date","username","url"}},​​tableSQL[twreplies//​​Cases[#,x_:>(x//Values)]&//​​Cases[#,r_:>(connector["GetTweet","TweetID"->(r//First)]//Normal//Values)]&,cols]//​​rowTransformSQL[#,Association["id":>id,​​"text":>StringDelete[text,RegularExpression["^(@\\w+\\s*)+"]],"date":>date,"username":>username,"url":>url,​​"replyto":>StringCases[text,RegularExpression["@\\w+"]]​​]]&​​];
Example of using function.
In[]:=
tbReplies=twRepliesSQL[twitter,"Username"->"elonmusk",MaxItems->180];

Exploring Elon most recent tweets

Check table structure
In[]:=
tbReplies//​​tableSQLAsDataset
Out[]=
id
text
date
username
url
refs
1597524485074485248
This will forever be our top priority
Tue 29 Nov 2022 10:34:52
elonmusk
https://twitter.com/elonmusk/status/15975244850744...
{@Liz_Wheeler}
1597404771618430976
This is a battle for the future of civilization. If free speech is lost even in America, tyranny is all that lies ahead.
Tue 29 Nov 2022 02:39:10
elonmusk
https://twitter.com/elonmusk/status/15974047716184...
{@SwipeWright}
1597341615865020418
Exactly
Mon 28 Nov 2022 22:28:13
elonmusk
https://twitter.com/elonmusk/status/15973416158650...
{@BillyM2k}
1597337261787709440
Absolutely, especially if done in collusion with the government
Mon 28 Nov 2022 22:10:54
elonmusk
https://twitter.com/elonmusk/status/15973372617877...
{@saylor,@lexfridman}
1597335738655604737
Why are so many in the media against free speech? This is messed up.
Mon 28 Nov 2022 22:04:51
elonmusk
https://twitter.com/elonmusk/status/15973357386556...
{@RubinReport}
1597333438524448768
A revolution against online censorship in America
Mon 28 Nov 2022 21:55:43
elonmusk
https://twitter.com/elonmusk/status/15973334385244...
{@Jason}
1597332117280608256
Support is greatly appreciated!
Mon 28 Nov 2022 21:50:28
elonmusk
https://twitter.com/elonmusk/status/15973321172806...
{@stillgray}
1597326823192694784
🍿
Mon 28 Nov 2022 21:29:26
elonmusk
https://twitter.com/elonmusk/status/15973268231926...
{@micsolana}
1597303084178251777
Wow, they don’t sound biased at all!
Mon 28 Nov 2022 19:55:06
elonmusk
https://twitter.com/elonmusk/status/15973030841782...
{@TheRabbitHole84}
1597298832403939328
Secret suppression of free speech by Apple. Customers were never told. What the hell is going on here?
Mon 28 Nov 2022 19:38:12
elonmusk
https://twitter.com/elonmusk/status/15972988324039...
{@LBRYcom}
rows 1–10 of 160
Performing searches
In[]:=
tbReplies//​​whereSQL[#,StringContainsQ[text,"free speech"]]&//​​tableSQLAsDataset
Out[]=
id
text
date
username
url
replyto
1597404771618430976
This is a battle for the future of civilization. If free speech is lost even in America, tyranny is all that lies ahead.
Tue 29 Nov 2022 02:39:10
elonmusk
https://twitter.com/elonmusk/status/15974047716184...
{@SwipeWright}
1597335738655604737
Why are so many in the media against free speech? This is messed up.
Mon 28 Nov 2022 22:04:51
elonmusk
https://twitter.com/elonmusk/status/15973357386556...
{@RubinReport}
1597298832403939328
Secret suppression of free speech by Apple. Customers were never told. What the hell is going on here?
Mon 28 Nov 2022 19:38:12
elonmusk
https://twitter.com/elonmusk/status/15972988324039...
{@LBRYcom}
1597058841396797440
That American media would argue *against* free speech in America – within the bounds of the law – is an utter travesty.
​
Shame on them! Shame, shame, shame.
Mon 28 Nov 2022 03:44:34
elonmusk
https://twitter.com/elonmusk/status/15970588413967...
{@ggreenwald}
1596323842246545409
It’s insane! I’m just fighting for free speech in America.
Sat 26 Nov 2022 03:03:56
elonmusk
https://twitter.com/elonmusk/status/15963238422465...
{@teslaownersSV,@stillgray}
In[]:=
tbReplies//​​whereSQL#,date<
Fri 25 Nov 2022 10:22:25GMT+1
&//​​tableSQLAsDataset
Out[]=
id
text
date
username
url
replyto
1596065310142259201
All verified individual humans will have same blue check, as boundary of what constitutes “notable” is otherwise too subjective.
​
Individuals can have secondary tiny logo showing they belong to an org if verified as such by that org. ⋱
Fri 25 Nov 2022 09:56:38
elonmusk
https://twitter.com/elonmusk/status/15960653101422...
{@Cryptoking,@RBReich}
1596054261292728322
Incitement to violence will result in account suspension
Fri 25 Nov 2022 09:12:43
elonmusk
https://twitter.com/elonmusk/status/15960542612927...
{@MrAndyNgo,@ramzpaul}
1596053664338440192
Sorry for the delay, we’re tentatively launching Verified on Friday next week.
​
Gold check for companies, grey check for government, blue for individuals (celebrity or not) and all verified accounts will be manually authenticated before check activates. ⋱
Fri 25 Nov 2022 09:10:21
elonmusk
https://twitter.com/elonmusk/status/15960536643384...
{@Cryptoking,@RBReich}
1596050769953886208
Interesting … now pay $8
Fri 25 Nov 2022 08:58:51
elonmusk
https://twitter.com/elonmusk/status/15960507699538...
{@RBReich}
1596024967615123456
Much Ado About Nothing
Fri 25 Nov 2022 07:16:19
elonmusk
https://twitter.com/elonmusk/status/15960249676151...
{@stillgray,@axios}
1595976636088057857
But you have piqued my curiosity … who are these “online experts” you speak of?
Fri 25 Nov 2022 04:04:16
elonmusk
https://twitter.com/elonmusk/status/15959766360880...
{@AP}
1595973736833892356
AP is such an expert in misinformation. Twitter couldn’t hope to compete!
Fri 25 Nov 2022 03:52:45
elonmusk
https://twitter.com/elonmusk/status/15959737368338...
{@AP}
1595959040332517379
Mars plans are still moving forward
Fri 25 Nov 2022 02:54:21
elonmusk
https://twitter.com/elonmusk/status/15959590403325...
{@ThePrashanthCB,@viniciuscfp82}
1595956761160454145
How can it be both illegal and “by the court”? Twitter must abide by the laws of each country or get shut down.
Fri 25 Nov 2022 02:45:17
elonmusk
https://twitter.com/elonmusk/status/15959567611604...
{@viniciuscfp82}
1595953880726020097
🤣🤣
Fri 25 Nov 2022 02:33:51
elonmusk
https://twitter.com/elonmusk/status/15959538807260...
{@PleaseBeGneiss}
rows 1–10 of 78
In[]:=
tbReplies//​​whereSQL[#,ContainsAny[replyto,{"@semaforben"}]]&//​​tableSQLAsDataset
Out[]=
id
text
date
username
url
replyto
1595559226805395457
Good point. Conflicts of interest should be made readily apparent to the reader.
Thu 24 Nov 2022 00:25:38
elonmusk
https://twitter.com/elonmusk/status/15955592268053...
{@RyanZohoury,@WholeMarsBlog,@semaforben}
1595558540109705216
Just wow …
Thu 24 Nov 2022 00:22:54
elonmusk
https://twitter.com/elonmusk/status/15955585401097...
{@sourpatchlyds,@semaforben}
1595558069156532225
They should get a “SBF-Affiliated Media” label 🤣
Thu 24 Nov 2022 00:21:02
elonmusk
https://twitter.com/elonmusk/status/15955580691565...
{@WholeMarsBlog,@semaforben}
1595557676599377920
Yup
Thu 24 Nov 2022 00:19:28
elonmusk
https://twitter.com/elonmusk/status/15955576765993...
{@WholeMarsBlog,@semaforben}
1595554584860102657
🤣
Thu 24 Nov 2022 00:07:11
elonmusk
https://twitter.com/elonmusk/status/15955545848601...
{@nichegamer,@brandonorselli,@semaforben}
1595554537053589505
That’s why he won’t answer
Thu 24 Nov 2022 00:07:00
elonmusk
https://twitter.com/elonmusk/status/15955545370535...
{@nichegamer,@brandonorselli,@semaforben}
1595552639273472001
To be direct, the very real concern here is that you have been pushing a completely false SBF ownership of Twitter narrative while effectively being his paid shill.
Wed 23 Nov 2022 23:59:27
elonmusk
https://twitter.com/elonmusk/status/15955526392734...
{@semaforben}
1595551706749624321
All public holders of Twitter were allowed to roll their stock into Twitter as a private company, but he did not do so. Your reporting made it falsely sound like he did, when in fact he owns 0%.
​
For the last time, how much of you does SBF own? Stop dodging the question.
Wed 23 Nov 2022 23:55:45
elonmusk
https://twitter.com/elonmusk/status/15955517067496...
{@semaforben}
1595509452781850636
On the other @semafor *did* take the SBF money and @semaforben won’t disclose how much SBF owns of them
Wed 23 Nov 2022 21:07:51
elonmusk
https://twitter.com/elonmusk/status/15955094527818...
{@EricNewcomer,@karaswisher,@semafor,@semaforben}
1595500566389497856
No. He may have owned shares in Twitter as a public company, but he certainly does not own shares in Twitter as a private company.
Wed 23 Nov 2022 20:32:32
elonmusk
https://twitter.com/elonmusk/status/15955005663894...
{@David_Ingram,@semaforben,@semafor}
rows 1–10 of 12
Generating a word-cloud based on last tweets.
In[]:=
tbReplies//​​summaryMapSQL[#,{text},(StringRiffle[#]//WordCloud)&]&//​​showTableSQL
Total Rows:1 Elapsed:4.8921
Out[]//TableForm=
text
Get a hourly histogram of tweets count
Count the most replied users .
I have to flatten and unnest “replyto” column as we have a list structure.
For more details on unnestSQL check the documentation SQLOperators paclet https://resources.wolframcloud.com/PacletRepository/resources/DamianCalin/SQLOperators/guide/SQLOperatorsGuide.html

Donations