+ 1.

+ 1.
Maybe we should amend the script so it does what he's doing, always good to know what your oppenent is backing.MemphisFlash wrote: ↑Tue Jan 12, 2021 8:37 amLooks like someone trying to steal the idea Archery1969
https://www.youtube.com/watch?v=a4w2z1L ... e=emb_logo
Capture.JPG
Code: Select all
import json
import re
import requests
from bs4 import BeautifulSoup
from requests_html import HTMLSession
def main():
session = HTMLSession()
baseUrl = "https://www.sportinglife.com"
results=[]
urls = []
res = requests.get("https://www.sportinglife.com/greyhounds/racecards")
soup = BeautifulSoup(res.text, "html.parser")
data =json.loads( soup.find('script', type='application/json').string) #convert to dictionary
for market in data['props']['pageProps']['meetings']:
for race in market['races']:
if race['race_stage'] == "Dormant":
urls.append('/greyhounds/racecards/' + race['date'] + '/' + race['course_name'].replace(" ", "-") + '/racecard/' + str(race['race_summary_reference']['id']))
x = 0
for link in urls:
res = session.get(baseUrl + link)
print(baseUrl + link)
soup = BeautifulSoup(res.text, "html.parser")
data =json.loads( soup.find('script', type='application/json').string)
grade = data['props']['pageProps']['race']['race_summary']['race_class']
distance = data['props']['pageProps']['race']['race_summary']['distance']
course = data['props']['pageProps']['race']['race_summary']['course_name']
race = data['props']['pageProps']['race']['race_summary']['date'] + "," + data['props']['pageProps']['race']['race_summary']['time'] + " " + course
Runners = dict()
data =json.loads( soup.find('script', type='application/json').string) #convert to dictionary
for runner in data['props']['pageProps']['race']['runs']:
runs=0
Trap = runner['cloth_number']
Name = runner['greyhound']['name']
fastest_time=100
for time in runner['greyhound']['previous_results']:
raceDate=time['date']
if 'distance' in time.keys() and time['course_name'] == course and time['distance'] == distance and time['run_time'] !="" and runs < 5:
runs += 1
#print(raceDate + " " + str(time['run_time']) + " " + str(Trap) + " " + Name)
if float(time['run_time'].strip("s")) <= fastest_time :
fastest_time=float(time['run_time'].strip("s"))
Runners[fastest_time] = str(Trap) + '. ' + Name
#print("\nFastest time " + str(fastest_time) + "\n")
if bool(Runners) == True and ('OR' in grade or 'A' in grade) and len(Runners.items())>1:
x = sorted(((k, v) for k, v in Runners.items()))
if (1 >= x[1][0] - x[0][0]) >= 0.1 and x[1][0] !=100:
timeDiff = round((x[1][0] - x[0][0]), 2)
results.append(race + ', ' + x[0][1] + ', class ' + grade + ', time difference ' + str(timeDiff))
results.sort()
file = open('dogs_1.txt', mode='w')
for line in results: file.write(line+'\n')
file.close()
main()
If only, luckily python is one of those coding languages where a little knowledge goes a long way.
Yep that was scraping and reporting every race because the lineArchery1969 wrote: ↑Wed Jan 13, 2021 11:34 amImports, probably over the top but its working using the PyCharm Windows IDE.
Code: Select all
if (1 >= x[1][0] - x[0][0]) >= 0.1 and x[1][0] !=100:
Code: Select all
if 0.1 <= (x[1][0] - x[0][0]) <= 1 and x[1][0] !=100:
Hard to know why they're different as SportingLife delete the form data after the race is run but it's set to look at the last 5 races where the course and distance are the same as today's race. Maybe your database is looking at races from all courses or distances or more than 5 races.Archery1969 wrote: ↑Wed Jan 13, 2021 3:03 pmObservation.
SportingLife
2021-01-13,14:07 Monmore, 4. Stepitout Mary, Class A6, Time Difference 0.49
My Database
2021-01-13,14:07 Monmore, 1. Waikiki Tom, Class A6, Time Difference 0.36
Could be that I am using the adjusted time last run. T1 did actually shorten in price and start around 6/4 Favourite.
Anyway,,,,
Depends what you're trying to do as there's so many versions out there nowMemphisFlash wrote: ↑Wed Jan 13, 2021 3:49 pmdoes the file need the code changing, i'm getting confused now, lol?
Code: Select all
import json
import re
import requests
from bs4 import BeautifulSoup
from requests_html import HTMLSession
def main():
session = HTMLSession()
baseUrl = "https://www.sportinglife.com"
results=[]
urls = []
res = requests.get("https://www.sportinglife.com/greyhounds/racecards")
soup = BeautifulSoup(res.text, "html.parser")
data =json.loads( soup.find('script', type='application/json').string) #convert to dictionary
for market in data['props']['pageProps']['meetings']:
for race in market['races']:
if race['race_stage'] == "Dormant":
urls.append('/greyhounds/racecards/' + race['date'] + '/' + race['course_name'].replace(" ", "-") + '/racecard/' + str(race['race_summary_reference']['id']))
x = 0
for link in urls:
res = session.get(baseUrl + link)
print(baseUrl + link)
soup = BeautifulSoup(res.text, "html.parser")
data =json.loads( soup.find('script', type='application/json').string)
grade = data['props']['pageProps']['race']['race_summary']['race_class']
distance = data['props']['pageProps']['race']['race_summary']['distance']
course = data['props']['pageProps']['race']['race_summary']['course_name']
race = data['props']['pageProps']['race']['race_summary']['date'] + "," + data['props']['pageProps']['race']['race_summary']['time'] + " " + course
Runners = dict()
data =json.loads( soup.find('script', type='application/json').string) #convert to dictionary
for runner in data['props']['pageProps']['race']['runs']:
runs=0
Trap = runner['cloth_number']
Name = runner['greyhound']['name']
fastest_time=100
for time in runner['greyhound']['previous_results']:
raceDate=time['date']
if 'distance' in time.keys() and time['course_name'] == course and time['distance'] == distance and time['run_time'] !="" and runs < 5:
runs += 1
#print(raceDate + " " + str(time['run_time']) + " " + str(Trap) + " " + Name)
if float(time['run_time'].strip("s")) <= fastest_time :
fastest_time=float(time['run_time'].strip("s"))
Runners[fastest_time] = str(Trap) + '. ' + Name
#print("\nFastest time " + str(fastest_time) + "\n")
if bool(Runners) == True and ('OR' in grade or 'A' in grade) and len(Runners.items())>1:
x = sorted(((k, v) for k, v in Runners.items()))
if 0.1 <= (x[1][0] - x[0][0]) <= 1 and x[1][0] !=100:
timeDiff = round((x[1][0] - x[0][0]), 2)
results.append(race + ', ' + x[0][1] + ', class ' + grade + ', time difference ' + str(timeDiff))
results.sort()
file = open('dogs_1.txt', mode='w')
for line in results: file.write(line+'\n')
file.close()
main()
Code: Select all
if 'distance' in time.keys() and time['course_name'] == course and time['distance'] == distance and time['run_time'] !="" and runs < 5:
Once it's got the fastest races for all runners (if a runner doesn't have previous race data or race data at the distance/course it gets entered as 100*) it then checks the race grade is A something or OR and we have data for more than one runner.{
"race_id": 223351,
"date": "2021-01-04",
"course_name": "Yarmouth",
"distance": "462",
"trap_number": 1,
"sectional_time": "5.71s",
"finish_distance": "3",
"position": 2,
"odds": "8/1",
"run_time": "28.74s"
}
Code: Select all
if bool(Runners) == True and ('OR' in grade or 'A' in grade) and len(Runners.items())>1:
Code: Select all
x = sorted(((k, v) for k, v in Runners.items()))
Code: Select all
if 0.1 <= (x[1][0] - x[0][0]) <= 1 and x[1][0] !=100:
Code: Select all
results.append(race + ', ' + x[0][1] + ', class ' + grade + ', time difference ' + str(timeDiff))
Code: Select all
results.sort()
file = open('dogs_1.txt', mode='w')
for line in results: file.write(line+'\n')
file.close()