Skip to content

Instantly share code, notes, and snippets.

@semifor
Created August 31, 2017 19:53
Show Gist options
  • Save semifor/7d88ca39fd3e6d1f2752f2036946eec6 to your computer and use it in GitHub Desktop.
Save semifor/7d88ca39fd3e6d1f2752f2036946eec6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl -d
use 5.22.0;
use Getopt::Long;
use Twitter::API;
use open qw/:std :utf8/;
my @traits = qw/Enchilada/;
my $traits = '';
GetOptions(
'traits=s', \$traits,
) or die "usage...\n";
if ( $traits ) {
@traits = split /,/ => $traits;
}
my %cred = (
consumer_key => $ENV{TWITTER_API_CONSUMER_KEY} // die,
consumer_secret => $ENV{TWITTER_API_CONSUMER_SECRET} // die,
access_token => $ENV{TWITTER_API_ACCESS_TOKEN} // die,
access_token_secret => $ENV{TWITTER_API_ACCESS_TOKEN_SECRET} // die,
);
my $client = Twitter::API->new_with_traits(
@traits ? ( traits => \@traits ): (),
%cred
);
$DB::deep = 1000;
$DB::single = 1;
1;
@semifor
Copy link
Author

semifor commented Aug 31, 2017

Simple REPL I use for ad-hoc Twitter API calls.

Set up the appropriate ENV variables. Run the script, c<enter> to run to the break point on line 30. Then make Twitter API calls. E.g.,

$ twitter-re.pl

Debugger skipping /^(?:Moose|Eval::Closure|Class::MOP)/

See ~/.perldb if you don't like this behavior.


Loading DB routines from perl5db.pl version 1.49
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

DB::DB(/Users/marc/bin/twitter-re.pl:8):
8:	my @traits = qw/Enchilada/;
auto(-1)  DB<1> {{v
  DB<2> c
DB::DB(/Users/marc/bin/twitter-re.pl:32):
32:	1;
auto(-1)  DB<2> v
29
30:	$DB::deep = 1000;
31:	$DB::single = 1;
32==>	1;
  DB<2> $r = $client->user_timeline({ screen_name => 'realDonaldTrump', count => 20 })

  DB<3> x map "$_->{source} - $_->{text}", @$r
0  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @FoxNews: .@KellyannePolls on Harvey recovery: We hope when it comes to basic Hurricane Harvey funding that we can rely upon a nonpartis\x{2026}'
1  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @SecShulkin: Our Mobile Vet Center set up and ready to help #Veterans impacted by #HurricaneHarvey in Corpus Christi. https://t.co/P3qNX\x{2026}'
2  '<a href="https://studio.twitter.com" rel="nofollow">Media Studio</a> - First responders have been doing heroic work. Their courage & devotion has saved countless lives \x{2013} they represent t\x{2026} https://t.co/Va37wntt1g'
3  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @IvankaTrump: We must reform our tax code so that all Americans can succeed in our modern economy & achieve the American Dream! #TaxRefo\x{2026}'
4  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - Texas & Louisiana: We are w/ you today, we are w/ you tomorrow, & we will be w/ you EVERY SINGLE DAY AFTER, to rest\x{2026} https://t.co/9AqR1L3fIQ'
5  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - Will be leaving for Missouri soon for a speech on tax cuts and tax reform - so badly needed!'
6  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - After reading the false reporting and even ferocious anger in some dying magazines, it makes me wonder, WHY? All I want to do is #MAGA!'
7  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - After witnessing first hand the horror & devastation caused by Hurricane Harvey,my heart goes out even more so to the great people of Texas!'
8  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - The U.S. has been talking to North Korea, and paying them extortion money, for 25 years. Talking is not the answer!'
9  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @BrazoriaCounty: https://t.co/sUTyXBzer9'
10  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - .@foxandfriends   We are not looking to fill all of those positions. Don\'t need many of them - reduce size of government. @IngrahamAngle'
11  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - Leaving now for Texas!'
12  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @TheFive: "Trump just won on law & order and now he\'s delivering the goods." -@jessebwatters #thefive'
13  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @TXMilitary: #PhotosFromTheField: Aerial photos from our rescue crews earlier today. #Harvey #TMDHarvey @USNationalGuard https://t.co/fA\x{2026}'
14  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @NWSHouston: Historic flooding is still ongoing across the area. If evacuated, please DO NOT return home until authorities indicate it i\x{2026}'
15  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @GregAbbott_TX: Thanks to the Texas National Guard for their help to rescue flooded Texans. #HurricaneHarvey https://t.co/lhpJtAne10'
16  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @Inspire_Us: No color, no religion, no nationality should come between us, we are all children of God. - Mother Teresa'
17  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @KatiePavlich: Your boss pardoned a traitor who gave U.S. enemies state secrets, he also pardoned a terrorist who killed Americans. Spar\x{2026}'
18  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - RT @DineshDSouza: Finally, as if by accident, the @washingtonpost breaks down & admits the truth about where the violence is coming from ht\x{2026}'
19  '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a> - HISTORIC rainfall in Houston, and all over Texas. Floods are unprecedented, and more rain coming. Spirit of the people is incredible.Thanks!'
  DB<4>

Oh hey! Look at that 3rd tweet. Trump didn't tweet that. Someone on his communications team did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment