def search(self, z): try: self.bgg = boardgamegeek.BGGClient() self.g = self.bgg.game(z) return (self.g.id) except: pass
def enter(self): self.query = self.lineEdit.text() self.idcheck = self.search(self.query) try: self.g.id self.metadata = self.lookup(self.idcheck) except: self.bgg = boardgamegeek.BGGClient() self.search = self.bgg.search(self.query) self.g = self.popup(self.search)
def main_process(): """ the main program just uses the functions defined above to first get the game ID lists, uses those to get the data from the BGG API, and finally uploads the data to MongoDB""" bgg = boardgamegeek.BGGClient(requests_per_minute=10) lists = [] for i in range(0, 100): lists.append(get_game_ids("numvoters", i + 1, 1)) data = get_api_data(bgg, lists) update_game_database(data)
def get_game_details(gameid): client = boardgamegeek.BGGClient() game = client.game(game_id=gameid) return { "id": game.id, "name": game.name, "rating": game.rating_average, "weight": game.rating_average_weight, "min_players": game.min_players, "max_players": game.max_players, "time": game.playing_time, "image": game.image }
def search(search_str): client = boardgamegeek.BGGClient() games = [] try: games = [client.game(search_str)] except boardgamegeek.BGGItemNotFoundError: pass search_results = client.search(search_str, search_type=[board_game_type]) return games + [ client.game(game_id=game.id) for game in search_results[:2] if not games or game.id != games[0].id ]
def get_game(search_str): client = boardgamegeek.BGGClient() print(search_str) try: # jesli tutaj sie uda, to super board_game = client.game(search_str) except boardgamegeek.BGGItemNotFoundError: # a jesli wejdzie tutaj, to sortowanie jest zle search_results = client.search(search_str, search_type=[board_game_type]) # wybieranie pierwszego elemetu jest slabe game_id = search_results[0].id # ale przynajmniej cos znajduje board_game = client.game(game_id=game_id) return board_game
# -*- coding: utf-8 -*- import boardgamegeek from glob import glob import logging from itertools import zip_longest from shutil import copyfileobj bgg = boardgamegeek.BGGClient() logging.basicConfig(filename='logs/collections.log', filemode='w', level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S') def load_usernames(file): with open(file, mode='r', encoding='utf-8') as f: return [line.rstrip() for line in f] def grouper(n, iterable, fillvalue=None): args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) def get_collection(username): try: games = [game.id for game in bgg.collection(user_name=username)] except boardgamegeek.BGGItemNotFoundError as e:
def get_bgg_client(): """ This will return a bgg client :return: bgg client object """ return bgg.BGGClient(disable_ssl=True)
def search_output(game): client = boardgamegeek.BGGClient() return {"id": game.id, "name": game.name, "image": game.image}
import boardgamegeek as bgg # Cache BGG requests for 15 minutes cache = bgg.CacheBackendSqlite('cache.db', ttl=15 * 60) client = bgg.BGGClient(cache=cache)