Showing posts with label facebook. Show all posts
Showing posts with label facebook. Show all posts

Jun 12, 2010

Bulk responding to facebook wallposts

So it happens that my birthday is coming up, and like last year there's bound to be a shitload of posts on my Facebook wall...and like last time I'm probably expected to respond to said posts otherwise I'd be "rude".

Here's the dilema though, I can't be bothered to spend all the time going through the wall, clicking on links..responding blah blah. What I'd like to do, is respond to all of them in bulk. So here's my solution...

1.download all wallposts to a csv file
2.edit said csv file and add responses to those posts that i want to respond to
3.send off said responses.

How-to after the jump

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\"");

Jun 29, 2009

Automatic birthday wishes on facebook

here we go yet again...another update. This time, aimed at trying to make the whole thing less complicated for people, and also remove the whole linux limitation thing as opposed to the older version that I put up three months ago. The response to this has been quite positive...

presenting... keyku 

This new version has been setup as a facebook application and not a hack, so it's more elegant this time, and errr.... a bit more...legal let's say (the old version violated the facebook terms of use a little...this one does not)

setup instructions can be found on the application page

feel free to drop in there and tinker around, suggest features, flame the discussion board etc :P

have fun.

once again, thanks to Dave Tompkins for his help.

May 26, 2009

Upload photos to facebook from Nautilus

EDIT:
~UPDATED 15-07-2010
Added ability to create album.
Photo's will be auto-rotated if EXIF information is available.
12-JUN-2010
reworked the mechanism to work with the new FBCMD.
Does not need a manual update of albumdata file (will be handled on it's own.)

If you run this on a directory, it will upload all *.jpg files in said directory.

30-MAY-09

Fixed stupid bug where the cancelling uploaded the picture anyway.Thank you Mr. Anonymous bug reporter.

It's been a while since I've posted an update, not that I suspect that anybody missed me or anything. Nonetheless I'm throwing out an obligatory apology and the explaination for it being "been busy"

anyway this is something I whipped up today that somebody might find useful. It's a nautilus script that uploads your photos to facebook. So you can just right-click on a photo and upload it there.It's fairly basic (offers multiple uploads,album-selection, no-tagging,no caption), and once again it's not completely idiot proof so I'm not taking responsibility if you muck something up.

currently this depends on the following
  • libnotify (particularly notify-send)
  • zenity
  • imagemagick
  • fbcmd (and hence php)
fbcmd here being the facebook command-line application by Dave Tompkins, which can be found at http://fbcmd.dtompkins.com. So once you have that up and running and properly authorized (find instructions on fbcmd page)

The script needs to go into ~/.gnome2/nautilus-scripts


Next you should setup an albumid file because it's faster if you maintain a local list). Do this by running

php fbcmd.php albums | tee ~/.fbaids

if you'd rather fetch album information from facebook everytime you can replace the line "aidlist=~/.fbaids" with "aidlist=\"$(php FBCMDPATH albums)\""
that should do it.


please note that I haven't implemented a check on weather the upload was successful or not. Also there is no filetype check so be careful.

#!/bin/bash
# AUTHOR: (c) Naail Abdul Rahman (http://kudanai.blogspot.com)
# VERSION: 1.0
# LICENSE: GPL (http://www.gnu.org/licenses/gpl.html)
# REQUIRES: libnotify, zenity, FBCMD (http://fbcmd.dtompkins.com),imagemagick
# NAME:  Upload to Facebook
# DESCRIPTION: Simple nautilus script to invoke FBCMD upload functionality.
#  Currently only supports pictures.Hope to adding notes as well.
#  FBCMD is a command line interface to facebook by Dave Tompkins
 
fbcmdl=fbcmd #command to invoke fbcmd...usually just fbcmd
 
function notify() {
 notify-send -i fbnotif UPLOADING "$@"
}
 
function makealbum() {
 title=$(zenity --entry --title="Title?" --text="Enter Album Title (Required):")
 if [ -z $title ]
 then
  getaid
 fi
 
 desc=$(zenity --entry --title="Description?" \
  --text="Enter a description for the album (optional):\nLeave blank if you don't want to set a descroption")
 location=$(zenity --entry --title="Location?" \
  --text="Enter a location for the album (optional):\nLeave blank if you don't want to set a location")
 privacyOpt=$(zenity --entry --title="Privacy?" \
  --text="Who can see this album? (default:everyone)\n1.friends\n2.friends-of-friends\n3.networks\n4.everyone")
 
  case $privacyOpt in
   1) privacy="friends"
    ;;
   2) privacy="friends-of-friends"
    ;;
   3) privacy="networks"
    ;;
   4) privacy="everyone"
    ;;
   *) privacy="everyone"
    ;;
  esac
 notify "creating album $title"
 $fbcmdl addalbum "${title}" "${desc}" "${location}" $privacy
}
 
