Advertisement
fmasanori

Hacking Friends Photos PyLadies version

Sep 29th, 2011
3,473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  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())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement