Skip to content

Commit

Permalink
Needs lots of cleanup, but accessories are now displayed as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Oglesby committed Apr 4, 2020
1 parent fb3f9a3 commit 3d814e5
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 4 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function get_widgets(SETTINGS) {
game.tags_str = game.tags.join(", ");
game.description = game.description.trim();
game.has_expansions = (game.expansions.length > 0);
game.has_accessories = (game.accessories.length > 0);

return game;
});
Expand Down
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ <h2 class="heading">
</ul></dd>
</div>
{{/ has_expansions }}
{{# has_accessories }}
<div class="accessories">
<dt>Accessories</dt>
<dd>
<ul>
{{# accessories }}
<li><a href="https://boardgamegeek.com/boardgame/{{{ id }}}">{{ name }}</a></li>
{{/ accessories }}
</ul>
</dd>
</div>
{{/ has_accessories }}
</dl>
<p class="description">
{{# helpers.highlight }}{ "attribute": "description" }{{/ helpers.highlight }}
Expand Down
46 changes: 44 additions & 2 deletions scripts/mybgg/bgg_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def after_status_hook(_, status):
collection = collection["items"]
return collection


def _games_list_to_games(self, data):
def numplayers_to_result(_, results):
result = {result["value"].lower().replace(" ", "_"): int(result["numvotes"]) for result in results}
Expand Down Expand Up @@ -229,6 +230,46 @@ def log_item(_, item):
),
alias="expansions",
),
xml.array(
xml.dictionary(
"link[@type='boardgamedesigner']", [
xml.integer(".", attribute="id"),
xml.boolean(".", attribute="inbound", required=False),
],
required=False
),
alias="designer",
),
xml.array(
xml.dictionary(
"link[@type='boardgameartist']", [
xml.integer(".", attribute="id"),
xml.boolean(".", attribute="inbound", required=False),
],
required=False
),
alias="artist",
),
xml.array(
xml.dictionary(
"link[@type='boardgamepublisher']", [
xml.integer(".", attribute="id"),
xml.boolean(".", attribute="inbound", required=False),
],
required=False
),
alias="publisher",
),
xml.array(
xml.dictionary(
"link[@type='boardgameaccessory']", [
xml.integer(".", attribute="id"),
xml.boolean(".", attribute="inbound", required=False),
],
required=False
),
alias="accessory",
),
xml.array(
xml.dictionary("poll[@name='suggested_numplayers']/results", [
xml.string(".", attribute="numplayers"),
Expand All @@ -239,7 +280,8 @@ def log_item(_, item):
], required=False),
hooks=xml.Hooks(after_parse=numplayers_to_result)
)
]),
],
required=False),
alias="suggested_numplayers",
hooks=xml.Hooks(after_parse=suggested_numplayers),
),
Expand Down Expand Up @@ -269,7 +311,7 @@ def log_item(_, item):
attribute="value",
alias="rating"
),
xml.string("playingtime", attribute="value", alias="playing_time"),
xml.string("playingtime", attribute="value", alias="playing_time", required=False),
],
required=False,
alias="items",
Expand Down
23 changes: 22 additions & 1 deletion scripts/mybgg/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def collection(self, user_name, extra_params):
**extra_params,
)

params = {"subtype": "boardgameaccessory", "own": 1}
accessory_data = self.client.collection(user_name=user_name, **params)

accessory_list_data = self.client.game_list([game_in_collection["id"] for game_in_collection in accessory_data])

plays_data = self.client.plays(
user_name=user_name,
)
Expand All @@ -60,6 +65,13 @@ def collection(self, user_name, extra_params):
if expansion["inbound"] and expansion["id"] in game_id_to_expansion:
game_id_to_expansion[expansion["id"]].append(expansion_data)


game_id_to_accessory = {game["id"]: [] for game in games_data}
for accessory_data in accessory_list_data:
for accessory in accessory_data["accessory"]:
if accessory["inbound"] and accessory["id"] in game_id_to_accessory:
game_id_to_accessory[accessory["id"]].append(accessory_data)

games = [
BoardGame(
game_data,
Expand All @@ -70,6 +82,10 @@ def collection(self, user_name, extra_params):
expansions=[
BoardGame(expansion_data)
for expansion_data in game_id_to_expansion[game_data["id"]]
],
accessories=[
BoardGame(accessory_data)
for accessory_data in game_id_to_accessory[game_data["id"]]
]
)
for game_data in games_data
Expand All @@ -78,7 +94,12 @@ def collection(self, user_name, extra_params):
for game in games:
for exp in game.expansions:
exp.name = remove_prefix(exp.name, game.name)
game.expansions.sort(key=lambda x: x.name) # Resort the list after updating the names
for acc in game.accessories:
acc.name = remove_prefix(acc.name, game.name)

# Resort the list after updating the names
game.expansions.sort(key=lambda x: x.name)
game.accessories.sort(key=lambda x: x.name)

return games

Expand Down
8 changes: 8 additions & 0 deletions scripts/mybgg/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ def add_objects(self, collection):
for expansion in game["expansions"]
]

game["accessories"] = [
{
attribute: accessory[attribute]
for attribute in ["id", "name"]
}
for accessory in game["accessories"]
]

# Make sure description is not too long
game["description"] = self._prepare_description(game["description"])

Expand Down
5 changes: 4 additions & 1 deletion scripts/mybgg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
articles = ['A', 'An', 'The']

class BoardGame:
def __init__(self, game_data, image="", tags=[], numplays=0, previous_players=[], expansions=[]):
def __init__(self, game_data, image="", tags=[], numplays=0, previous_players=[], expansions=[], accessories=[]):
self.id = game_data["id"]

name = game_data["name"]
Expand All @@ -29,6 +29,7 @@ def __init__(self, game_data, image="", tags=[], numplays=0, previous_players=[]
self.tags = tags
self.previous_players = previous_players
self.expansions = expansions
self.accessories = accessories

def calc_num_players(self, game_data, expansions):
num_players = game_data["suggested_numplayers"].copy()
Expand All @@ -51,6 +52,8 @@ def calc_playing_time(self, game_data):
240: '3-4h',
}
for playing_time_max, playing_time in playing_time_mapping.items():
if not game_data["playing_time"]:
return 'Unknowns'
if playing_time_max > int(game_data["playing_time"]):
return playing_time

Expand Down

0 comments on commit 3d814e5

Please sign in to comment.