Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Noisebridge PyClass Homework
import urllib2
from lxml.html import fromstring
import json
def collate_data():
print "beginning collating..."
# get the list of users from noisebridge wiki
# and put them in a dictionary with userid as key
nb_url = ""
fp = urllib2.urlopen(nb_url)
data =
doc = fromstring(data)
names = doc.xpath("//div[@id='mw-content-text']/ul/li/a")
TODO: Lookup the list of users that the noisebridge twitter account
follows and save that data in a list for later.
nb_follows_url = ""
people = {}
for name in names:
uid = name.text
if name not in people:
people[uid] = {'nb_id': uid,
'nb_following': False,
'is_following_nb': False,
'gender': None,
'location': '',
'twitter_id': '',
'facebook_id': '',
'name' : '',
# for each user, try to find their facebook info.
# base FB url is<username>
# if they are a FB user, and in the US, collect their
# info in the dictionary
for uid, user in people.items():
fb_url = '' % user['nb_id']
print fb_url
fp = urllib2.urlopen(fb_url)
fb_data =
except urllib2.HTTPError:
fb_obj = json.loads(fb_data)
user['name'] = fb_obj['name']
user['gender'] = fb_obj['gender']
user['location'] = fb_obj['locale']
user['facebook_id'] = fb_obj['id']
TODO: continue going to see if each user has a twitter account
add that info here. The base url for gathering twitter info
is below and you will need to replace with their name, being
sure to catch any bad username.
If they have a username, check to see if they are following
noisebridge and if noisebridge is following them. noisebridges
twitter id is 16460799.
twittter_user_url = ""
print people
# print a list of people that noisebridge should follow on
# twitter. bonus if you figure out the facebook api page and do the same
# there
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.