function getaid() {
 
 aid=$(zenity --entry --title="Album?" \
   --text="Enter AlbumID or #\n\nenter:\n  0 for list\n  l (low L) for latest\n a for new")
  
 if [ -z $aid ];
 then
  echo "null value for aid - quiting"
  notify "upload cancelled"
  exit
 else
  case $aid in
   0) echo "please wait, fetching album data"
    $fbcmdl albums | zenity --text-info \
       --title "album names and stuff" --width=600
    getaid
    ;;
   l) aid="latest"
    ;;
   a) makealbum
    echo "created album.."
    aid="latest"
    ;;
  esac
 fi
}
 
getaid
notify "uploading photos"
  
for arg
do
 if [ -f $arg ]
 then
  echo "adding regular file ${arg}"
  convert -auto-orient -resize '604>' "$arg" /tmp/fbuplpictmpxx.jpg
  $fbcmdl addpic /tmp/fbuplpictmpxx.jpg $aid
 elif [ -d $arg ]
 then
  echo "uploading directory ${arg}"
  $fbcmdl addpicd $arg $aid
 fi
done
 
notify "upload finished"
exit

Mar 23, 2009

Let's get poking - (facebook poke with bash / perl)

facebook, bash, curl, poke..poking... that about covers it. This is neither elegant nor complete. Call it a "hack" if you will. Please keep in mind that facebook does not look favourably on browser side scripting so this is technically against their TOS. Having said that, unless you go all spammy on your friends, you should remain under the radar. As far as requests go, they'll think you're doing it manually..which is ok... (unless like I said you over do it..)

copy code below to new file
chmod it +x
the script take three args - email,password and UID of the person you wanna poke.
it will try to reuse any cookies left over from a previous session so if you have problems, delete the cookie file /tmp/email.fbcookie

have fun. don't spam!

update
This here is a new modified version running on Perl. working as of 26/03/2010
#!/usr/bin/perl
#---------------------------- #
# facebook poke script        #
# c2010 - KudaNai             #
# http://kudanai.blogspot.com #
# --------------------------- #
# use with caution.you may    #
# get banned for violation    #
# of facebook ToS.            #
# good luck.                  #
# --------------------------- #
use strict;
use WWW::Mechanize;
use HTTP::Cookies;

my $username = 'yourusername'; #change these values.
my $password = 'yourpassowrd';

die "invalid number of arguments" unless (scalar @ARGV)==1;

my $mech = WWW::Mechanize->new();$mech->cookie_jar(HTTP::Cookies->new());
$mech->get("http://www.facebook.com/login.php");
$mech->submit_form(
form_number => 1,
fields =>
{
email=>$username,
pass=>$password
}
);

$mech->content() =~ /post_form_id\"\svalue=\"(\w+)\"/;

foreach my $uid (@ARGV)
{
$mech->post("http://www.facebook.com/ajax/poke.php?__a=1",
{
uid=>$uid,
pokeback=>"1",
post_form_id=>$1,
post_form_id_source=>"AsyncRequest"
}
);
#print $mech->content();
}


and the old version for reference.

#!/bin/bash

email=$1
pass=$2
uid=$3

cookie="/tmp/${email}.fbcookie"


login()
{
echo "logging in..."
curl -L --silent -A "MOZILLA/5.0" -b ${cookie} -c ${cookie} \
-d "email=${email}" -d "pass=${pass}" -d "login=Log+In" \
http://m.facebook.com/login.php > /dev/null
}

poke()
{
gfid=`curl -L --silent -A "MOZILLA/5.0" -b ${cookie} -c ${cookie} \
"http://m.facebook.com/profile.php?id=${uid}" | \
awk '{FS="gfid=";RS="\">";if (NR!=1 && $2!~/^$/) {print $2}}'`


curl --silent -G -A "MOZILLA/5.0" -b ${cookie} -c ${cookie} \
-d "id=${uid}" -d "gfid=${gfid}" -d "poke=${uid}" -d "refid=17" \
"http://m.facebook.com/a/profile.php" > /dev/null
}

