예제 #1
0
        def handle(self, *args, **options):
       		url = 'http://topbet.eu/sportsbook/college-football/ncaa'
        	update_counter = 0
                newmatch_counter = 0


		r = requests.get(url)


		soup = BeautifulSoup(r.text)
		soup.find_all('td')
		events = soup.findAll("div",{"class":"event"})
		#single event
		for single in events:
		    header = single.find_all('h3')
	  	    tds = single.find_all('td')
		    matchuparray = []
	   	    for td in tds:
	 	        line = td.get_text()
		        line = line.strip()
		        matchuparray.append(line)
	    
		    headerarray =[]

		    for x in header:
			line = x.get_text()
			line = line.strip()
			headerarray.append(line)

		    headerstring = headerarray.pop()
		    headersplit = headerstring.split('\n')
	            
		    if 'O' in headersplit: 
		        headersplit.remove('O')
	            if '' in headersplit:
		        headersplit.remove('')
	                
		    header_date = headersplit[0]
		    header_time = headersplit[1]

		    match = re.search(r'\d{4}-\d{2}-\d{2}', header_date)
		    matchup_summary = header_date.replace(match.group(),'').strip()

		    away_full_name = matchup_summary[0:matchup_summary.find(' at ')].strip()
	    	    home_full_name = matchup_summary[matchup_summary.find( ' at ')+4:len(matchup_summary)].strip()

	 	    matchupdatetime_string = match.group() +' '+header_time 
		    
		    matchupdatetime = datetime.datetime.strptime(matchupdatetime_string, '%Y-%m-%d %H:%M')
                    eastern_time = tz.gettz('America/New_York')
                    utc_time = tz.gettz('UTC')
                    matchupdatetime = matchupdatetime.replace(tzinfo = utc_time)
                    matchupdatetime = matchupdatetime.astimezone(eastern_time)
		    matchuparray.reverse()

		    away_rotid_temp= matchuparray.pop()
	            away_rotid_temp = away_rotid_temp.strip()
	    	    away_rotid_temp = away_rotid_temp.split('\n')
		    away_rotid_temp.remove('')
		    away_rotid = away_rotid_temp[1].strip()
		    away_team_str= matchuparray.pop()
		    away_spread=matchuparray.pop()
		    away_spread_line=matchuparray.pop()
		#temp = matchuparray.pop()
		    spread_on_string = matchuparray.pop()
		    away_money_line=matchuparray.pop()
		#matchuparray.pop()
		    moneyline_on_string = matchuparray.pop()
		#matchuparray.pop()
		    over_string=matchuparray.pop()
		    away_over = matchuparray.pop()
		    over_line = matchuparray.pop()
		#matchuparray.pop()
		    overunder_on_string = matchuparray.pop()
		    home_rotid= matchuparray.pop()
		    home_team_str = matchuparray.pop()
		    home_spread = matchuparray.pop()
		    home_spread_line=matchuparray.pop()
		    bet_str3_spread = matchuparray.pop()
		    home_money_line= matchuparray.pop()
		    betstr5_moneyline_on_string = matchuparray.pop()
		    Under_str = matchuparray.pop()
		    over_under_repeat = matchuparray.pop()
		    under_line = matchuparray.pop()
	            bet_str4_overunder = matchuparray.pop()

	    
		    moneyline_on = True
		    overunder_on = True
		    spread_on = True
	            city_id_away = away_team_str[0:3]
		    city_id_home = home_team_str[0:3]
	            if moneyline_on_string == 'Off':
	                moneyline_on = False

	            if spread_on_string == 'Off':
	                spread_on = False

	            if overunder_on_string == 'Off':
	    	        overunder_on = False
	            
		    away_mascot = away_full_name.replace(away_team_str,'').strip()
		    home_mascot = home_full_name.replace(home_team_str,'').strip()
		    
		    away_team = Team.objects.filter(league = "NCAAF", city  = away_team_str, full_name = away_full_name)
		    home_team = Team.objects.filter(league = "NCAAF", city  = home_team_str, full_name = home_full_name)
		    if away_team.count() == 0:
		        away_team = Team(league = "NCAAF", city = away_team_str, team_name = away_mascot, full_name = away_full_name)
		        away_team.save()
		    else:
		        away_team = away_team[0]
			away_team.city_id = city_id_away
			away_team.save()
		    if home_team.count() == 0:
		        home_team = Team(league = "NCAAF", city = home_team_str, team_name = home_mascot, full_name = home_full_name)
		        home_team.save()
		    else: 
		        home_team = home_team[0]
			home_team.city_id = city_id_home
			home_team.save()
		    result_exists = Matchup.objects.filter(away_rotid=away_rotid, away_team = away_team, home_team = home_team, league = "NCAAF").count()
	            if result_exists > 0:
	                newmatchup = Matchup.objects.get(away_rotid=away_rotid, league="NCAAF", away_team = away_team, home_team = home_team)
	                newmatchup.date = matchupdatetime
	                newmatchup.away_rotid = away_rotid
	                newmatchup.away_team = away_team
	                newmatchup.away_spread = away_spread
	                newmatchup.away_spread_line = away_spread_line
	                newmatchup.away_money_line = away_money_line
	                newmatchup.over_under = away_over
	                newmatchup.over_line = over_line
	                newmatchup.under_line = under_line
	                newmatchup.home_rotid= home_rotid
	                newmatchup.home_team = home_team
	                newmatchup.home_spread =home_spread
	                newmatchup.home_spread_line = home_spread_line
	                newmatchup.home_money_line = home_money_line
	                newmatchup.moneyline_on = moneyline_on
	                newmatchup.overunder_on = overunder_on
	                newmatchup.spread_on = spread_on
	 	        newmatchup.save()
			logger.debug("%s @ %s matchup UPDATED in NCAAF" % (newmatchup.home_team.city, newmatchup.away_team.city))
			update_counter = update_counter + 1
	            else:	
		        newmatchup = Matchup(
		        date = matchupdatetime,
		        league = "NCAAF",
	   	        away_rotid = away_rotid, 
			away_team = away_team,
			away_spread = away_spread,
		    	away_spread_line = away_spread_line,
	       	    	away_money_line = away_money_line,
		    	over_under = away_over,
		   	over_line = over_line,  
		    	under_line = under_line, 
		    	home_rotid= home_rotid,
		    	home_team = home_team, 
		        home_spread =home_spread,  
		        home_spread_line = home_spread_line,
		        moneyline_on = moneyline_on,
	    		overunder_on = overunder_on,
	    		spread_on = spread_on,
	   	        home_money_line = home_money_line)	
		        newmatchup.save()
			newmatch_counter = newmatch_counter +1
			logger.debug("%s @ %s matchup ADDED to NCAAF" % (newmatchup.home_team.city, newmatchup.away_team.city))

		adm = Admin.objects.get(pk = 1)
		adm.NCAAF_LastUpdate = timezone.now()
		adm.save()

		time = datetime.datetime.now().strftime('%d%m%Y %H:%M:%S')
		description = "%d NCAAF Matchups added. %d NCAAF Matchups Updated" % (newmatch_counter, update_counter)
		print time, description
		totaldesc = time+"- "+description
                logger.info("%d NCAAF Matchups added. %d NCAAF Matchups Updated" % (newmatch_counter, update_counter)) 
		self.stdout.write("%d NCAAF Matchups added. %d NCAAF Matchups Updated" % (newmatch_counter, update_counter))
		if newmatch_counter > 0:
		    send_mail('New NCAAF Matchups', totaldesc, '*****@*****.**',['*****@*****.**'], fail_silently=False)		    
