projects
/
lab.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
* pack usage message to $help = sub {...}
[lab.git]
/
Dev
/
twitter
/
dump_timeline.pl
diff --git
a/Dev/twitter/dump_timeline.pl
b/Dev/twitter/dump_timeline.pl
index
246a1d4
..
8216287
100755
(executable)
--- a/
Dev/twitter/dump_timeline.pl
+++ b/
Dev/twitter/dump_timeline.pl
@@
-15,7
+15,7
@@
use YAML::Tiny;
use Data::Dumper;
use Encode;
use Data::Dumper;
use Encode;
-if ($ARGV[0] && ($ARGV[0] eq '--help' || $ARGV[0] eq '-h') ) {
+my $help = sub {
die <<EOM;
usage: $0
[user_timeline(default)|retweeted_by_me|mentions
die <<EOM;
usage: $0
[user_timeline(default)|retweeted_by_me|mentions
@@
-26,7
+26,11
@@
usage: $0
]
]
EOM
]
]
EOM
+};
+if ($ARGV[0] && ($ARGV[0] eq '--help' || $ARGV[0] eq '-h') ) {
+ &{$help};
}
}
+
my $method = $ARGV[0] || 'user_timeline';
my $screen_name = $ARGV[1] || '';
my $pages = $ARGV[2] || 1;
my $method = $ARGV[0] || 'user_timeline';
my $screen_name = $ARGV[1] || '';
my $pages = $ARGV[2] || 1;
@@
-37,12
+41,12
@@
my $dump = $ARGV[3] || 0;
my $conf = loadconf("$Bin/config.yml");
if (! defined $conf) {
my $conf = loadconf("$Bin/config.yml");
if (! defined $conf) {
- die "$0: cannot parse config file.\n";
+ die "$0: cannot parse config file.";
}
my $bot = login($conf);
if (! $bot->authorized) {
}
my $bot = login($conf);
if (! $bot->authorized) {
- die "$0: this client is not yet authorized.\n";
+ die "$0: this client is not yet authorized.";
}
}
@@
-67,7
+71,8
@@
eval {
$res = $bot->mentions($param);
}
else {
$res = $bot->mentions($param);
}
else {
- die "$0: unknown method => $method\n";
+ warn "$0: unknown method '$method'";
+ &{$help};
}
if ($dump) {
}
if ($dump) {
@@
-92,7
+97,6
@@
eval {
if ($@) {
evalrescue($@);
}
if ($@) {
evalrescue($@);
}
-print "done\n";
sub loadconf {
sub loadconf {
@@
-105,7
+109,7
@@
sub loadconf {
my $yaml = YAML::Tiny->read($file);
if ($!) {
my $yaml = YAML::Tiny->read($file);
if ($!) {
- warn "$0: '$file' $!\n";
+ warn "$0: '$file' $!";
}
return $yaml->[0];
}
return $yaml->[0];