if [ ! -e "${cookie}" ];then login;fi
poke

Mar 6, 2009

Automatic Birthday Wishes on Facebook

EDIT: 29/06/2009 - a new, better and more elegant version has been released. I encourage users to switch over to that one.
Announcement is HERE

Well here we are again. Update time! :|

A few months ago I put together a little script that would automatically write on the walls of any of your friends of Facebook (limited to privacy settings of said individuals of course). The script was/is largely based on the Command line application by Dave Tompkins.

as of the most recent update, my script is no longer compatible with the new version. So a few changes were in order. So here it is.

unlike the previous version, you don't need to patch anything. Just a vanilla install of fbcmd + this script and that's it.

download script from HERE


Installation:

1.Download and install fbcmd, follow instructions from HERE
2.Download my script, and put it anywhere you want.
3.Edit the email,password fields in the script: and locations of the fbcmd files
4.Run it manually, or setup a cron job for it.

the setup should be fairly straightforward. Please note that the wall post procedure is not officially supported by facebook, and may break from time to time (because facebook may change their page structure). Please report any bugs ASAP and I'll will try to have them fixed as soon as I can.

have fun!

Nov 21, 2008

Automate birthday wishes on facebook

NEW VERSION IS OUT, and is now compatible with the latest (v0.95) version of fbcmd. You can find it HERE

EDIT 3: 02/DEC/08 - Fixed birthday issue for single digit days. Damn paddings...

EDIT 2: 23/NOV/08 - Fixed the incorrect date matching problem. You should update before the 2nd of December or you'll be in trouble.

EDIT: I fixed one serious error in the code, and updated the how to and made it..simpler.


let's face it, no matter how much you try you will always forget somebody's birthday and end up in a hole. I've been " " this close to death on several occasions now, and I'm actually reputed for having a good grip of the whole birthday business.

so last night I wanted to kill some time and I came up with a little bash script that might be of help to some of you. Basically what it does is

  1. Go online and grab the user ID's of everybody who's birthday falls on "today" (make sure your system clock is setup properly)
  2. Write a message on their wall

This is setup to run once a day, and voila! you have yourself a free ticket out of...birthday forgetters hell... *cough*

Should be fairly straightforward on any *nix system.

We'll be needing some way to access information on facebook. For that we're going to use fbcmd which is, as the developer describes "a simple command line interface for facebook." Go to the projects website here and download the latest version. At the time of writing, this was 0.90 (BETA)

Note that the patch file provided is for this particular version. I will update it if necessary in the future.

extract the archive to your home directory (places->home).
now download the patch file and script from here and also extract it to ~/fbcmd (directory should already exist from the previous archive)

Now go to the facebook application page, HERE and allow the application to access your information, and click "generate" to get an AUTH CODE for your account. Copy this down