예제 #2
0
    def handle(self, *args, **options):
        url = "http://topbet.eu/sportsbook/basketball/nba"
        update_counter = 0
        newmatch_counter = 0

        r = requests.get(url)

        soup = BeautifulSoup(r.text)
        soup.find_all("td")
        events = soup.findAll("div", {"class": "event"})
        # single event
        for single in events:
            header = single.find_all("h3")
            tds = single.find_all("td")
            matchuparray = []
            for td in tds:
                line = td.get_text()
                line = line.strip()
                matchuparray.append(line)

            headerarray = []

            for x in header:
                line = x.get_text()
                line = line.strip()
                headerarray.append(line)

            headerstring = headerarray.pop()
            headersplit = headerstring.split("\n")

            if "O" in headersplit:
                headersplit.remove("O")
            if "" in headersplit:
                headersplit.remove("")

            header_date = headersplit[0]
            header_time = headersplit[1]

            match = re.search(r"\d{4}-\d{2}-\d{2}", header_date)
            matchup_summary = header_date.replace(match.group(), "").strip()

            away_full_name = matchup_summary[0 : matchup_summary.find(" at ")].strip()
            home_full_name = matchup_summary[matchup_summary.find(" at ") + 4 : len(matchup_summary)].strip()

            matchupdatetime_string = match.group() + " " + header_time

            matchupdatetime = datetime.datetime.strptime(matchupdatetime_string, "%Y-%m-%d %H:%M")
            eastern_time = tz.gettz("America/New_York")
            utc_time = tz.gettz("UTC")
            sameday = datetime.date(matchupdatetime.year, matchupdatetime.month, matchupdatetime.day)
            tomorrow = sameday + timedelta(days=1)
            matchupdatetime = matchupdatetime.replace(tzinfo=utc_time)
            matchupdatetime = matchupdatetime.astimezone(eastern_time)
            matchuparray.reverse()

            away_rotid_temp = matchuparray.pop()
            away_rotid_temp = away_rotid_temp.strip()
            away_rotid_temp = away_rotid_temp.split("\n")
            if "" in away_rotid_temp:
                away_rotid_temp.remove("")
            away_rotid = away_rotid_temp[1].strip()
            away_team_str = matchuparray.pop()
            away_spread = matchuparray.pop()
            away_spread_line = matchuparray.pop()
            if away_spread_line == "EVEN":
                away_spread_line = "100"
            # temp = matchuparray.pop()
            spread_on_string = matchuparray.pop()
            away_money_line = matchuparray.pop()
            if away_money_line == "EVEN":
                away_money_line = "100"
            # matchuparray.pop()
            moneyline_on_string = matchuparray.pop()
            # matchuparray.pop()
            over_string = matchuparray.pop()
            away_over = matchuparray.pop()
            over_line = matchuparray.pop()
            if over_line == "EVEN":
                over_line = "100"
            # matchuparray.pop()
            overunder_on_string = matchuparray.pop()
            home_rotid = matchuparray.pop()
            home_team_str = matchuparray.pop()
            home_spread = matchuparray.pop()
            home_spread_line = matchuparray.pop()
            if home_spread_line == "EVEN":
                home_spread_line = "100"
            bet_str3_spread = matchuparray.pop()
            home_money_line = matchuparray.pop()
            if home_money_line == "EVEN":
                home_money_line = "100"
            betstr5_moneyline_on_string = matchuparray.pop()
            Under_str = matchuparray.pop()
            over_under_repeat = matchuparray.pop()
            under_line = matchuparray.pop()
            if under_line == "EVEN":
                under_line = "100"
            bet_str4_overunder = matchuparray.pop()

            moneyline_on = True
            overunder_on = True
            spread_on = True
            city_id_away = away_team_str[0:3]
            city_id_home = home_team_str[0:3]
            if moneyline_on_string == "Off":
                moneyline_on = False

            if spread_on_string == "Off":
                spread_on = False

            if overunder_on_string == "Off":
                overunder_on = False

            away_mascot = away_full_name.replace(away_team_str, "").strip()
            home_mascot = home_full_name.replace(home_team_str, "").strip()

            away_team = Team.objects.filter(league="NBA", city=away_team_str, full_name=away_full_name)
            home_team = Team.objects.filter(league="NBA", city=home_team_str, full_name=home_full_name)
            if away_team.count() == 0:
                away_team = Team(league="NBA", city=away_team_str, team_name=away_mascot, full_name=away_full_name)
                away_team.save()
            else:
                away_team = away_team[0]
                away_team.city_id = city_id_away
                away_team.save()
            if home_team.count() == 0:
                home_team = Team(league="NBA", city=home_team_str, team_name=home_mascot, full_name=home_full_name)
                home_team.save()
            else:
                home_team = home_team[0]
                home_team.city_id = city_id_home
                home_team.save()
            result_exists = Matchup.objects.filter(
                away_rotid=away_rotid,
                away_team=away_team,
                home_team=home_team,
                league="NBA",
                date__gt=sameday,
                date__lt=tomorrow,
                game_completed="no",
            ).count()
            if result_exists > 0:
                newmatchup = Matchup.objects.get(
                    away_rotid=away_rotid,
                    league="NBA",
                    away_team=away_team,
                    home_team=home_team,
                    date__gt=sameday,
                    date__lt=tomorrow,
                )
                newmatchup.date = matchupdatetime
                newmatchup.away_rotid = away_rotid
                newmatchup.away_team = away_team
                newmatchup.away_spread = away_spread
                newmatchup.away_spread_line = away_spread_line
                newmatchup.away_money_line = away_money_line
                newmatchup.over_under = away_over
                newmatchup.over_line = over_line
                newmatchup.under_line = under_line
                newmatchup.home_rotid = home_rotid
                newmatchup.home_team = home_team
                newmatchup.home_spread = home_spread
                newmatchup.home_spread_line = home_spread_line
                newmatchup.home_money_line = home_money_line
                newmatchup.moneyline_on = moneyline_on
                newmatchup.overunder_on = overunder_on
                newmatchup.spread_on = spread_on
                newmatchup.save()
                logger.debug("%s @ %s matchup UPDATED in NBA" % (newmatchup.home_team.city, newmatchup.away_team.city))
                update_counter = update_counter + 1
            else:
                newmatchup = Matchup(
                    date=matchupdatetime,
                    league="NBA",
                    away_rotid=away_rotid,
                    away_team=away_team,
                    away_spread=away_spread,
                    away_spread_line=away_spread_line,
                    away_money_line=away_money_line,
                    over_under=away_over,
                    over_line=over_line,
                    under_line=under_line,
                    home_rotid=home_rotid,
                    home_team=home_team,
                    home_spread=home_spread,
                    home_spread_line=home_spread_line,
                    moneyline_on=moneyline_on,
                    overunder_on=overunder_on,
                    spread_on=spread_on,
                    home_money_line=home_money_line,
                )
                newmatchup.save()
                newmatch_counter = newmatch_counter + 1
                logger.debug("%s @ %s matchup ADDED to NBA" % (newmatchup.home_team.city, newmatchup.away_team.city))

        adm = Admin.objects.get(pk=1)
        adm.NBA_LastUpdate = timezone.now()
        adm.save()

        time = datetime.datetime.now().strftime("%d%m%Y %H:%M:%S")
        description = "%d NBA Matchups added. %d NBA Matchups Updated" % (newmatch_counter, update_counter)
        print time, description
        totaldesc = time + "- " + description
        logger.info("%d NBA Matchups added. %d NBA Matchups Updated" % (newmatch_counter, update_counter))
        self.stdout.write("%d NBA Matchups added. %d NBA Matchups Updated" % (newmatch_counter, update_counter))
        if newmatch_counter > 0:
            send_mail(
                "New NBA Matchups", totaldesc, "*****@*****.**", ["*****@*****.**"], fail_silently=False
            )
    def handle(self, *args, **options):
        url = "http://topbet.eu/sportsbook/college-football/ncaa"
        r = requests.get(url)
        soup = BeautifulSoup(r.text)
        soup.find_all("td")
        events = soup.findAll("div", {"class": "event"})
        # single event
        for single in events:
            header = single.find_all("h3")
            tds = single.find_all("td")
            matchuparray = []
            for td in tds:
                line = td.get_text()
                line = line.strip()
                matchuparray.append(line)

            headerarray = []

            for x in header:
                line = x.get_text()
                line = line.strip()
                headerarray.append(line)

            headerstring = headerarray.pop()
            headersplit = headerstring.split("\n")

            if "O" in headersplit:
                headersplit.remove("O")
            if "" in headersplit:
                headersplit.remove("")

            header_date = headersplit[0]
            header_time = headersplit[1]
            match = re.search(r"\d{4}-\d{2}-\d{2}", header_date)
            matchup_summary = header_date.replace(match.group(), "").strip()

            away_full_name = matchup_summary[0 : matchup_summary.find(" at ")].strip()
            home_full_name = matchup_summary[matchup_summary.find(" at ") + 4 : len(matchup_summary)].strip()

            matchupdatetime_string = match.group() + " " + header_time
            matchupdatetime = datetime.datetime.strptime(matchupdatetime_string, "%Y-%m-%d %H:%M")
            eastern = timezone("US/Eastern")
            matchupdatetime = eastern.localize(matchupdatetime)
            matchupdatetime = matchupdatetime - timedelta(hours=4)
            matchuparray.reverse()

            away_rotid_temp = matchuparray.pop()
            away_rotid_temp = away_rotid_temp.split("\n")
            away_rotid = away_rotid_temp[1]
            away_team_str = matchuparray.pop()
            away_spread = matchuparray.pop()
            away_spread_line = matchuparray.pop()
            # temp = matchuparray.pop()
            spread_on_string = matchuparray.pop()
            away_money_line = matchuparray.pop()
            # matchuparray.pop()
            moneyline_on_string = matchuparray.pop()
            # matchuparray.pop()
            over_string = matchuparray.pop()
            away_over = matchuparray.pop()
            over_line = matchuparray.pop()

            overunder_on_string = matchuparray.pop()
            home_rotid = matchuparray.pop()
            home_team_str = matchuparray.pop()
            home_spread = matchuparray.pop()
            home_spread_line = matchuparray.pop()
            bet_str3_spread = matchuparray.pop()
            home_money_line = matchuparray.pop()
            betstr5_moneyline_on_string = matchuparray.pop()
            Under_str = matchuparray.pop()
            over_under_repeat = matchuparray.pop()
            under_line = matchuparray.pop()
            bet_str4_overunder = matchuparray.pop()

            moneyline_on = True
            overunder_on = True
            spread_on = True

            if moneyline_on_string == "Off":
                moneyline_on = False

            if spread_on_string == "Off":
                spread_on = False

            if overunder_on_string == "Off":
                overunder_on = False

            away_mascot = away_full_name.replace(away_team_str, "").strip()
            home_mascot = home_full_name.replace(home_team_str, "").strip()

            away_team = Team.objects.filter(league="NCAAF", city=away_team_str)
            home_team = Team.objects.filter(league="NCAAF", city=home_team_str)
            if away_team.count() == 0:
                away_team = Team(league="NCAAF", city=away_team_str, team_name=away_mascot, full_name=away_full_name)
                away_team.save()
            else:
                away_team = away_team[0]
            if home_team.count() == 0:
                home_team = Team(league="NCAAF", city=home_team_str, team_name=home_mascot, full_name=home_full_name)
                home_team.save()
            else:
                home_team = home_team[0]
            result_exists = Matchup.objects.filter(away_rotid=away_rotid).count()
            if result_exists > 0:
                newmatchup = Matchup.objects.get(away_rotid=away_rotid)
                newmatchup.date = matchupdatetime
                newmatchup.away_rotid = away_rotid
                newmatchup.away_team = away_team
                newmatchup.away_spread = away_spread
                newmatchup.away_spread_line = away_spread_line
                newmatchup.away_money_line = away_money_line
                newmatchup.over_under = away_over
                newmatchup.over_line = over_line
                newmatchup.under_line = under_line
                newmatchup.home_rotid = home_rotid
                newmatchup.home_team = home_team
                newmatchup.home_spread = home_spread
                newmatchup.home_spread_line = home_spread_line
                newmatchup.home_money_line = home_money_line
                newmatchup.moneyline_on = moneyline_on
                newmatchup.overunder_on = overunder_on
                newmatchup.spread_on = spread_on
                newmatchup.save()
            else:
                newmatchup = Matchup(
                    date=matchupdatetime,
                    league="NCAAF",
                    away_rotid=away_rotid,
                    away_team=away_team,
                    away_spread=away_spread,
                    away_spread_line=away_spread_line,
                    away_money_line=away_money_line,
                    over_under=away_over,
                    over_line=over_line,
                    under_line=under_line,
                    home_rotid=home_rotid,
                    home_team=home_team,
                    home_spread=home_spread,
                    home_spread_line=home_spread_line,
                    moneyline_on=moneyline_on,
                    overunder_on=overunder_on,
                    spread_on=spread_on,
                    home_money_line=home_money_line,
                )
                newmatchup.save()
