Created
February 18, 2013 19:38
-
-
Save kylestev/4979997 to your computer and use it in GitHub Desktop.
Checks your Facebook friends and records the people that have removed you as a friend since the last check. Technically this is against the API's Terms of Service, so let's just call this a proof of concept.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import json | |
| def fbquery(token, query): | |
| from urllib import urlencode | |
| from urllib2 import urlopen | |
| from re import sub | |
| query = sub('\ {2,}', ' ', query) | |
| url = 'https://api.facebook.com/method/fql.query?' + urlencode({'query': query, 'access_token': token, 'format': 'json'}) | |
| return json.loads(urlopen(url).read()) | |
| def load_file(f): | |
| from os.path import exists | |
| content = None | |
| if exists(f): | |
| with file(f, 'r') as fh: | |
| content = json.loads(''.join(fh.readlines())) | |
| return extract_data(content) | |
| def extract_data(data): | |
| friends = [] | |
| if data != None: | |
| for friend in data: | |
| friends.append(friend['name']) | |
| return friends | |
| def main(): | |
| if len(sys.argv) != 3: | |
| return 'Please specify the cached file and then the access token' | |
| cached = load_file(sys.argv[1]) | |
| token = sys.argv[2] | |
| data = fbquery(token, """SELECT uid, name | |
| FROM user | |
| WHERE uid IN ( | |
| SELECT uid2 | |
| FROM friend | |
| WHERE uid1 = me() | |
| )""") | |
| new = extract_data(data) | |
| for name in cached: | |
| if not name in new: | |
| print 'Peace, %s' % name | |
| with file(sys.argv[1], 'w') as fh: | |
| fh.write(json.dumps(data)) | |
| if __name__ == '__main__': | |
| sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment