Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pip
- def install(package):
- pip.main(['install', package]);
- install("beautifulsoup4");
- install("requests");
- install("pymysql");
- from bs4 import BeautifulSoup
- import requests
- from html.parser import HTMLParser
- import pymysql
- import smtplib
- import datetime
- class Horse(object):
- def __init__(self, name, header, b365ToFairPercent, columnsTheSamePercent, columnsTheSame, bet365, betFair):
- self.name = name;
- self.header = header;
- self.b365ToFairPercent = b365ToFairPercent;
- self.columnsTheSame = columnsTheSame;
- self.columnsTheSamePercent = columnsTheSamePercent;
- self.bet365 = bet365;
- self.betFair = betFair;
- def getRaceList():
- ans = [];
- url = "https://www.oddschecker.com/horse-racing";
- r = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'});
- r = r.content;
- soup = BeautifulSoup(r, "html.parser");
- data = soup.find("div", class_="module show-times");
- data = data.find_all("div", { "class" : "racing-time"});
- for item in data:
- betURL = item.find("a");
- betURL = "https://www.oddschecker.com" + betURL["href"];
- ans.append(betURL);
- return ans;
- def getData(raceURL):
- r = requests.get(raceURL, headers={'User-Agent': 'Mozilla/5.0'});
- r = r.content;
- soup = BeautifulSoup(r, "html.parser");
- header = soup.find("div", class_="page-description module").find("h1").text;
- dataTable = soup.find("tbody", {"id" : "t1"});
- rows = dataTable.find_all("tr");
- for row in rows:
- if row is not None:
- bet365Odds = getB365Odds(row);
- if (bet365Odds != -1):
- name = getName(row);
- otherOdds = getOtherOdds(row);
- betFairOdd = otherOdds[-3];
- b365ToFairPercent = convertFraction(bet365Odds)/convertFraction(betFairOdd);
- b365ToFairPercent = round(b365ToFairPercent*100, 2);
- if (b365ToFairPercent > 101):
- columnsTheSame = otherOdds.count(bet365Odds) - 1;
- if (columnsTheSame == -1):
- columnsTheSame = 0;
- columnsTheSamePercent = 0;
- else:
- columnsTheSamePercent = 1/columnsTheSame;
- columnsTheSamePercent = round(columnsTheSamePercent * 100, 2);
- horseList.append(Horse(name, header, b365ToFairPercent, columnsTheSamePercent, columnsTheSame, convertFraction(bet365Odds), convertFraction(betFairOdd)));
- print(name);
- def getName(row):
- name = row.find("a");
- unwanted = name.find("span");
- unwanted.extract();
- name=name.text;
- return name;
- def getB365Odds(row):
- odds = row.select(".bc.bs");
- try:
- b365Class = odds[0]["class"];
- except:
- return -1;
- if "b" in b365Class:
- return odds[0].text;
- else:
- return -1;
- def getOtherOdds(row):
- otherOdds = [];
- odds = row.select(".bc.bs");
- for odd in odds:
- if (odd.text == ""):
- otherOdds.append(-1);
- else:
- otherOdds.append(odd.text);
- return otherOdds;
- def convertFraction(frac_str):
- try:
- return float(frac_str)
- except ValueError:
- num, denom = frac_str.split('/')
- try:
- leading, num = num.split(' ')
- whole = float(leading)
- except ValueError:
- whole = 0
- frac = float(num) / float(denom)
- return whole - frac if whole < 0 else whole + frac
- def sendEmail():
- server = smtplib.SMTP('smtp.mailgun.org', 587)
- server.starttls()
- server.login("b365@netontarget.com", "f5wqd84c")
- msg = "JOB DONE!"
- server.sendmail("b365@netontarget.com", "asw@netontarget.com", msg)
- server.quit()
- raceList = [];
- raceList = getRaceList();
- raceList = ["https://www.oddschecker.com/horse-racing/perth/16:05/winner"];
- horseList = [];
- for raceURL in raceList:
- getData(raceURL);
- hostname="s1.netontarget.net"
- user="admin_horses"
- password="1dOXRTcfBq"
- db="admin_b365"
- myConnection = pymysql.connect( host=hostname, user=user, passwd=password, db=db )
- cur = myConnection.cursor();
- now = datetime.datetime.now()
- for horse in horseList:
- query = "INSERT INTO b365alerts(horse, race, bet365, betfair, columnsthesame, columnsthesamepercentage, bet365tobetfairpercentage, `datetime`)VALUES(\'"
- query += horse.name + "\', \'" + horse.header + "\', \'" + str(horse.bet365) + "\', \'" + str(horse.betFair) + "\', \'";
- query += str(horse.columnsTheSame) + "\', \'" + str(horse.columnsTheSamePercent) + "\', \'" + str(horse.b365ToFairPercent) + "\', \'" + str(now) + "\')";
- print(query);
- cur.execute(query);
- myConnection.commit();
- myConnection.close();
- sendEmail();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement