Module | FacebookPictures |
In: |
facebook_bot/pictures.rb
|
Handles all Picture related functionality. Mainly, uploading pictures to Facebook and tagging them all nice.
Changes the profile picture given a picture filename. Can only (currently) take JPEGs. It will blow up on anything else.
fb.change_profile_picture 'cute.jpg'
# File facebook_bot/pictures.rb, line 7 7: def change_profile_picture picture 8: login 9: id_info = get_ids_from_url '/editprofile.php?picture', ['id','code'] 10: params = id_info.merge({'type' => 'profile', 11: 'return' =>'editprofile.php?picture', 12: 'agree' => '1', 13: 'uploadbutton' => 'Upload Picture'}) 14: upload_file_to_url picture,'/pic_upload.php', params 15: end
Gets a list of all pictures in an album, given a album URL. Returns a list of image IDs. An example is worth a thousand words:
pictures = fb.get_pictures 'http://www.facebook.com/album.php?profile'
Pictures Array is now something like:
['img_56425733_1813949','img_35978903_1813949',...]
# File facebook_bot/pictures.rb, line 62 62: def get_pictures url 63: login 64: connect URI.parse(url).host 65: doc = hpricot_get_url url 66: 67: pictures = [] 68: doc.search("//div[@id='album']//img") do |img| 69: pictures << img.attributes['id'] 70: end 71: pictures 72: end
Tag a picture of picture_id (found via the get_pictures method, probably) with a subject (FacebookFriend instance of person tagging, or ‘self’ if we‘re tagging ourself.) and at a position [x%,y%] Array, usually found via random.position.
fb.tag_picture get_pictures('http://www.facebook.com/album.php?profile')[0], 'self', [5,5] fb.tag_picture '40009493', 'self', [40.232,23.3434] fb.tag_picture '43253433', '3453453434', [22.232,54.3434] fb.tag_picture '2334534534', fb.get_friends.find{|x| x.name == 'Mark Zuckerberg'}, [54.1,10.2]
# File facebook_bot/pictures.rb, line 34 34: def tag_picture picture_id, friend, position 35: login 36: img_str, pid, id = picture_id.split('_') 37: 38: # if we're tagging self, create a dummy friend to use of myself. 39: if friend == 'self' 40: friend = FacebookFriend.new(id,'myself','') 41: end 42: 43: subject = friend.id 44: 45: post_form_id = get_ids_from_url("/photo.php?pid=#{pid}&id=#{id}", ['post_form_id'])['post_form_id'] 46: 47: req = @http.post2('/ajax/photo_tagging_ajax.php',"pid=#{pid}&id=#{id}&subject=#{subject}&name=disregarded&email=&action=add&x=#{position[0]}&y=#{position[1]}&post_form_id=#{post_form_id}",@opts[:headers]) 48: 49: if req.code.to_i == 200 50: puts "Successfully tagged a photo of #{friend.name} at #{position[0]},#{position[1]}." 51: else 52: puts "Failed to tag a photo of #{friend.name}!" 53: log req 54: end 55: end
Shortcut function to tag your profile picture with subject (FacebookFriend or ‘self’) and Position [x%,y%]. subject can be ‘self’ if you‘re taggging a picture of yourself.
fb.tag_profile_picture 'self', [49.232,23.230] fb.tag_profile_picture '34534522', [49.232,23.230] fb.tag_profile_picture fb.get_friends.find{|x| x.name == 'Mark Zuckerberg'}, [49.232,23.230]
# File facebook_bot/pictures.rb, line 22 22: def tag_profile_picture friend, position 23: login 24: tag_picture get_pictures('http://www.facebook.com/album.php?profile')[0], friend, position 25: end