Skip to content

Instantly share code, notes, and snippets.

@commadelimited
Last active September 29, 2018 16:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save commadelimited/c2b76b16252017aa1a519fb82c8c2d5b to your computer and use it in GitHub Desktop.
Save commadelimited/c2b76b16252017aa1a519fb82c8c2d5b to your computer and use it in GitHub Desktop.
Show the owned games overlap of two BGG users

Compare BGG Games

This script will compare the collections of two BoardGameGeek users, and return all of the owned games which appear in both collections. Optionally, pass in one of the following strings to return games matching that status:

  • all
  • for_trade
  • prev_owned
  • want
  • wishlist

To use this script you'll first need to install the boardgamegeek Python lib on your local machine Use pip install boardgamegeek. If that does not work try easy_install boardgamegeek

Put this script whereever you like, then call it like so:

python bgg_games.py commadelimited elilong

To include only games in both player's wishlists

python bgg_games.py commadelimited elilong wishlist

To include only games in both player's previously owned lists

python bgg_games.py commadelimited elilong prev_owned

This script uses the boardgamegeek Python library:

https://github.com/lcosmin/boardgamegeek

########################################
# DO NOT CHANGE ANYTHING BELOW THIS LINE
########################################
import sys
from boardgamegeek.api import BoardGameGeek
bgg = BoardGameGeek()
def compare(users, status):
master_list = []
for user in users:
collection = bgg.collection(user_name=user)
if status == 'all':
master_list.append([item.name for item in collection.items])
else:
master_list.append([item.name for item in collection.items if getattr(item, status)])
return [val for val in master_list[0] if val in master_list[1]]
if __name__ == '__main__':
options = [
'all',
'for_trade',
'owned',
'prev_owned',
'want',
'wishlist',
]
users = sys.argv[1:3]
# if there are more than 2 args, and the 3rd arg is valid
if len(sys.argv[1:4]) > 2 and sys.argv[3] in options:
status = sys.argv[3]
# else default to only owned games
else:
status = 'owned'
try:
print compare(users, status)
except Exception, e:
print "An error occurred, please try again."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment