Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Hacking Friends Photos PyLadies version

By: fmasanori on Sep 29th, 2011  |  syntax: Python  |  size: 1.20 KB  |  views: 2,069  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import urllib.request
  2. import json
  3.  
  4. '''
  5. 0. pyLadies version of Hacking Facebook Photos
  6. 1. Install Python 3.x (batteries included yay)
  7. 2. Log into https://developers.facebook.com/docs/reference/api/
  8. 3. Copy Friends Link with access_token
  9. 4. Run
  10. Obs.: try advanced hacking in this links
  11.   https://github.com/facebook/python-sdk
  12.   https://github.com/facebook/fbconsole
  13.   https://github.com/finiteloop/socialcookbook
  14. '''
  15.  
  16. def get_friends():
  17.   url = 'Copy the friends link here'
  18.   resp = urllib.request.urlopen(url).read()
  19.   data = json.loads(resp.decode('utf-8'))
  20.   return data['data']
  21.  
  22. def picture(id_friend):
  23.   url = 'https://graph.facebook.com/'+ id_friend + '/picture?type=large'
  24.   return urllib.request.urlopen(url).read()
  25.  
  26. def female(id_friend):
  27.   url = 'https://graph.facebook.com/'+ id_friend
  28.   resp = urllib.request.urlopen(url).read()
  29.   data = json.loads(resp.decode('utf-8'))
  30.   if 'gender' not in data: return False
  31.   return data['gender'] == 'female'
  32.  
  33. def download_pics(friends):
  34.   for f in friends:
  35.     if female(f['id']):
  36.       print (f['name'])
  37.       file = open (f['name']+'.jpg', 'wb')
  38.       file.write(picture(f['id']))
  39.       file.close()
  40.  
  41. download_pics(get_friends())