Greyhound Mystique

Any markets not covered in the other boards
Post Reply
spreadbetting
Posts: 3140
Joined: Sun Jan 31, 2010 8:06 pm

Just noticed that was almost a year ago and I haven't done anything with Python since :( I'll try and take a look later as I could do with getting back into coding myself.
User avatar
MemphisFlash
Posts: 2335
Joined: Fri May 16, 2014 10:12 pm

never used python, i'm still getting to gips with power querys in excel.
is it easy to learn for an old'en like me.
Vladimir CC
Posts: 88
Joined: Wed Jan 22, 2020 1:13 pm

Code: Select all

import re
import requests
from bs4 import BeautifulSoup
from requests_html import HTMLSession

def extract_times(input):
    times_regex = re.compile(r'Best: (.....)sLast: (.....)s')
    best_times_regex = re.compile(r'Best: (.....)s')
    match = times_regex.search(input)
    best_match = best_times_regex.search(input)

    if match:
        if float(match.group(2)) < float(match.group(1)):
            return float(match.group(2))
        else:
            return round((float(match.group(1)) + float(match.group(2))) / 2, 2)

    return 100



def main():
    session = HTMLSession()
    baseUrl = "https://www.sportinglife.com"
    results = []
    res = requests.get("https://www.sportinglife.com/greyhounds/racecards")
    soup = BeautifulSoup(res.text, "html.parser")
    summary = list(filter(None, [link.find_parent('a', class_='') for link in soup.find_all('span', class_='gh-meeting-race-time')]))

    x = 0
    for tag in summary:
        link = tag.get('href')
        res = session.get(baseUrl + link)
        soup = BeautifulSoup(res.text, "html.parser")
        race = soup.find('h1').get_text()
        grade = soup.find(class_='gh-racecard-summary-race-class gh-racecard-summary-always-open').get_text()
        summary = soup.find_all(class_="gh-racing-runner-key-info-container")
        Runners = dict()

        for runner in summary:
            Trap = runner.find(class_="gh-racing-runner-cloth").get_text()
            Name = re.sub(r'\(.*\)', '', runner.find(class_="gh-racing-runner-greyhound-name").get_text())
            Average_time = extract_times(runner.find(class_="gh-racing-runner-greyhound-sub-info").get_text())
            Runners[Average_time] = Trap + '. ' + Name

        if bool(Runners) == True and ('OR' in grade or 'A' in grade):

            x = sorted(((k, v) for k, v in Runners.items()))

            if (x[1][0] - x[0][0]) >= 0.1:
                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()
fixed the code and cleaned it a little bit. the results are now stored in a txt file.
spreadbetting
Posts: 3140
Joined: Sun Jan 31, 2010 8:06 pm

Thanks, any idea why the old code had stopped working ?
Vladimir CC
Posts: 88
Joined: Wed Jan 22, 2020 1:13 pm

spreadbetting wrote:
Sat Dec 19, 2020 2:05 pm
Thanks, any idea why the old code had stopped working ?
can't quite remember well because i've worked on the code last summer. but i remember that the code wasn't retrieving any race link from the main page in the first place.
User avatar
MemphisFlash
Posts: 2335
Joined: Fri May 16, 2014 10:12 pm

can you do a step by step guide on how to load it
spreadbetting
Posts: 3140
Joined: Sun Jan 31, 2010 8:06 pm

MemphisFlash wrote:
Sat Dec 19, 2020 2:56 pm
can you do a step by step guide on how to load it
You'd need to have python installed on your PC and all the relevant libraries, from there it's no more than opening the file and pressing run.

https://www.python.org/downloads/release/python-391/ your OS needs to be above win 7

If you want to instal it I can take you from there
Vladimir CC
Posts: 88
Joined: Wed Jan 22, 2020 1:13 pm

MemphisFlash wrote:
Sat Dec 19, 2020 2:56 pm
can you do a step by step guide on how to load it
1. if you don't have python installed, download the installer from here https://www.python.org/downloads/
2. during the installation, make sure to check the "Add to PATH" checkbox.
3. open notepad, paste the code and save the file with ".py" extension (<something>.py)
4. open Command Prompt and change the working directory to where you have your python script: cd <your directory>
5. run the python script: python <your filename>
if it doesn't work try with "python3". if that doesn't work either, you probably haven't added python to PATH
6. wait 1/2 min until the program finishes.
7. check the new txt file that has appeared in the folder where the script is. the file is overwritten every time you run the script.
And that's the quickest way to run a python code, just by the command line. No additional software.

Example:
example.jpg
You do not have the required permissions to view the files attached to this post.
Vladimir CC
Posts: 88
Joined: Wed Jan 22, 2020 1:13 pm

spreadbetting wrote:
Sat Dec 19, 2020 3:44 pm
MemphisFlash wrote:
Sat Dec 19, 2020 2:56 pm
can you do a step by step guide on how to load it
You'd need to have python installed on your PC and all the relevant libraries
Yes, I forgot to mention that you need to install requests and beautifulsoup4 libraries for the script to run. you can do that by typing "pip(or pip3) install beautifulsoup4, requests" command in the command prompt
dvwooly
Posts: 24
Joined: Fri Feb 07, 2014 10:42 pm

Vlad you legend ... thanks
User avatar
murdok
Posts: 151
Joined: Sun Apr 02, 2017 7:10 pm

Vladimir CC wrote:
Sat Dec 19, 2020 3:59 pm
MemphisFlash wrote:
Sat Dec 19, 2020 2:56 pm
can you do a step by step guide on how to load it
1. if you don't have python installed, download the installer from here https://www.python.org/downloads/
2. during the installation, make sure to check the "Add to PATH" checkbox.
3. open notepad, paste the code and save the file with ".py" extension (<something>.py)
4. open Command Prompt and change the working directory to where you have your python script: cd <your directory>
5. run the python script: python <your filename>
if it doesn't work try with "python3". if that doesn't work either, you probably haven't added python to PATH
6. wait 1/2 min until the program finishes.
7. check the new txt file that has appeared in the folder where the script is. the file is overwritten every time you run the script.
And that's the quickest way to run a python code, just by the command line. No additional software.

Example:
example.jpg
I lost a lot of time installing the libraries and PATH but now it works thx vlad you are the men :lol: :D :D


just returned a scrap line I thought it returned all the lines of the day :D


voilá
" 21:28 Hove Sat 19 December 2020, 4. Tommys Pluto, class OR, time difference 0.14 "
User avatar
MemphisFlash
Posts: 2335
Joined: Fri May 16, 2014 10:12 pm

so what have i done wrong
Capture.JPG
You do not have the required permissions to view the files attached to this post.
jamesg46
Posts: 3771
Joined: Sat Jul 30, 2016 1:05 pm

Vladimir, nice work & top guy for sharing your work. Thank you!
User avatar
murdok
Posts: 151
Joined: Sun Apr 02, 2017 7:10 pm

MemphisFlash wrote:
Sat Dec 19, 2020 10:58 pm
so what have i done wrong

Capture.JPG

run this in to cmd

pip install beautifulsoup4

pip3 install beautifulsoup4

i tink you need the libraries thing ....
User avatar
MemphisFlash
Posts: 2335
Joined: Fri May 16, 2014 10:12 pm

getting this error now
Capture.JPG
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Other Betfair Sports Trading markets”