Skip to content

Instantly share code, notes, and snippets.

@gamesbook
Last active April 27, 2018 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamesbook/8c82723cec2f1d0f542b2d94631a00c2 to your computer and use it in GitHub Desktop.
Save gamesbook/8c82723cec2f1d0f542b2d94631a00c2 to your computer and use it in GitHub Desktop.
Create summary of BoardGameGeek.com games
# -*- coding: utf-8 -*-
from __future__ import print_function
import csv
# via https://github.com/lcosmin/boardgamegeek
from boardgamegeek import BoardGameGeek
import logging
logging.basicConfig()
GAMES = """Monopoly
Clue
Risk"""
games_list = GAMES.split('\n')
count = len(games_list)
bgg = BoardGameGeek()
games = []
for key, name in enumerate(games_list):
print("Fetching #%s of %s: %s" % (key + 1, count, name))
try:
g = None
g = bgg.game(name.strip())
try:
link = "https://boardgamegeek.com/boardgame/%s/" % g.id
except:
link = ""
d = g.__dict__['_data']
try:
rank = d.get('ranks')[0]['value']
except:
rank = None
games.append([
g.name,
link,
d.get('yearpublished'),
rank,
d.get('average'),
d.get('playingtime'),
d.get('maxplayers')])
except Exception as err:
games.append([name, link, None, None, None, None, None])
print(err)
csvfile = "bgg_games.csv"
with open(csvfile, "w") as output:
writer = csv.writer(
output, lineterminator='\n', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
writer.writerow(['Name', 'Link', 'Year', 'Rank', 'Rating', 'Time', 'Players'])
writer.writerows(games)
@gamesbook
Copy link
Author

Given a list of games, create a CSV file that is easy to import into a spreadsheet (or Google Sheets) to get an overview of the game's key data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment