-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicker_cmd.py
More file actions
65 lines (55 loc) · 2.28 KB
/
picker_cmd.py
File metadata and controls
65 lines (55 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
""" Game picker: chooses boardgame from your collection on boardgamgeek.com
based on given filters """
from random import shuffle
from boardgamegeek import BGGClient
GOOD_THRESH = 0.2
BAD_THRESH = 0.2
MIN_VOTES = 20
def suggest_playernum(votes_dict):
""" function to determine, if the game is really playable with the given
number of players """
total_votes = votes_dict['total_votes']
max_players = len(votes_dict["results"].items())
if total_votes < MIN_VOTES:
result = [list(range(1, max_players)), list(range(1, max_players))]
return result
best = []
not_recommended = []
for val in votes_dict['results'].values():
best.append(val['best']/total_votes)
not_recommended.append(val['not_recommended']/total_votes)
good_num = [i for i, x in enumerate(best, 1) if x > GOOD_THRESH]
bad_num = [i for i, x in enumerate(not_recommended, 1) if x > BAD_THRESH]
return [good_num, bad_num]
def search_match(col):
""" Generator for finding games that match filter criteria """
for i, game in enumerate(col, 1):
numfit = suggest_playernum(game.suggested_numplayers)
if (game.max_players >= num_player and
game.min_players <= num_player and
game.max_playing_time <= playtime and
num_player in numfit[0] and
num_player not in numfit[1] and
round(game.rating_average_weight) == weight):
yield i, game.name
bgg = BGGClient()
USERNAME = eval(input("BGG Username: "))
collection = bgg.collection(USERNAME, exclude_subtype='boardgameexpansion', own=True, wishlist=None)
shuffle(collection.items)
ids = [x.id for x in collection.items]
print('Hello ' + USERNAME + ', you have ' + str(len(collection)) + ' games in your collection '
'(expansions not counting)')
# get games from BGG
try:
print('Collecting games.. ')
game_list = bgg.game_list(ids)
except:
print('Error!')
else:
print('Done.\n')
num_player = eval(input("How many players: "))
playtime = eval(input("Maximum playtime in minutes: "))
weight = eval(input("Weight (1 = light, 5 = heavy): "))
match = search_match(game_list)
for num in range(5):
print('Match: Game No. %d: %s' % (next(match)))