root/misc/blogping

Revision 2061 (checked in by miyagawa, 14 years ago)

add --list command

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use ExtUtils::MakeMaker;
5 use XMLRPC::Lite;
6 use YAML;
7
8 my $conf = "$ENV{HOME}/.blogping";
9
10 my @ping = (
11     'http://ping.feedburner.com/',
12     'http://www.bloglines.com/ping',
13     'http://rpc.technorati.jp/rpc/ping',
14     'http://rpc.reader.livedoor.com/ping',
15     'http://blogsearch.google.com/ping/RPC2',
16 );
17
18 our $changed;
19 our $config = eval { YAML::LoadFile($conf) || {} };
20 setup_default() unless $config->{default};
21
22 if (@ARGV and ($ARGV[0] eq '--list' || $ARGV[0] eq '-l')) {
23     my $default = $config->{default};
24     for my $name (keys %$config) {
25         next if $name eq 'default';
26         my $site = $config->{$name};
27         $name .= '*' if $name eq $default;
28         print $name, " " x (16-length($name)), "$site->{name} ($site->{url})\n";
29     }
30     exit;
31 }
32
33 my $name = $ARGV[0] || $config->{default};
34 my $site = $config->{$name} || setup_site($name);
35
36 for my $ping (@ping) {
37     warn "pinging $ping\n";
38     my $result = XMLRPC::Lite->proxy($ping)->call("weblogUpdates.ping", $site->{name}, $site->{url})->result;
39     warn YAML::Dump $result;
40 }
41
42 END {
43     YAML::DumpFile($conf, $config) if $changed;
44 }
45
46 sub setup_default {
47     warn "Setting up the default site.\n";
48     $config->{default} = my $name = prompt("Short name:");
49     setup_site($name);
50 }
51
52 sub setup_site {
53     my $name = shift;
54     warn "Setting up config for site '$name'\n";
55     my $site;
56     $site->{name} = prompt("Blog name:");
57     $site->{url}  = prompt("Blog url:");
58     $changed++;
59     return $config->{$name} = $site;
60 }
Note: See TracBrowser for help on using the browser.