lcosmin / boardgamegeek

A Python interface to boardgamegeek.com. Pulls information from BGG and creates Python objects for the data.
BSD 3-Clause "New" or "Revised" License
118 stars 72 forks source link

line 102 error about __getattr__ #22

Closed HughP closed 8 years ago

HughP commented 8 years ago

I have the following code which I am running in terminal on OS X. boardgamegeek-0.13.2 Python 2.7.9 (default, Jan 29 2015, 06:28:58) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin

from boardgamegeek import BoardGameGeek
>>> bgg = BoardGameGeek()
>>> g = bgg.game("carcassonne")
>>> g.name 'carcassonne'
>>> for n in g.expansions: print n.id, n.name

Which works as expected.

however when I try the following I get an error.

for n in g.expansions: print n.id, n.name, n.alternative_names
> 167903 20 Jahre Darmstadt Spielt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/boardgamegeek/utils.py", line 102, in __getattr__
    raise AttributeError

I am both new to python and to the bgg module. Any suggestions on what my problem might be?

Is this at all because there is many to one relationship? I mean some things have more than one alternative name...

lcosmin commented 8 years ago

When you fetch game data for 'Carcassonne', the BGG API returns very little data about the expansions, something like this:

  <link type="boardgameexpansion" id="130998" value="Carcassonne: Little Buildings"/>
  <link type="boardgameexpansion" id="118618" value="Carcassonne: Mage &amp; Witch"/>
  <link type="boardgameexpansion" id="38431" value="Carcassonne: The Cult"/>

The library maps each expansion to a Thing() object (something that only has a name and an id) and makes them available as g.expansions (a list of Thing()s). Elements of this list don't have .alternative_names (the data isn't provided).

If you really need the alternative names, you'll have to do a bgg.game(game_id=GAME_ID) for each of them.

PS: play around with dir() on the objects returned by the library to see what's available in each of them.