/
fetch_tweet.pl
executable file
·54 lines (37 loc) · 1.16 KB
/
fetch_tweet.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env perl
# -*-cperl-*-
# usage: fetch_tweet.pl -c /yer/ini.cfg -o tw.html -u http://twitter.com/you/status/9999999
use strict;
use Getopt::Std;
use Config::Simple;
use WWW::Mechanize;
use IO::AtomicFile;
{
&main();
exit;
}
sub main {
my %opts = ();
getopts('c:o:u:', \%opts);
my $cfg = Config::Simple->new($opts{'c'});
#
my $m = WWW::Mechanize->new();
$m->get("http://www.twitter.com");
my %login = ("session[username_or_email]" => $cfg->param("twitter.username"),
"session[password]" => $cfg->param("twitter.password"));
$m->submit_form(
form_number => 1,
fields => \%login,
button => ""
);
my $r = $m->get($opts{'u'});
if (! $r->is_success()){
warn "failed to retrieve $opts{'u'} with error code: ". $r->code();
return 0;
}
my $fh = IO::AtomicFile->open($opts{'o'}, "w");
binmode $fh, ":utf8";
$fh->print($r->decoded_content());
$fh->close();
return 1;
}