Skip to content

Instantly share code, notes, and snippets.

@nipotan
Created July 15, 2010 07:01
Show Gist options
  • Save nipotan/476606 to your computer and use it in GitHub Desktop.
Save nipotan/476606 to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use WWW::Mechanize;
use Config::Pit;
use URI;
my $loctouch_id;
while (my $line = <STDIN>) {
if ($line =~ m{^http://(?:[^.]+\.)?tou\.ch/member/([^/]+)/}m) {
$loctouch_id = $1;
last;
}
}
exit 0 unless defined $loctouch_id;
auto_follow($loctouch_id);
exit 0;
sub auto_follow {
my @ids = @_; # XXX test
my $mech = WWW::Mechanize->new(agent => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7');
$mech->get('http://loc.tou.ch/');
unless (logged_in($mech->uri)) {
$mech->get('http://loc.tou.ch/auth/login');
my $config = pit_get('livedoor.com', require => {
livedoor_id => 'Your livedoor ID',
password => 'Your Password',
});
$mech->submit_form(
form_id => 'home',
fields => {
livedoor_id => $config->{livedoor_id},
password => $config->{password},
},
);
die "login failed.\n" unless logged_in($mech->uri);
}
for my $loctouch_id (@ids) {
my $member_url = sprintf 'http://loc.tou.ch/member/%s/', $loctouch_id;
$mech->get($member_url);
my($json) = $mech->content =~ /^Folkat\.page_owner\s*=\s*\{(.+?)\};$/m;
return unless $json;
my($id) = $json =~ m{"id":"(\d+)"};
return unless $id;
my $form_id = sprintf 'follow_%d', $id;
# XXX mechanize hack
$mech->form_id($form_id);
my $current_form = $WWW::Mechanize::VERSION >= 1.64 ?
$mech->{current_form} : $mech->{form};
$current_form->action(URI->new('http://loc.tou.ch/api/member/follow'));
my $res = $mech->submit_form(form_id => $form_id, fields => {});
}
}
sub logged_in {
my $url = shift;
return $url eq 'http://loc.tou.ch/home/#map/';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment