Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- import urllib2
- import time
- import sys
- def get_collection(username):
- base_url = 'http://www.boardgamegeek.com/xmlapi2/'
- get_url = 'collection?username={0}&subtype=boardgame&own=1'.format(username)
- bggfile = urllib2.urlopen(base_url + get_url)
- bggxml = bggfile.read()
- bggfile.close()
- # find returns -1 if it fails to find something
- # BGG takes time to render a user's list - if it does, it returns a nessage page
- # check for that message, and if we see it, wait 5 seconds and try again
- if bggxml.find('Your request for this collection has been accepted and will be processed.') != -1:
- time.sleep(5)
- game_list = get_collection(username)
- else:
- soup = BeautifulSoup(bggxml)
- game_list = [game.string for game in soup.findAll('name')]
- return game_list
- user1 = sys.argv[1]
- user2 = sys.argv[2]
- print 'fetching games for ' + user1 + ' and ' + user2
- # super simple approach to make sure we get the real results, since BGG takes a few seconds to render a collection
- # to XML
- user1coll = get_collection(user1)
- user2coll = get_collection(user2)
- print user1 + ' has the following games which ' + user2 + 'does not:'
- print set(user1coll).difference(set(user2coll))
- print '*********'
- print user1 + ' and ' + user2 + 'have the following games in common:'
- print set(user1coll).intersection(set(user2coll))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement