Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts

Nov 18, 2009

Replying to Facebook mail on command line

this is a little helper script that I wrote to use in conjunction with FBCMD to reply to inbox messages directly on the command line without going to the website.

It takes two args, the message number (as given out by fbcmd inbox) and the message itself. pretty straightforward. Just throwing it out there.

it's meant to be used with fbcmd, but if you like you can provide a thread_id to it as well (slight mod might be needed)



#!/usr/bin/perl

use strict;
use WWW::Mechanize;
use HTTP::Cookies;

my $username = 'youremail';
my $password = 'yourpass';
my $maildata = "/home/youruser/.fbcmd/maildata.txt";

my $msgid=`php -r \"\\\$ld=unserialize(file_get_contents('$maildata'));print \\\$ld['ids'][$ARGV[0]];\"`;

my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());

$mech->get("http://lite.facebook.com/login/");
$mech->submit_form(form_number => 1,fields =>{email=>$username,password=>$password});

$mech->content() =~ /\/w\/(\w+)\/logout/;
$mech->post("http://lite.facebook.com/w/".$1."/inbox/reply/".$msgid."/",{message=>$ARGV[1],__async__=>'true'});

Jul 16, 2009

Facebook inbox count for conky/others

YAFS again! I'll just throw this out there.

small perl (c-ish again I guess) script to get number of unread messages in facebook. for use with conky etc... supply username and pass as args.


#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use HTTP::Cookies;

my $username = @ARGV[0];
my $password = @ARGV[1];

my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->post("https://login.facebook.com/login.php?m&next=http://m.facebook.com/inbox",{email=>$username,pass=>$password});
$mech->content() =~ /Inbox\s\((\d+)\)/;

print $1?("$1 New Message".($1>1?"s\n":"\n")):"0 New Messages\n";

Jul 12, 2009

Uploading photos to Facebook groups with Perl

here we go again, YAFS (yet another facebook script)

a little different this time since it's in Perl, which is new to me. This script takes a list of file names as arguments, and uploads them to a specified group on facebook. It uses WWW::Mechanize (which is awesome) to do the heavy lifting, and also depends on imagemagick (to resize images)

do note however that this was NOT written to be platform independent so windows users might encounter some problemns. However it should be fixable with a little modification.

USAGE

you'll need to edit the lines for your user-name and password.

perl gup.pl GID [file1] [file2] ...
where GID is the concerned groupID. You need to be a member of the group, and should have upload rights to its photo album.

#!/usr/bin/perl
# -----------------------------------------------
# Script to upload photos to a Facebook group.
# 2009 - kudanai, http://kudanai.blogspot.com
#
# This script can act as a nautilus extension.
# (preset GID and set $i=0 on line 59)
#
# This program is distributed in the hope that
# it will be useful,but WITHOUT ANY WARRANTY;
# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.
# -----------------------------------------------

use strict;
use WWW::Mechanize;
use HTTP::Cookies;

#edit your username, password and group_id here
#these values MUST BE CORRECT for the script
#to work properly
my $username = 'username@example.com';
my $password = 'password';
my $gid = $ARGV[0];

#-----no need to edit beyond this point-----

#url for login page + redirect instruction
my $url = "https://login.facebook.com/login.php?" .
"&next=http%3A%2F%2Fwww.facebook.com%2Feditalbum.php%3Foid%3D".
$gid."%26add%3D1%26htmlup%3D1";

#initialize objects
my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());

#notify
#system("notify-send -i fbnotif UPLOADING \"Logging in\"");

$mech->get($url);
$mech->submit_form(
form_number => 1,
fields =>{
email=>$username,
pass=>$password
},
button=>'login'
);

#notify - if you have libnotify installed, uncomment
#these notify commands to get progress notifications
#system("notify-send -i fbnotif UPLOADING \"Uploading photos\"");


#loop through args and post the files
#five at a time.

my $i=1;
while(defined $ARGV[$i])
{

$mech->form_name('upload');
for(my $j=1;$j<6;$j++,$i++)
{
if(defined $ARGV[$i])
{
system("convert -resize 604 \"".$ARGV[$i]."\" /tmp/".$j.".fgup.jpg");
$mech->field("file$j"=>"/tmp/$j.fgup.jpg");
}   
}
$mech->tick('agree','1');
$mech->submit();
if(defined $ARGV[$i]) {
$mech->back()
}
}

#remove temporary images
system( "find /tmp -name '*.fgup.jpg' -exec rm {} \\;>/dev/null" );

#notify
#system("notify-send -i fbnotif UPLOADING \"Finished Uploads\"");