def get_user_ratings(username, bgg=None):
    """Returns a dict: gameid -> rating"""
    if bgg is None:
        bgg = BoardGameGeek()

    collection = bgg.collection(username)

    user_ratings = dict()
    for item in collection:
        if item.rating:
            user_ratings[item.id] = item.rating

    return user_ratings
Example #2
0
def bgg_games(ids=None, user=None, filename=None, number=None, progress=False,
              **kwargs):
    """Return a list of BoardGameGeek games; sourced by ID, or user, or file

    Args:
        ids: list
            games IDs (integers) used by BGG
        user: string
            BGG user name; if supplied, then :
            * IDs will be ignored
        filename: string
            name of file containing game data saved in JSON format
        number: integer
            max no. of valid games to retrieve; default is 10
        progress: boolean
            show which games are being retrieved
    """
    if not number:
        number = 10
    else:
        number = int(number)
    tmpdir = tempfile.mkdtemp()
    predictable_filename = 'bgggames.cache'
    dbname = os.path.join(tmpdir, predictable_filename)
    bgg = BoardGameGeek(cache="sqlite://{}?ttl=1000".format(dbname),
                        disable_ssl=True)
    games = []
    if user:
        ids = []
        #bgg_user = bgg.user(user)
        try:
            collection = bgg.collection(user)
            if collection:
                for game in collection:
                    ids.append(game.id)
            else:
                print 'Unable to retrieve collection for %s - do they exist?' \
                    % user
        except BoardGameGeekAPIRetryError, err:
            print err
    Fix bug that causes certain game names to crash the program

"""

#change these to check other bgg user and send to different email
bggUser = "******"
userEmail = "*****@*****.**"

r = praw.Reddit('BGG Wishlist Mention Tracker by /u/shbones v 1.1')
sent_already = []

while True:
    #Repopulate boardgamegeek.com wishlist every run
    wishlist = []
    bgg = BoardGameGeek()
    collection = bgg.collection(bggUser)
    try:
        games = collection.items
        print games
        for each_game in games:
            if each_game.wishlist == True:
                wishlist.append(each_game.name.lower())

        #Check for mentions in Title or Text in Top 10 current posts on reddit.com/r/boardgames
        subreddit = r.get_subreddit('boardgames')
        for submission in subreddit.get_hot(limit=10):
            post_text = submission.selftext.lower()
            post_title = submission.title.lower()
            has_game = any(string in (post_text + post_title)
                           for string in wishlist)
            if submission.id not in sent_already and has_game:
Example #4
0
        game.image,
        'thumbnail':
        game.thumbnail,
    }
    cache[id] = json.dumps(fields)
    return fields


dic = {}
for user in name:
    print('Fetching collection of', user)
    c = 0
    found = False
    while not found and c < 5:
        try:
            hislist = bgg.collection(user_name=user)
            found = True
        except:
            pass
    if not found:
        exit(1)
    for item in hislist:
        if item.owned:
            dic[item.id] = dic.get(item.id, []) + [user]

print('Fetching all the games!')
ready = []
total_count = len(dic.keys())
count = 0
with progressbar.ProgressBar(max_value=total_count) as bar:
    for game in dic.items():
"""
This script creates a list of all games belonging to my collection
on boardgamegeek.com, and saves that list to a JSON file. It uses the 
BoardGameGeek library to get the collection and game information.   
"""
from boardgamegeek import BoardGameGeek
import json
import urllib
import re

bgg = BoardGameGeek()
collection = bgg.collection("escrimeuse")
# First we get the IDs of all the games in the collection
ids = []
for item in collection:
	ids.append(item.id)
# Now we get the information for each game
games = []
for i in ids:
	games.append(bgg.game(None,i))
# We're only interested in a subset of properties, so we create new objects
wanted_keys = ["name", "year", "mechanics", "thumbnail", "categories", "max_players", "min_players", "playing_time"]
new_games = [ {
	"id" : game.id,
	"name" : game.name,
	"year" : game.year,
	"mechanic" : game.mechanics,
	"thumbnail" : game.thumbnail,
	"category" : game.categories,
	"max_players" : game.max_players,
	"min_players" : game.min_players,