Changeset 2059

Show
Ignore:
Timestamp:
10/29/06 02:34:14
Author:
miyagawa
Message:

update blogping to use YAML config file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • misc/blogping

    r2028 r2059  
    22use strict; 
    33use warnings; 
     4use ExtUtils::MakeMaker; 
    45use XMLRPC::Lite; 
    56use YAML; 
     7 
     8my $conf = "$ENV{HOME}/.blogping"; 
    69 
    710my @ping = ( 
     
    1316); 
    1417 
    15 my $blog_url  = shift || "http://blog.bulknews.net/mt/"; 
    16 my $blog_name = shift || "blog.bulknews.net"; 
     18our $changed; 
     19our $config = eval { YAML::LoadFile($conf) || {} }; 
     20setup_default() unless $config->{default}; 
     21 
     22my $name = $ARGV[0] || $config->{default}; 
     23my $site = $config->{$name} || setup_site($name); 
     24 
     25use XXX; 
     26XXX $site; 
    1727 
    1828for my $ping (@ping) { 
    1929    warn "pinging $ping\n"; 
    20     my $result = XMLRPC::Lite->proxy($ping)->call("weblogUpdates.ping", $blog_name, $blog_url)->result; 
     30    my $result = XMLRPC::Lite->proxy($ping)->call("weblogUpdates.ping", $site->{name}, $site->{url})->result; 
    2131    warn YAML::Dump $result; 
    2232} 
     33 
     34END { 
     35    YAML::DumpFile($conf, $config) if $changed; 
     36} 
     37 
     38sub setup_default { 
     39    warn "Setting up the default site.\n"; 
     40    $config->{default} = my $name = prompt("Short name:"); 
     41    setup_site($name); 
     42} 
     43 
     44sub setup_site { 
     45    my $name = shift; 
     46    warn "Setting up config for site '$name'\n"; 
     47    my $site; 
     48    $site->{name} = prompt("Blog name:"); 
     49    $site->{url}  = prompt("Blog url:"); 
     50    $changed++; 
     51    return $config->{$name} = $site; 
     52}