open up a terminal now and run the following commands, one at a time.
sudo apt-get install curl php5-cli gnome-schedule
cd ~/fbcmd
patch -b -i fbcmd.diff fbcmd.php
php fbcmd.php AUTH XXXXXX
where XXXXXX is the AUTH CODE you copied down earlier. Now you should have access to your account through the application. Now we can move on to the wish script. In the same terminal type out the following.
php fbcmd.php FRIENDSC > fbUIDlist
gedit fbbdaywish
when the editor pops up, change the values for email, pass and put in your email ad and password. Change the value of "post" to whatever you want your friend to be greeted with. (TIP: avoid !'s, it causes some problems)

now type
gnome-schedule
The scheduled tasks dialog should come up. Click on new->recurrent. Enter any description you like. In the command field type
~/fbcmd/fbbdaywish >> ~/fbcmd/bday.log
uncheck the "no output" option, and select "every day" from the drop down menu. Click ok, and you're set to go!

Let me know how it turns out.

Oct 11, 2008

Scraping facebook email addresses

Last night I had a dilema - I came to realize that I don't even have a fraction of my friends email addresses in my contact book, which is a very bad thing by any means. Of course there's facebook for ya! but it's still no substitute for some good ol' emails.

So I thought maybe I could simply get them off of facebook - no go!

why? Facebook doesn't provide plain-text email adds, which presents a bit of a problem. After a little research, it became clear that FB uses one of those string-to-image scripts. Hah! easy I thought, I'll just decode the Base64 string and voila... as it happens it's not that easy. It's not a Base64 string and to be honest I couldn't figure out what it was. So that left me with the other option - OCR

This didn't prove too difficult at all. For the most part all I had to do was go through all my friends profile pages, extract the string_image hash, and pass that to

http://m.facebook.com/string_image.php?ct=XXXXXXX&fp=8.7&state=0

where ct takes the has, and fp is a float that controls the size of the output image. 8.7 is standard. you can crank that up to improve the OCR detection rate. I found 35 to be the optimal value between size and clarity.

based on this, i was able to whip up a quick bash script to take in a list of User-ID's (just a bunch of numbers that corrospond to a given user. Do what you will to grab that), grab the email image and use OCR on it. I used OCRAD to do the OCR, and imagemagick for convertion.

EDIT: It saddens me that some people have been making money off the code that I wrote. I helped you guys out in good faith. Really sucks that you took advantage of it. Anyway, I've decided to re-post the code here so the lamesters can be exposed for what they are. I'm posting the rewritten perl code here, since the original bash thing didn't work anyway.

NOTE: I have made some deliberate omissions here. modifications are needed before the code will be functional. you WILL GET BANNED by facebook if you overdo it.

here's the bash stuff:

BOING BOING!!! where did the code go? SOrry guys, I had to remove it.

and in perl: (the xxxx's should be easy to figure out if you see my other scripts)

#!/usr/bin/perl
use strict;
use xxxxx;
use xxxxx;
use Image::Magick;
use Shell qw[ocrad];

my $username = @ARGV[0];
my $password = @ARGV[1];
my $iurl;#temp var
my $id;  #temp var
my $x;   #temp var
my $uids="uids"; #path of uid list file
my $idlist="idlist"; #path of output file
my $size=35;  #size of email image to download

my $mech = xxxxxxx->new();
my $image = Image::Magick->new();

$mech->cookie_jar(xxxxxxxxx->new());

#login
$mech->post("https://login.facebook.com/login.php?m&next=http://m.facebook.com/inbox",{email=>$username,pass=>$password});

#star processing uids
open(UIDS,$uids);
open(IDLS,">>$idlist");
foreach $id ()
{
  chomp($id);
  $mech->get("http://m.facebook.com/profile.php?id=".$id."&v=info&refid=17");
  if(defined ($iurl=$mech->find_image( url_regex => qr/string_image.php/ )))
  {
    ($iurl=$iurl->url_abs())=~s/8.7/$size/;
    chomp($iurl);
    $x = $image->Read($iurl);
    $x = $image->Write(gamma=>0.3,colorspace=>'rgb',filename=>$id.".ppm");
    print IDLS "$id,".ocrad("$id.ppm")."\n";
    @$image = ();

   }
   else 
   {
    print IDLS "$id,undefined\n";
  }
}

close(UIDS);close(IDLS);

This works remarkably well for the most part, although ocrad did confuse some 1's for l's. I had better results with tesseract - but had to convert all the images to bi-tonal graymaps first. otherwise it's simply useless.

Sep 16, 2008

Update Facebook status through Bash, using cURL

anger management part 2 peeps!

A nice simple bash script to update the status on facebook from the command line. Pretty straight forward, using cURL here again. As usual, edit the email and passord. Script takes one argument, the status. There's no error-checking so there really isn't a way to know if it was successful or not. I'll add that in sometime later.

I love cURL!

edit: some installation instructions for the younger peeps
1) copy past it into a new file on the desktop say fbupdater
2) open terminal, type "sudo cp /Desktop/fbupdater /usr/local/bin/fbupdater"
3) type "chmod a+x /usr/local/bin/fbupdater"



and that should do it.


#!/bin/bash


email=YOUR-EMAIL
pass=YOUR-PASSWORD

stat=$1

cd $HOME

echo "logging in"

pfID=`curl -L --silent -A "MOZILLA/5.0" -b cookie -c cookie -d "email=${email}" \
-d "pass=${pass}" -d "login=Log+In" http://m.facebook.com/login.php | \
sed -nr 's/.*post_form_id" value="(\w+)".*/\1/p'`

echo "updating"
curl --silent -L -A "MOZILLA/5.0" -b cookie -c cookie -d "post_form_id=${pfID}" \
-d "status=${stat}" -d "update=Update" http://m.facebook.com/home.php > /dev/null

if [ -e cookie ]
then
rm cookie
else
echo "no cookie file? something went wrong?"
fi