Skip to content

Instantly share code, notes, and snippets.

@cagerton
Created April 23, 2010 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cagerton/377301 to your computer and use it in GitHub Desktop.
Save cagerton/377301 to your computer and use it in GitHub Desktop.
# Steps to monitor who removes you from their friends list on facebook:
# Grab the new Facebook Python-SDK from github.
# Modify & run the appengine+oauth example/demo as follows:
# -in facebookoauth.py define _parse_json & _dump_json
# -in user add two db.TextProperty fields: friends, unfriends
# -swap the HomeHandler class for below...
# -update template to display as desired.
# run & reload every few days and see who doesn't like you anymore.
class HomeHandler(BaseHandler):
def get(self):
unfriends = []
friends = []
friend_count = 0
user = self.current_user
if user:
# grab current friends
friends_d = json.load(urllib.urlopen(
"https://graph.facebook.com/me/friends?" +
urllib.urlencode(dict(access_token=user.access_token))))
friends = friends_d['data']
friend_count = len(friends)
friend_ids = set([u['id'] for u in friends])
# load current data.
oldfriends = _parse_json(user.friends)
oldfriend_ids = set([u['id'] for u in oldfriends])
unfriends = _parse_json(user.unfriends)
unfriend_ids = set([u['id'] for u in unfriends])
# find missing friends
u_new = set()
for u in oldfriend_ids - friend_ids:
if not u in unfriend_ids: # again, really?
u_new.add(u)
# put missing friends into unfriend list
for u in oldfriends:
if u['id'] in u_new:
unfriends.append(u)
user.friends = _dump_json(friends)
user.unfriends = _dump_json(unfriends)
user.put()
path = os.path.join(os.path.dirname(__file__), "oauth.html")
args = {'current_user':self.current_user,
'unfriends':unfriends,
'friends':friends,
'friend_count':friend_count,
}
self.response.out.write(template.render(path, args))
{% if unfriends %}
<p>Look who doesn't like you:
<ul>
{% for u in unfriends %}
<li><img src="http://graph.facebook.com/{{ u.id }}/picture"/>{{u.name}}</li>
{%endfor%}
</ul>
</p>
{%endif%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment