Skip to content

Instantly share code, notes, and snippets.

@kristi
Created September 1, 2011 16:07
Show Gist options
  • Save kristi/1186517 to your computer and use it in GitHub Desktop.
Save kristi/1186517 to your computer and use it in GitHub Desktop.
find missing natcomm facebook members
#!/usr/bin/env python
import codecs
import json
import urllib2
tcomm_id = '105089836262253'
natcomm_id = '134083046643371'
# Get token from
# https://developers.facebook.com/tools/explorer
# or create a fb app (https://developers.facebook.com/apps)
# and use the app token (https://developers.facebook.com/tools/access_token/)
token = '245618128809868|3bhuIWbSfxJsjxVYXL49GpWCipY'
def get_members(facebook_id):
'''Return a list of member names'''
access_token = 'access_token='+token
address = 'https://graph.facebook.com/' + facebook_id + '/members?'+access_token
data = json.load(urllib2.urlopen(address))
return [member_dict['name'] for member_dict in data["data"]]
def write_members(members, filename, header):
'''Write list of members to a text file in utf-8 format'''
with codecs.open(filename, mode='w', encoding='utf-8') as f:
f.write(header.format(num=len(members)))
for name in sorted(members):
f.write(name + '\n')
# Taiko Community member list
tc = set(get_members(tcomm_id))
# NA Taiko Community member list
na = set(get_members(natcomm_id))
# Members in NATComm but not in TC
missing = na - tc
write_members(missing, "missing.txt", "missing {num} members from the natcomm group:\n")
# Members in TC but not in NATComm
added = tc - na
write_members(added, "added.txt", "added {num} members who weren't in the natcomm group:\n")
# Members in both TC and NATComm
both = tc & na
write_members(both, "both.txt", "found {num} members in both the natcomm group and the tc group:\n")
# For web page
#print "Content-type: text/plain\n"
# Print some stats
print "NATComm: {num} members".format(num=len(na))
print "TaikoCom: {num} members".format(num=len(tc))
print "{num} unique members".format(num=len(tc|na))
print "{num} NATComm members NOT in TaikoComm".format(num=len(missing))
print "{num} TaikoComm members NOT in NATComm".format(num=len(added))
print "{num} members in both NATComm and TaikoComm".format(num=len(both))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment