def scheduled_update_of_cache(): logging.info('*** SCHEDULED UPDATE RUNNING ***') AufcDatabaseProxy.update_cache() this_weekend_fixtures() last_weekend_results()
def test_update_ground_nicknames(self): AufcDatabaseProxy.update_ground_nicknames() self.assertIsNotNone(AufcDatabaseProxy.ground_nicknames) self.assertEqual(AufcDatabaseProxy.ground_nicknames['Woodville Oval'], 'The Woods') self.assertEqual(AufcDatabaseProxy.ground_nicknames['University Oval'], 'Bob Neil #1')
def get_game_details_from_sportstg(game): url = url_generator.get_url(int(game['year']), game['gender'], game['division'], int(game['round']), bool(game['is_past_game']), bool(game['is_final'])) logging.info('Extracting game details from URL: ' + url) populated_game = Game(int(game['round']), int(game['year']), url, bool(game['is_past_game']), bool(game['is_final'])) populated_game.nickname = game['nickname'] populated_game.division = game['division'] populated_game.gender = game['gender'] populated_game.url_code = game['url_code'] populated_game.AUFC_logo = 'https://upload.wikimedia.org/wikipedia/en/4/45/Adelaide_University_Football_Club_Logo.png' populated_game.priority = get_div_priority(game['division']) # Scrape details from sportstg. populate_game_from_sportstg(populated_game) result = populated_game.result if result == 'WIN' or result == 'LOSS' or result == 'DRAW': populated_game.has_been_played = True else: populated_game.has_been_played = False # Populate nicknames. populated_game.opposition_nickname = AufcDatabaseProxy.get_opposition_nickname( populated_game.opposition) populated_game.location_nickname = AufcDatabaseProxy.get_ground_nickname( populated_game.location) if populated_game.error != '' or populated_game.result == 'BYE': return populated_game for i in range(len(populated_game.goal_kickers)): goals = populated_game.goal_kickers[i]['goals'] populated_game.goal_kickers[i] = copy.deepcopy( AufcDatabaseProxy.get_player_nickname( populated_game.goal_kickers[i]['name'])) populated_game.goal_kickers[i]['goals'] = goals for i in range(len(populated_game.best_players)): populated_game.best_players[i] = AufcDatabaseProxy.get_player_nickname( populated_game.best_players[i]['name']) populated_game.best_players[i].pop('goals', None) # Get the correct image url (may need to be overridden). override_image_url = AufcDatabaseProxy.get_override_image_url( populated_game.opposition) if override_image_url != '': populated_game.image_url = override_image_url if populated_game.image_url == '': populated_game.image_url = 'http://a1.espncdn.com/combiner/i?img=/i/teamlogos/soccer/500/default-team-logo-500.png&h=288&scale=crop&w=288&location=origin' return populated_game
def test_update_player_names_and_nicknames(self): AufcDatabaseProxy.update_player_names_and_nicknames() self.assertIsNotNone(AufcDatabaseProxy.player_names_and_nicknames) self.assertGreater( len(AufcDatabaseProxy.player_names_and_nicknames.keys()), 4000) player = AufcDatabaseProxy.player_names_and_nicknames['J. Dearing'] self.assertEqual(player['fullname'], 'Jackson Dearing') self.assertEqual(player['nickname'], 'Buck Hunter')
def test_update_overrides(self): AufcDatabaseProxy.update_overrides() self.assertIsNotNone(AufcDatabaseProxy.ground_nicknames_overrides) self.assertIsNotNone(AufcDatabaseProxy.image_url_overrides) self.assertEqual( AufcDatabaseProxy.image_url_overrides['Marion'], 'https://aflnational.com/wp-content/uploads/Marion-Rams-AFL-logo.jpg' )
def test_update_opposition_nicknames(self): AufcDatabaseProxy.update_opposition_nicknames() self.assertIsNotNone(AufcDatabaseProxy.opposition_nicknames) self.assertEqual(AufcDatabaseProxy.opposition_nicknames['Portland'], 'Flagon of Portland') self.assertEqual(AufcDatabaseProxy.opposition_nicknames['North Haven'], 'North Misbe-haven') self.assertEqual( AufcDatabaseProxy.opposition_nicknames["Saint Peters O.C."], 'The Silver Spooners')
def test_get_player_nickname(self): player = AufcDatabaseProxy.get_player_nickname('J. Dearing') self.assertEqual(player['fullname'], 'Jackson Dearing') self.assertEqual(player['nickname'], 'Buck Hunter') self.assertEqual( AufcDatabaseProxy.get_player_nickname('J. GooseInvalid'), { 'fullname': '', 'nickname': '', 'name': 'J. GooseInvalid', 'memberID': 0 })
def setUpClass(cls): AufcDatabaseProxy.update_cache()
'is_past_game': True, 'round': False } teams.append(team) return teams @app.route('/input-table-teams-data', methods=['GET']) def input_table_teams_data(): year = request.args.get('year') response_data = json.dumps( initialise_teams_input_data_from_configuration(year)) return allow_cors(response_data) def scheduled_update_of_cache(): logging.info('*** SCHEDULED UPDATE RUNNING ***') AufcDatabaseProxy.update_cache() this_weekend_fixtures() last_weekend_results() if __name__ == '__main__': sched = BackgroundScheduler(daemon=True) sched.add_job(scheduled_update_of_cache, 'interval', seconds=40000) sched.start() AufcDatabaseProxy.update_cache() app.run(host="0.0.0.0", debug=True)
def test_get_opposition_nickname(self): self.assertEqual( AufcDatabaseProxy.get_opposition_nickname('Athelstone'), 'The Raggies') self.assertEqual( AufcDatabaseProxy.get_opposition_nickname('Rostrevor OC'), 'Ross and Trevor') self.assertEqual( AufcDatabaseProxy.get_opposition_nickname('Non existant club'), '') self.assertEqual( AufcDatabaseProxy.get_opposition_nickname("St Peter's OC"), 'The Silver Spooners') self.assertEqual( AufcDatabaseProxy.get_opposition_nickname("Angle Vale"), "Angle Fail") self.assertEqual( AufcDatabaseProxy.get_opposition_nickname("St Paul's OS"), "Saint Paul") self.assertEqual( AufcDatabaseProxy.get_opposition_nickname( "Payneham Norwood Union"), "Payneham in the @rse") self.assertEqual( AufcDatabaseProxy.get_opposition_nickname("Blackfriars OS"), "Friar Tuck") self.assertEqual(AufcDatabaseProxy.get_opposition_nickname("Gaza"), "Nice Gaza") self.assertEqual( AufcDatabaseProxy.get_opposition_nickname( "Brighton District & O.S."), "Brighton Boomers") self.assertEqual( AufcDatabaseProxy.get_opposition_nickname("Smithfield"), "Smiths Chips") self.assertEqual( AufcDatabaseProxy.get_opposition_nickname("Christies Beach"), "Christies a B!tch")
def test_get_correct_image_url(self): self.assertEqual( AufcDatabaseProxy.get_override_image_url("Morphettville Park"), "https://mpwfc.files.wordpress.com/2014/05/mpwfc_logo.png?w=676") self.assertEqual(AufcDatabaseProxy.get_override_image_url('Gaza'), '')
def test_connect_to_database(self): connection = AufcDatabaseProxy.connect_to_aufc_database() self.assertIsNotNone(connection) connection.close()
def test_get_ground_nickname(self): self.assertEqual( AufcDatabaseProxy.get_ground_nickname('University Oval'), 'Bob Neil #1') self.assertEqual( AufcDatabaseProxy.get_ground_nickname('Goodwood Oval'), 'Sin Stadium') self.assertEqual( AufcDatabaseProxy.get_ground_nickname('Non existant Oval'), '') self.assertEqual(AufcDatabaseProxy.get_ground_nickname('Caterer Oval'), 'Hackney High') self.assertEqual( AufcDatabaseProxy.get_ground_nickname( 'Ray White TTG Oval (Pertaringa)'), '') self.assertEqual(AufcDatabaseProxy.get_ground_nickname("Forfeit"), "FORFEIT") self.assertEqual( AufcDatabaseProxy.get_ground_nickname("Payneham Oval"), "@rse Park") self.assertEqual( AufcDatabaseProxy.get_ground_nickname("West Lakes Shore Oval"), "Fake Field") self.assertEqual( AufcDatabaseProxy.get_ground_nickname("St Pauls College"), "The Cathedral") self.assertEqual(AufcDatabaseProxy.get_ground_nickname("Hunter Park"), "The Nursing Home") self.assertEqual( AufcDatabaseProxy.get_ground_nickname("Harpers Field"), "Grovel Park") self.assertEqual( AufcDatabaseProxy.get_ground_nickname("Harpers Field No 2"), "Grovel Park") self.assertEqual( AufcDatabaseProxy.get_ground_nickname("University Oval"), "Bob Neil #1") self.assertEqual(AufcDatabaseProxy.get_ground_nickname("Caterer Oval"), "Hackney High") self.assertEqual( AufcDatabaseProxy.get_ground_nickname("Karen Rolton Oval"), "The Barton") self.assertEqual(AufcDatabaseProxy.get_ground_nickname("Simonds Park"), "The Dog Pound") self.assertEqual( AufcDatabaseProxy.get_ground_nickname("Woodville Oval"), "The Woods")