예제 #4
0
	def handle(self, *args, **options):
            url_topbets = 'http://topbet.eu/sportsbook/nfl'
            self.stdout.write("querying %s" % url_topbets)
	    content = urllib2.urlopen(url_topbets)
	    soup = BeautifulSoup(content)
	    events = soup.findAll("div",{"class":"event"})
	    update_counter = 0
	    newmatch_counter = 0
	    self.stdout.write("%s events found" % (len(events)))
	    #SINGLE EVENT
	    for single in events:
		header = single.find_all('h3')
		tds = single.find_all('td')
		matchuparray = []
		for td in tds:
	   	    line = td.get_text()
	 	    line = line.strip()
		    matchuparray.append(line)
			    

		headerarray =[]

		for x in header:
		    line = x.get_text()
		    line = line.strip()
		    headerarray.append(line)
	    
		headerstring = headerarray.pop()
		headersplit = headerstring.split('\n')
		headersplit.reverse()	
	       	if 'O' in headersplit:
		    headersplit.remove('O')
	        if '' in headersplit:
	            headersplit.remove('')
	        header_date = headersplit[1]
		header_time = headersplit[0]
	                
		match = re.search(r'\d{4}-\d{2}-\d{2}', header_date)
	        if match is None:
	            match = re.search(r'\d{4}-\d{2}-\d{2}', "0000-00-00")
		matchupdatetime_string = match.group() +' '+header_time 
		matchupdatetime = datetime.datetime.strptime(matchupdatetime_string, '%Y-%m-%d %H:%M')
		eastern_time = tz.gettz('America/New_York')
	        utc_time = tz.gettz('UTC')
	        matchupdatetime = matchupdatetime.replace(tzinfo = utc_time)
	        matchupdatetime = matchupdatetime.astimezone(eastern_time)
		matchuparray.reverse()

		away_rotid_temp= matchuparray.pop()
	        away_rotid_temp = away_rotid_temp.strip()
		away_rotid_temp = away_rotid_temp.split('\n')
		away_rotid_temp.remove('')
		away_rotid = away_rotid_temp[1].strip()
		away_team_str= matchuparray.pop() #Pittsburgh
		away_spread=matchuparray.pop()
		away_spread_line=matchuparray.pop()
		if away_spread_line == "EVEN":
			away_spread_line = "100"
		#temp = matchuparray.pop()
	        spread_on_string = matchuparray.pop() 	
	        away_money_line=matchuparray.pop()
		if away_money_line == "EVEN":
			away_money_line = "100"
		moneyline_on_string = matchuparray.pop()
		over_string = matchuparray.pop()
		away_over = matchuparray.pop()
		
	        over_line = matchuparray.pop()
		if over_line == "EVEN":
			over_line = "100"
		overunder_on_string = matchuparray.pop()
		home_rotid= matchuparray.pop()
		home_team_str = matchuparray.pop()
		home_spread = matchuparray.pop()
		home_spread_line=matchuparray.pop()
		if home_spread_line == "EVEN":
			home_spread_line = "100"
		spread_on_string2 = matchuparray.pop()
		home_money_line= matchuparray.pop()
		if home_money_line == "EVEN":
			home_money_line = "100"
		moneyline_on_string2 =matchuparray.pop()
		over_string2 =matchuparray.pop()
		home_over = matchuparray.pop()
		under_line = matchuparray.pop()
		if under_line == "EVEN":
		    under_line = "100"
		if home_team_str == "New York-A":
	 	    home_team_str = "Jets"
		elif home_team_str == "New York-N":
	 	    home_team_str = "Giants"
		elif home_team_str == 'Phila.':
		    home_team_str = 'Philadelphia'

		if away_team_str == "New York-A":
		    away_team_str = "Jets"
		elif away_team_str == "New York-N":
	 	    away_team_str =  "Giants"
		elif away_team_str == 'Phila.':
		    away_team_str = 'Philadelphia'
	        	
	        overunder_on = True
		moneyline_on = True
		spread_on = True
	        if overunder_on_string == 'Off':
		    overunder_on = False
		if moneyline_on_string == 'Off':
		    moneyline_on = False
	        if spread_on_string =='Off':
	            spread_on = False

		teams = Team.objects.all().filter(league="NFL")
		for x in teams:
			matchteam = x.city.find(home_team_str[0:6])
			if matchteam != -1:
		        	home_team = x
		for x in teams:
			matchteam = x.city.find(away_team_str[0:6])
			if matchteam != -1:
		        	away_team = x
	                
	        result_exists = Matchup.objects.filter(away_rotid=away_rotid, home_rotid = home_rotid, league = "NFL", home_team = home_team, away_team = away_team).count()
	        if result_exists > 0:
			newmatchup = Matchup.objects.get(away_rotid=away_rotid, league="NFL", home_team = home_team, away_team = away_team)
		        newmatchup.date = matchupdatetime
	                newmatchup.away_rotid = away_rotid
	                newmatchup.away_team = away_team
	                newmatchup.away_spread = away_spread
	                newmatchup.away_spread_line = away_spread_line
	                newmatchup.away_money_line = away_money_line
	                newmatchup.over_under = away_over
	                newmatchup.over_line = over_line
	                newmatchup.under_line = under_line
	                newmatchup.home_rotid= home_rotid
	                newmatchup.home_team = home_team
	                newmatchup.home_spread =home_spread
	                newmatchup.home_spread_line = home_spread_line
	                newmatchup.home_money_line = home_money_line
	                newmatchup.overunder_on = overunder_on
			newmatchup.moneyline_on = moneyline_on
			newmatchup.spread_on = spread_on
	 		newmatchup.save()
			update_counter = update_counter + 1
	                #logger.debug("%s vs %s - NFL Matchup Updated" % (newmatchup.away_team.city, newmatchup.home_team.city))
	        else:
			newmatchup = Matchup(
			date = matchupdatetime,
			away_rotid = away_rotid, 
			away_team = away_team,
			away_spread = away_spread,
			away_spread_line = away_spread_line,
			away_money_line = away_money_line,
			over_under = away_over,
			over_line = over_line,  
			under_line = under_line, 
			home_rotid= home_rotid,
			home_team = home_team, 
			home_spread =home_spread,  
			home_spread_line = home_spread_line,
			home_money_line = home_money_line,
			moneyline_on = moneyline_on,
	    		overunder_on = overunder_on,
	    		spread_on = spread_on)
			newmatchup.save()
	                #logger.debug("%s vs %s - NFL Matchup Added" % (newmatchup.away_team.city, newmatchup.home_team.city))
			newmatch_counter = newmatch_counter + 1
	    #logger.info("%d NFL Matchups added. %d NFL Matchups Updated" % (newmatch_counter, update_counter)) 

	    adm = Admin.objects.get(pk=1)
	    adm.NFL_LastUpdate = timezone.now()
	    adm.save()
            
	    time = datetime.datetime.now().strftime('%m/%d/%Y %H:%M:%S')
	    description = "%d  NFL Matchups added. %d NFL Matchups Updated" % (newmatch_counter, update_counter)
	    print time, description
	    totaldesc = time +"- "+ description
            self.stdout.write("%d NFL Matchups added. %d NFL Matchups Updated" % (newmatch_counter, update_counter))
	    if newmatch_counter > 0:
		send_mail('NEW NFL Matchups', totaldesc, '*****@*****.**',['*****@*****.**'], fail_silently=False)	
