Skip to content

Instantly share code, notes, and snippets.

@Songmu
Created December 16, 2010 00:31
Show Gist options
  • Save Songmu/742837 to your computer and use it in GitHub Desktop.
Save Songmu/742837 to your computer and use it in GitHub Desktop.
EmEditor macro for get twitter timeline
#language="PerlScript";
our $Window;
my $document = $Window->document;
use strict;
use warnings;
use utf8;
use Data::Dumper;
use YAML::Syck;
use HTTP::Date;
use POSIX qw/strftime/;
use Encode;
our $VERSION = 0.01;
use Net::Twitter;
use Win32::OLE;
Win32::OLE->Option(CP=>Win32::OLE::CP_UTF8);
my $config_file = 'C:\myCom\conf\twitter.conf';
my $config = YAML::Syck::LoadFile($config_file) or die $!;
my $twit = Net::Twitter->new(
traits => [qw/API::REST OAuth WrapError/],
consumer_key => $config->{consumer_key},
consumer_secret => $config->{consumer_secret},
ssl => 1,
);
$twit->access_token ($config->{access_token});
$twit->access_token_secret($config->{access_token_secret});
my $friend = decode_utf8 $document->selection->Text;
$friend =~ s/[\s\r\n]/ /mg;
my $tweets =
!$friend ? $twit->friends_timeline :
$friend eq '@' ? $twit->mentions :
$twit->user_timeline({id => $friend});
$Window->OutputBar->Clear();
$Window->OutputBar->{'Visible'} = 1;
die Dumper($twit) unless ref $tweets eq 'ARRAY';
@$tweets = reverse @$tweets;
for (@$tweets){
# fixup twitter's strange time format so str2time groks
my $created_at = $_->{created_at}; $created_at =~ s/\+0000/GMT/;
my $when = strftime("%H:%M:%S", localtime(str2time($created_at)));
my $text = $_->{text}; $text =~ s/\s/ /g; # \t|\n|\r to spaces.
$Window->OutputBar->writeln(sprintf "%16s[%s] %s", $_->{user}{screen_name}, $when, $text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment