def import_tournament(type, path, bracket, region, name): config = Config() mongo_client = MongoClient(host=config.get_mongo_url()) if type == 'tio': scraper = TioScraper(path, bracket) elif type == 'challonge': scraper = ChallongeScraper(path) else: click.echo("Illegal type") dao = Dao(region, mongo_client=mongo_client) player_map = get_player_alias_to_id_map(scraper, dao) # TODO pass in a map of overrides for specific players tournament = Tournament.from_scraper(type, scraper, player_map, region) if name: tournament.name = name dao.insert_tournament(tournament) click.echo("Generating new ranking...") rankings.generate_ranking(dao) click.echo("Done!")
def _import_files(self): for f in NORCAL_FILES: scraper = TioScraper(f[0], f[1]) self._import_players(scraper, self.norcal_dao) player_map = self.norcal_dao.get_player_id_map_from_player_aliases( scraper.get_players()) self.norcal_dao.insert_tournament( Tournament.from_scraper('tio', scraper, player_map, self.norcal_dao.region_id)) for f in TEXAS_FILES: scraper = TioScraper(f[0], f[1]) self._import_players(scraper, self.texas_dao) player_map = self.texas_dao.get_player_id_map_from_player_aliases( scraper.get_players()) self.texas_dao.insert_tournament( Tournament.from_scraper('tio', scraper, player_map, self.texas_dao.region_id))
def post(self, region): dao = Dao(region, mongo_client=mongo_client) user = get_user_from_request(request, dao) if not user: return 'Permission denied', 403 if not is_user_admin_for_region(user, region): return 'Permission denied', 403 parser = reqparse.RequestParser() parser.add_argument('type', type=str, location='json') parser.add_argument('data', type=unicode, location='json') parser.add_argument('bracket', type=str, location='json') args = parser.parse_args() print "in server post, actually got this far!" if args['data'] is None: return "data required", 400 the_bytes = bytearray(args['data'], "utf8") if the_bytes[0] == 0xef: print "found magic numbers" return "magic numbers!", 503 type = args['type'] data = args['data'] if type == 'tio': if args['bracket'] is None: return "Missing bracket name", 400 data_bytes = bytes(data) if data_bytes[0] == '\xef': data = data[:3] scraper = TioScraper(data, args['bracket']) elif type == 'challonge': scraper = ChallongeScraper(data) else: return "Unknown type", 400 pending_tournament = PendingTournament.from_scraper( type, scraper, region) pending_tournament.alias_to_id_map = alias_service.get_alias_to_id_map_in_list_format( dao, pending_tournament.players) new_id = dao.insert_pending_tournament(pending_tournament) return_dict = {'id': str(new_id)} return return_dict
def post(self, region): dao = Dao(region, mongo_client=mongo_client) user = get_user_from_access_token(request.headers, dao) if not is_user_admin_for_region(user, region): return 'Permission denied', 403 parser = reqparse.RequestParser() parser.add_argument('type', type=str, location='json') parser.add_argument('data', type=unicode, location='json') parser.add_argument('bracket', type=str, location='json') args = parser.parse_args() if args['data'] is None: return "data required", 400 type = args['type'] data = args['data'] if type == 'tio': if args['bracket'] is None: return "Missing bracket name", 400 scraper = TioScraper(data, args['bracket']) elif type == 'challonge': scraper = ChallongeScraper(data) else: return "Unknown type", 400 pending_tournament = PendingTournament.from_scraper( type, scraper, region) pending_tournament.alias_to_id_map = alias_service.get_alias_to_id_map_in_list_format( dao, pending_tournament.players) new_id = dao.insert_pending_tournament(pending_tournament) return_dict = {'id': str(new_id)} return return_dict
def post(self, region): dao = get_dao(region) auth_user(request, dao) parser = reqparse.RequestParser() \ .add_argument('type', type=str, location='json') \ .add_argument('data', type=unicode, location='json') \ .add_argument('bracket', type=str, location='json') \ .add_argument('included_phases', type=list, location='json') args = parser.parse_args() if args['data'] is None: err("Tournament data required.") the_bytes = bytearray(args['data'], "utf8") if the_bytes[0] == 0xef: print "found magic numbers" err("Magic numbers!") type = args['type'] data = args['data'] included_phases = args['included_phases'] pending_tournament = None try: if type == 'tio': if args['bracket'] is None: err("Missing bracket name") data_bytes = bytes(data) if data_bytes[0] == '\xef': data = data[:3] scraper = TioScraper(data, args['bracket']) elif type == 'challonge': scraper = ChallongeScraper(data) elif type == 'smashgg': scraper = SmashGGScraper(data, included_phases) else: err("Unknown tournament type") pending_tournament, raw_file = M.PendingTournament.from_scraper( type, scraper, region) except Exception as ex: err('Scraper encountered an error: ' + str(ex)) if not pending_tournament or not raw_file: err('Scraper encountered an error.') try: pending_tournament.alias_to_id_map = alias_service.get_alias_to_id_map_in_list_format( dao, pending_tournament.players) except Exception as e: log_exception() err('Alias service encountered an error') # If the tournament is too large, don't insert the raw file into the db. if len(pending_tournament.players) < 1000: try: raw_file = dao.insert_raw_file(raw_file) except Exception as ex: print ex err('Dao insert_raw_file encountered an error') else: print 'Skipping inserting raw file for tournament because it is too large' try: new_id = dao.insert_pending_tournament(pending_tournament) return_dict = { 'id': str(new_id) } return return_dict except Exception as ex: err('Dao insert_pending_tournament encountered an error') err('Unknown error!')