def add_game(team_a, team_b, start_time): game = Game(game_type="MLB", team_a=team_a, team_b=team_b, start_time=start_time, is_finished=False) game.save()
def update_db_from(game): try: db_game = Game.objects.get(start_time=game["start_time"], team_a=game["team_a"], team_b=game["team_b"]) except: db_game = Game() db_game.update(game)
def update_db_from(game): db_game = get_game(game) if db_game: game["start_time"] = db_game.start_time db_game.update(game) db_game.save() else: db_game = Game(game) db_game.save()
from django.core.management import setup_environ import wagering.settings setup_environ(wagering.settings) from game_database.models import Game from game_database.scraper import scrape_nfl_schedule print "Do you want to delete all NFL games? Enter 'YES' to do so." text = raw_input("> ") if text == "YES": Game.objects.filter(game_type="NFL").delete() games = scrape_nfl_schedule(2013) for game in games: db_game = Game(**game) db_game.save()