예제 #5
0
def ManualEvent(events): 
    for single in events:
        header = single.find_all('h3')
        tds = single.find_all('td')
        matchuparray = []
        for td in tds:
            line = td.get_text()
            line = line.strip()
            matchuparray.append(line)


        headerarray =[]

        for x in header:
            line = x.get_text()
            line = line.strip()
            headerarray.append(line)

        headerstring = headerarray.pop()
        headersplit = headerstring.split('      ')
        headersplit.reverse()
        if 'O' in headersplit:
            headersplit.remove('O')
        if '' in headersplit:
            headersplit.remove('')
       
        header_date = headersplit[1]
        header_time = headersplit[0]
       
        match = re.search(r'\d{4}-\d{2}-\d{2}', header_date)
        if match is None:
            match = re.search(r'\d{4}-\d{2}-\d{2}', "0000-00-00")
        matchupdatetime_string = match.group() +' '+header_time
        matchupdatetime = datetime.datetime.strptime(matchupdatetime_string, '%Y-%m-%d %H:%M')
        eastern_time = tz.gettz('America/New_York')
        utc_time = tz.gettz('UTC')
        matchupdatetime = matchupdatetime.replace(tzinfo = utc_time)
        matchupdatetime = matchupdatetime.astimezone(eastern_time)
        matchuparray.reverse()
        away_rotid_temp= matchuparray.pop()
        away_rotid_temp = away_rotid_temp.strip()
        away_rotid_temp = away_rotid_temp.split('\n')
        if '' in away_rotid_temp:
            away_rotid_temp.remove('')
        away_rotid = away_rotid_temp[1].strip()
        away_team_str= matchuparray.pop() #Pittsburgh
        away_spread=matchuparray.pop()
        away_spread_line=matchuparray.pop()
        if away_spread_line == "EVEN":
           away_spread_line = "100"
        spread_on_string = matchuparray.pop()
        away_money_line=matchuparray.pop()
        if away_money_line == "EVEN":
            away_money_line = "100"
        moneyline_on_string = matchuparray.pop()
        over_string = matchuparray.pop()
        away_over = matchuparray.pop()

        over_line = matchuparray.pop()
        if over_line == "EVEN":
            over_line = "100"
        overunder_on_string = matchuparray.pop()
        home_rotid= matchuparray.pop()
        home_team_str = matchuparray.pop()
        home_spread = matchuparray.pop()
        home_spread_line=matchuparray.pop()
        if home_spread_line == "EVEN":
           home_spread_line = "100"
     
        spread_on_string2 = matchuparray.pop()
        home_money_line= matchuparray.pop()
        if home_money_line == "EVEN":
            home_money_line = "100"
        moneyline_on_string2 =matchuparray.pop()
        over_string2 =matchuparray.pop()
        home_over = matchuparray.pop()
        under_line = matchuparray.pop()
        if under_line == "EVEN":
            under_line = "100"
        if home_team_str == "New York-A":
            home_team_str = "Jets"
        elif home_team_str == "New York-N":
            home_team_str = "Giants"
        elif home_team_str == 'Phila.':
            home_team_str = 'Philadelphia'
        if away_team_str == "New York-A":
            away_team_str = "Jets"
        elif away_team_str == "New York-N":
            away_team_str =  "Giants"
        elif away_team_str == 'Phila.':
            away_team_str = 'Philadelphia'
        overunder_on = True
        moneyline_on = True
        spread_on = True
        if overunder_on_string == 'Off':
            overunder_on = False
        if moneyline_on_string == 'Off':
            moneyline_on = False
        if spread_on_string =='Off':
            spread_on = False
        teams = Team.objects.all().filter(league="NFL")
        for x in teams:
            matchteam = x.city.find(home_team_str[0:6])
            if matchteam != -1:
                home_team = x
        for x in teams:
            matchteam = x.city.find(away_team_str[0:6])
            if matchteam != -1:
                away_team = x

        sameday = datetime.date(matchupdatetime.year,matchupdatetime.month,matchupdatetime.day)
        tomorrow = sameday + timedelta(days = 1)
        result_exists = Matchup.objects.filter(away_rotid=away_rotid, home_rotid = home_rotid, league = "NFL", home_team = home_team, away_team=away_team, date__gt = sameday, date__lt=tomorrow, game_completed = "no").count()                
        if result_exists > 0:
            newmatchup = Matchup.objects.get(away_rotid=away_rotid, league="NFL", home_team = home_team, away_team = away_team,date__gt = sameday, date__lt=tomorrow, game_completed = "no")
            newmatchup.date = matchupdatetime
            newmatchup.away_rotid = away_rotid
            newmatchup.away_team = away_team
            newmatchup.away_spread = away_spread
            newmatchup.away_spread_line = away_spread_line
            newmatchup.away_money_line = away_money_line
            newmatchup.over_under = away_over
            newmatchup.over_line = over_line
            newmatchup.under_line = under_line
            newmatchup.home_rotid= home_rotid
            newmatchup.home_team = home_team
            newmatchup.home_spread =home_spread
            newmatchup.home_spread_line = home_spread_line
            newmatchup.home_money_line = home_money_line
            newmatchup.overunder_on = overunder_on
            newmatchup.moneyline_on = moneyline_on
            newmatchup.spread_on = spread_on
            newmatchup.save()
            update_counter = update_counter + 1
        else:
            newmatchup = Matchup(
                date = matchupdatetime,
                away_rotid = away_rotid,
                away_team = away_team,
                away_spread = away_spread,
                away_spread_line = away_spread_line,
                away_money_line = away_money_line,
                over_under = away_over,
                over_line = over_line,
                under_line = under_line,
                home_rotid= home_rotid,
                home_team = home_team,
                home_spread =home_spread,
                home_spread_line = home_spread_line,
                home_money_line = home_money_line,
                moneyline_on = moneyline_on,
                overunder_on = overunder_on,
                spread_on = spread_on)
            newmatchup.save()
                #logger.debug("%s vs %s - NFL Matchup Added" % (newmatchup.away_team.city, newmatchup.home_team.city))
            newmatch_counter = newmatch_counter + 1


        adm = Admin.objects.get(pk=1)
        adm.NFL_LastUpdate = timezone.now()
        adm.save()

        time = datetime.datetime.now().strftime('%m/%d/%Y %H:%M:%S')
        description = "%d  NFL Matchups added. %d NFL Matchups Updated" % (newmatch_counter, update_counter)
        print time, description
        totaldesc = time +"- "+ description
        self.stdout.write("%d NFL Matchups added. %d NFL Matchups Updated" % (newmatch_counter, update_counter))
        if newmatch_counter > 0:
            send_mail('NEW NFL Matchups', totaldesc, '*****@*****.**',['*****@*****.**'], fail_silently=False)