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 71 forks source link

gets "wrong" game #16

Closed glawler closed 9 years ago

glawler commented 9 years ago

python boardgamegeek/main.py -g illuminati

Does not return the first in the list at BGG, game 859. It returns game 17687, which is only connected to the game "Illuminati" because that is listed as one of it's alternate names.

glawler commented 9 years ago

Here's the URL: https://boardgamegeek.com/xmlapi2/search?exact=1&query=illuminati and the returned XML:

<items total="2" termsofuse="http://boardgamegeek.com/xmlapi/termsofuse">
<item type="boardgame" id="859">
<name type="primary" value="Illuminati"/>
<yearpublished value="1982"/>
</item>
<item type="boardgame" id="17687">
<name type="alternate" value="Illuminati"/>
<yearpublished value="2005"/>
</item>
</items>

The library should probably check against primary name if it has a choice of two or more entries.

glawler commented 9 years ago

Another suggestion I've heard is to sort the games by rank if the exact search returns more than one as that's usually the one people want.

glawler commented 9 years ago

Looks like the problem is that when the library does an exact search, it assumes only one response, which is usually the case, but not always.

lcosmin commented 9 years ago

Can you check out the latest release? I added a few features that might help you:

When there are more games with the same name:

The default behaviour is --most-recent (since --most-popular could require more API calls and it'd be slower).

Let me know how this works out for you.

glawler commented 9 years ago

I'm using the boardgamegeek.game() API though and not the command line. I was just using the command line as an example. Is it possible to add those arguments to the game() call as parameters?

lcosmin commented 9 years ago

Oh, I thought your problem was with the command line tool.

Of course it's possible to add extra parameters to game(), but I'm not convinced it's a good idea :-/ I'll have to think about it.

For most cases, the function performs ok as it is, as there are not many games with the same name. But when there are, which does the user want? Highest BGG rank might be the right one for most use cases, but certainly not all, and that would mean implementing a bunch of parameters for game() for all possible behaviours. If "best rank" wasn't costly to implement (extra API calls), I'd be ok with it, but with the extra calls, I don't know...

In the mean while, you can use the a piece of code like https://github.com/lcosmin/boardgamegeek/blob/master/boardgamegeek/main.py#L103 to get the behaviour you want.

glawler commented 9 years ago

If you won't put it in that's fine. I'll just have to put it in my code as that's the behavior I need. It seems to me that having the extra code in the library at the cost of library complexity makes more sense than having library users all implement the same thing, but I can understand if you want to keep the API clean.

I can also make the argument that the most popular, by definition!, is usually the game that people are after. :)

lcosmin commented 9 years ago

Can you give the develop branch a try? I added a parameter choose to game(). When dealing with multiple games with the same name, you can use it to determine which one is used.

lcosmin commented 9 years ago

Released in 0.13.0