#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::Adjuster;
use Tk::HList;
use Tk::ROText;
use LWP::UserAgent ();
use HTTP::Request::Common;
#Add username and password here to autologin
my $email = '';
my $password = '';
my $main = Tk::MainWindow->new;
my $selector = $main->HList(-columns => 6);
my $display = $main->ROText();
my $progress = $main->ProgressBar();
my %rowstyles = ();
my %meetupurls = ();
$selector->pack(-expand => 1, -fill => 'both');
$display->pack(-expand => 1, -fill => 'both');
$progress->pack(-fill => 'both');
my $web = 0;
sub simplify {
my $string = shift;
defined($string) or $string = "";
$string =~ s/&/&/;
$string =~ s/'/'/;
return $string;
}
my $email_entry = $display->Entry(-width => 30);
my $password_entry = $display->Entry(-show => '*', -width => 30);
$email_entry->insert(0, $email);
$password_entry->insert(0, $password);
my $login = sub {
$web = LWP::UserAgent->new();
$web->cookie_jar ( {} );
$web->get("http://www.meetup.com/login/"); #convince meetup we accept
#cookies
my $email = $email_entry->get;
my $password = $password_entry->get();
$web->post("http://www.meetup.com/login/",
[ email => $email,
password => $password ]);
my $res =
$web->request(HTTP::Request->new('GET',
'http://www.meetup.com/?sortBy=date'));
if ($res->is_error)
{
print "error fetching list of meetups\n";
return;
}
my $page = $res->content;
my @rows = ($page =~ m|
(.*?)
|sg);
my $rownum = 0;
foreach my $row (@rows)
{
my ($name, $date, $url) =
($row =~ m|href=[^>]*>([^<]*)ItemStyle('text');
$meetupurls{$name} = $url;
#what if we already have an item in selector with $name?
$selector->add($name, -at => $rownum, -itemtype=> 'text', -text=> $name,
-style => $rowstyles{$name} );
$selector->itemCreate($name, 1, -itemtype => 'text', -text => $date,
-style => $rowstyles{$name} );
$display->delete ('0.0', 'end');
$rownum++;
}
};
my $switcher = sub {
print " in switcher\n";
# This doesn't work as expected
# $main->Busy(-recurse => 1);
$progress->value(20);
my $name = shift;
$display->delete ('0.0', 'end');
$display->insert ('end', "$name");
$display->insert ('end', "\n");
my $rowurl = $meetupurls{$name};
print "Doing request...";
my $res = $web->request(HTTP::Request->new('GET', $rowurl));
print "done\n";
if ($res->is_error)
{
print "error fetching info1 for $name\n";
return;
}
my $page = $res->content;
my ($members, $yes, $maybe, $no) =
($page =~ />(\d*)\s*Member.*
>(\d*)\s*RSVPed:.Yes.*
>(\d*)\s*RSVPed:.Maybe.*
>(\d*)\s*RSVPed:.No/sx
);
$selector->itemCreate($name, 2, -itemtype => 'text',
-text => "$members members");
$selector->itemCreate($name, 3, -itemtype => 'text',
-text => "Y${yes}");
$selector->itemCreate($name, 4, -itemtype => 'text',
-text => "M$maybe");
$selector->itemCreate($name, 5, -itemtype => 'text',
-text => "N$no");
$progress->value(100);
$main->Unbusy(-recurse => 1);
};
$display->insert ('end', "Email:\n");
$display->windowCreate('end', '-window' => $email_entry);
$display->insert ('end', "\nPassword:\n");
$display->windowCreate('end', '-window' => $password_entry);
$display->insert ('end', "\n");
my $login_button = $display->Button(-text => 'Login',
-command => $login);
$display->windowCreate('end', '-window' => $login_button);
$selector->configure(-command => $switcher);
MainLoop;