示例#1
0
 def __init__(self):
     question_plugin_collection = QuestionCollection(
         'footyhints.question_plugins')
     self.question_plugins = question_plugin_collection.plugins
     for plugin in self.question_plugins:
         logger.debug("Loaded question plugin: {}".format(
             plugin.__class__.__name__))
示例#2
0
 def create_teams(self, teams_data):
     teams = {}
     if self.update:
         db_teams = Team.objects.all()
         for team in db_teams:
             teams[team.name] = team
         return teams
     sorted_team_names = sorted(teams_data)
     for sorted_name in sorted_team_names:
         team_data = teams_data[sorted_name]
         logger.debug("Creating team: {}".format(sorted_name))
         team = Team(name=sorted_name)
         if team_data['logo_url']:
             logger.debug("Downloading team logo from {0}".format(team_data['logo_url']))
             resp = requests.get(team_data['logo_url'])
             if resp.ok:
                 fp = BytesIO()
                 fp.write(resp.content)
                 file_type = team_data['logo_url'].split(".")[-1]
                 file_name = "{}.{}".format(slugify(team.name), file_type)
                 team.logo_image.save(file_name, files.File(fp))
             else:
                 logger.error("Received {0} when downloading team image".format(resp.text))
         teams[sorted_name] = team
         team.save()
     return teams
示例#3
0
 def run(self, game):
     logger.debug("Filling in questions for game: {}".format(game))
     self.delete_questions(game)
     for question_plugin in self.question_plugins:
         answer = question_plugin.answer(game)
         question = Question(description=question_plugin.description,
                             answer=answer,
                             position=question_plugin.position,
                             game=game)
         question.save()
         game.questions.add(question)
     game.save()
示例#4
0
def get_highlights_url(game):
    if config.mode.lower() == 'production':
        game_date = datetime.datetime.fromtimestamp(game['start_time']).strftime('%d/%m/%Y')
        game_search_str = "{} v. {} | PREMIER LEAGUE HIGHLIGHTS | {} | NBC Sports".format(
            game['home_team'],
            game['away_team'],
            game_date,
        )
        logger.debug("Searching youtube for highlights video {} \t{} vs {}".format(game_date, game['home_team'], game['away_team']))
        search = VideosSearch(game_search_str, limit=1)
        return 'https://www.youtube.com/embed/{}'.format(search.result()['result'][0]['id'])
    return 'https://www.youtube.com/embed/o1LAo78O8w8'
示例#5
0
 def find_game(self, match):
     # Look if game already exists
     home_teams_queryset = Team.objects.filter(name__contains=match['home_team'])
     if home_teams_queryset.count() > 0:
         home_team = home_teams_queryset[0]
         games_queryset = Game.objects.filter(team__name=home_team.name).filter(start_time=match['start_time'])
         if games_queryset.count() > 0:
             found_game = games_queryset[0]
             # Existing game found (based on home_team and start_time) so skip over
             logger.debug("Existing game found {} vs {} ({})".format(
                 found_game.home_team.name,
                 found_game.away_team.name,
                 found_game.start_time
             ))
             return found_game
     return None
示例#6
0
 def get_competition(self, league_name, logo_url):
     competition = Competition(name=league_name)
     if self.update:
         competition_queryset = Competition.objects.filter(name__contains=league_name)
         if competition_queryset.count() > 0:
             competition = competition_queryset[0]
             logger.debug("Found existing competition: {}".format(competition.name))
     else:
         if logo_url:
             logger.debug("Downloading competition logo from {0}".format(logo_url))
             resp = requests.get(logo_url)
             if resp.ok:
                 fp = BytesIO()
                 fp.write(resp.content)
                 file_type = logo_url.split(".")[-1]
                 file_name = "{}.{}".format(slugify(competition.name), file_type)
                 competition.logo_image.save(file_name, files.File(fp))
             else:
                 logger.error("Received {0} when downloading competition image".format(resp.text))
     competition.save()
     return competition
示例#7
0
    def run(self, game):
        logger.debug("Scoring game: {}".format(game))
        self.delete_score_modifications(game)
        # Main decision logic
        total_earned_score = 0
        total_potential_points = 0
        for score_plugin in self.score_plugins:
            score, reason = score_plugin.score(game)
            if score is not None:
                importance = LOWEST_PRIORITY - score_plugin.priority
                total_earned_score += score * importance
                # Average 75 points for each for high importance
                total_potential_points += 60 * importance
                score_modification = ScoreModification(
                    value=score,
                    reason=reason,
                    priority=score_plugin.priority,
                    game=game
                )
                score_modification.save()
                game.score_modifications.add(score_modification)

        score_earned_percent = (total_earned_score / total_potential_points) * 100
        game.interest_score = float("{0:.2f}".format(score_earned_percent))

        if game.interest_score >= 100:
            game.interest_score = 100
        elif game.interest_score <= 0:
            game.interest_score = 0

        if game.interest_score >= 66:
            game.interest_level = HIGH
        elif game.interest_score >= 33:
            game.interest_level = MEDIUM
        else:
            game.interest_level = LOW

        game.save()
示例#8
0
 def __init__(self):
     score_collection = ScoreCollection('footyhints.score_plugins')
     self.score_plugins = score_collection.plugins
     for plugin in self.score_plugins:
         logger.debug("Loaded score plugin: {}".format(plugin.__class__.__name__))
示例#9
0
 def __init__(self):
     logger.debug("Using football.api-sports.io data client")
示例#10
0
 def __init__(self):
     logger.debug("Using sample data client")