OZmium Sports Betting and Horse Racing Forums

OZmium Sports Betting and Horse Racing Forums (http://forums.ozmium.com.au/index.php)
-   General Topics (http://forums.ozmium.com.au/forumdisplay.php?f=59)
-   -   Python help using tkinter (http://forums.ozmium.com.au/showthread.php?t=32133)

Shaun 8th October 2020 11:43 AM

Python help using tkinter
 
This is my first attempt at a python app and can't find the answers i need so thought i would post here for some help.

This app will be a replacement for my Unitab prices excel sheet, so far i can import the venues and a bit of info for the day, i have tried a few different methods and the closes i can get is it prints the first venue info and stops, yet if you run this in your ide it prints all the info as i would like it.

The print statement doesn't need to be there.

Code:
from tkinter import * from tkcalendar import Calendar,DateEntry import json import requests app = Tk() app.title("Todays Races") app.geometry("1000x500") app.resizable(width=False, height=False) date_label = Label(app, text="Input Date", font=("bold", 14), pady=20) date_label.pack() cal = DateEntry(app,width=30,bg="darkblue",fg="white",date_pattern='yyyy-mm-dd',year=2020) cal.pack() date_btn = Button(app, text="Go", width=8, command=lambda: get_json()) date_btn.pack() def get_json(): state = "VIC" date = cal.get() url = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings?jurisdiction=" + state data = requests.get(url) data1 = json.loads(data.content) Venues = data1["meetings"] for Venue in Venues: Rtype = Venue["raceType"] track = Venue["meetingName"] Rstate = Venue["location"] Wcondition = Venue["weatherCondition"] Tcondition = Venue["trackCondition"] states = ("VIC","NSW","QLD","SA","WA","TAS","ACT") if Rtype == "R" and Rstate in states: text = track + " " + Rstate + " " + Tcondition + " " + Wcondition print(text) app.mainloop()

Shaun 8th October 2020 12:51 PM

Success......always the way, try to solve a problem for a couple days as soon as i post the issue i figure it out.

Code:
from tkinter import * from tkcalendar import Calendar,DateEntry import json import requests app = Tk() app.title("Todays Races") app.geometry("1000x500") app.resizable(width=False, height=False) date_label = Label(app, text="Input Date", font=("bold", 14), pady=20) date_label.pack() cal = DateEntry(app,width=30,bg="darkblue",fg="white",date_pattern='yyyy-mm-dd',year=2020) cal.pack() date_btn = Button(app, text="Go", width=8, command=lambda: get_json()) date_btn.pack() def get_json(): try: state = "VIC" date = cal.get() url = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings?jurisdiction=" + state data = requests.get(url) data1 = json.loads(data.content) Venues = data1["meetings"] for Venue in Venues: Rtype = Venue["raceType"] track = Venue["meetingName"] Rstate = Venue["location"] Wcondition = Venue["weatherCondition"] Tcondition = Venue["trackCondition"] states = ("VIC","NSW","QLD","SA","WA","TAS","ACT") if Rtype == "R" and Rstate in states: text = track + " " + Rstate + " " + Tcondition + " " + Wcondition text_label = Label(app, text=str(text)) text_label.pack() except: pass app.mainloop()

Shaun 14th October 2020 01:48 AM

I have progressed a bit further but having issues with the formatting, if you run this you will notice the results are going in a downward pattern rather than lining up under the headings.

Code:
from tkinter import * from tkcalendar import Calendar,DateEntry import json import requests app = Tk() app.title("Todays Races") app.geometry("1000x500") app.configure(bg='Lightblue') app.resizable(width=False, height=False) #Clears Daily Race Meetings def Fclear(): for widget in Rinfo.winfo_children(): widget.destroy() #Collects Daily Race Meetings def get_json(): state = "VIC" date = cal.get() url = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings?jurisdiction=" + state data = requests.get(url) data1 = json.loads(data.content) Venues = data1["meetings"] for Venue in Venues: Rtype = Venue["raceType"] Mname = Venue["meetingName"] Location = Venue["location"] Wcondition = Venue["weatherCondition"] Tcondition = Venue["trackCondition"] states = ("VIC","NSW","QLD","SA","WA","TAS","ACT") if Rtype == "R" and Location in states: #Race Info Mname_label = Label(Rinfo, text=Mname, font=("bold", 12), width=15, anchor=W, bg="Lightblue") Mname_label.grid(column=0, sticky=W) Location_label = Label(Rinfo, text=Location, font=("bold", 12), width=5 ,anchor=W, bg="Lightblue") Location_label.grid(column=2, sticky=W) Tcondition_label = Label(Rinfo, text=Tcondition, font=("bold", 12), width=10 ,anchor=W, bg="Lightblue") Tcondition_label.grid(column=3, sticky=W) Wcondition_label = Label(Rinfo, text=Wcondition, font=("bold", 12), width=10 ,anchor=W, bg="Lightblue") Wcondition_label.grid(column=4, sticky=W) # Date Selection Frame Dateframe = Frame(app, bg="Lightblue") Dateframe.grid(row=0, column=0, sticky=W) #Frame widgets date_label = Label(Dateframe, text="Input Date", font=("bold", 14), bg="Lightblue") date_label.grid(row=0, column=0) cal = DateEntry(Dateframe,width=15, bg="darkblue", fg="white", date_pattern='yyyy-mm-dd',year=2020) cal.grid(row=0, column=2) date_btn = Button(Dateframe, text="Go", width=8, bg="Lightgreen", command=get_json) date_btn.grid(row=0, column=3) delete_btn = Button(Dateframe, text="Clear", width=8, bg="#ff704d", command=Fclear) delete_btn.grid(row=0, column=4) #Headings frame Headingsframe = Frame(app, bg="Lightblue") Headingsframe.grid(row=1, column=0, sticky=W) #Race Info Headings htrack = Label(Headingsframe, text="Track", pady=10, font=("bold", 14),anchor=W, width=15, fg="Blue", bg="Lightblue") htrack.grid(row=0, column=0) hstate = Label(Headingsframe, text="State", pady=10, font=("bold", 14),anchor=W, width=5, fg="Blue", bg="Lightblue") hstate.grid(row=0, column=2) hcondition = Label(Headingsframe, text="Condition", pady=10, font=("bold", 14),anchor=W, width=10, fg="Blue", bg="Lightblue") hcondition.grid(row=0, column=3) hweather = Label(Headingsframe, text="Weather", pady=10, font=("bold", 14),anchor=W, width=10, fg="Blue", bg="Lightblue") hweather.grid(row=0, column=4) #Race Info Frame Rinfo = Frame(app, bg="lightblue") Rinfo.grid(row=2, column=0, sticky=W) app.mainloop()

chook 14th October 2020 04:38 AM

try .strip()
on the entries

chook 14th October 2020 04:58 AM

my early morning guess does not work
to make debug easier, change background colours
just do a think like
MNA_COLOR = "Red"
LOC_COLOR = "Blue"
and use that in places like your race info
then, when you are all filled with joy, change them to what you really want

it is a long time since i used tkinter
i will see if i can find a better answer for you

chook 14th October 2020 06:30 AM

label.grid( row=0,column=0,sticky=w)

Shaun 14th October 2020 10:08 AM

I will try your background solution, it might let me see what's going on, as for adding the row this seems to stop the loop as it always prints on row 0

Shaun 14th October 2020 11:19 AM

I solved this by creating a frame and spanning the column, i then just packed everything in from the left then just looped over and did it again.

Setting the colours definitely made a difference as i could see what was happening, now just to set them all back.

Code:
from tkinter import * from tkcalendar import Calendar,DateEntry import json import requests app = Tk() app.title("Todays Races") app.geometry("1000x500") app.configure(bg='Lightblue') app.resizable(width=False, height=False) #Clears Daily Race Meetings def Fclear(): for widget in Rinfo.winfo_children(): widget.destroy() #Collects Daily Race Meetings def get_json(): state = "VIC" date = cal.get() url = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings?jurisdiction=" + state data = requests.get(url) data1 = json.loads(data.content) Venues = data1["meetings"] for V in Venues: Rtype = V["raceType"] Mname = V["meetingName"] Location = V["location"] Wcondition = V["weatherCondition"] Tcondition = V["trackCondition"] states = ("VIC","NSW","QLD","SA","WA","TAS","ACT") if Rtype == "R" and Location in states: #Race Info frame Rinfo = Frame(app, width=100, bg="green") Rinfo.grid(columnspan=1) #Race info Mname_label = Label(Rinfo, text=Mname, font=("bold", 12), width=20, anchor=W, bg="red") Mname_label.pack(side=LEFT) Location_label = Label(Rinfo, text=Location, font=("bold", 12), width=5 ,anchor=W, bg="red") Location_label.pack(side=LEFT) Tcondition_label = Label(Rinfo, text=Tcondition, font=("bold", 12), width=10 ,anchor=W, bg="red") Tcondition_label.pack(side=LEFT) Wcondition_label = Label(Rinfo, text=Wcondition, font=("bold", 12), width=10 ,anchor=W, bg="red") Wcondition_label.pack(side=LEFT) # Date Selection Frame Dateframe = Frame(app, bg="Lightblue") Dateframe.grid(row=0, column=0, sticky=W) #Frame widgets date_label = Label(Dateframe, text="Input Date", font=("bold", 14), bg="Lightblue") date_label.grid(row=0, column=0) cal = DateEntry(Dateframe,width=15, bg="darkblue", fg="white", date_pattern='yyyy-mm-dd',year=2020) cal.grid(row=0, column=2) date_btn = Button(Dateframe, text="Go", width=8, bg="Lightgreen", command=get_json) date_btn.grid(row=0, column=3) delete_btn = Button(Dateframe, text="Clear", width=8, bg="#ff704d", command=Fclear) delete_btn.grid(row=0, column=4) #Headings frame Headingsframe = Frame(app, bg="Lightblue") Headingsframe.grid(row=1, column=0, sticky=W) #Race Info Headings htrack = Label(Headingsframe, text="Track", pady=10, font=("bold", 12),anchor=W, width=20, fg="Blue", bg="yellow") htrack.grid(row=0, column=0) hstate = Label(Headingsframe, text="State", pady=10, font=("bold", 12),anchor=W, width=5, fg="Blue", bg="orange") hstate.grid(row=0, column=2) hcondition = Label(Headingsframe, text="Condition", pady=10, font=("bold", 12),anchor=W, width=10, fg="Blue", bg="blue") hcondition.grid(row=0, column=3) hweather = Label(Headingsframe, text="Weather", pady=10, font=("bold", 12),anchor=W, width=10, fg="Blue", bg="green") hweather.grid(row=0, column=4) app.mainloop()

chook 14th October 2020 11:54 AM

#sorry for my rushed reply.
#above the for Venue in venues:
rowo = 0
for Venue in Venues:
#add row=rowo to your .grid( lines
#then at the bottom of that loop under
Wcondition_label.grid( column=4,sticky=W,row=rowo)
rowo += 1
#that will increment the row number
#you need row=rowo or whatever you choose to call it alongside the column=n

Shaun 14th October 2020 12:06 PM

I will also try this as it may be useful moving forward with this project.

chook 14th October 2020 01:44 PM

i hope this gets pasted properly
####### add row number
rowo = 0
for Venue in Venues:
Rtype = Venue["raceType"]
Mname = Venue["meetingName"]
Location = Venue["location"]
###### weather and track condition might not be there
if "weatherCondition" in Venue: Wcondition = Venue["weatherCondition"]
else: Wcondition = "BLEEK"
if "trackCondition" in Venue: Tcondition = Venue["trackCondition"]
else: Tcondition = "TkCoon"
states = ("VIC","NSW","QLD","SA","WA","TAS","ACT")
if Rtype == "R" and Location in states:
#Race Info
Mname_label = Label(Rinfo, text=Mname, font=("bold", 12), width=15, anchor=W, bg="Red")
Mname_label.grid(column=0, sticky=W,row=rowo)
Location_label = Label(Rinfo, text=Location, font=("bold", 12), width=5 ,anchor=W, bg="Pink")
Location_label.grid(column=2, sticky=W,row=rowo)
Tcondition_label = Label(Rinfo, text=Tcondition, font=("bold", 12), width=10 ,anchor=W, bg="Magenta")
Tcondition_label.grid(column=3, sticky=W,row=rowo)
Wcondition_label = Label(Rinfo, text=Wcondition, font=("bold", 12), width=10 ,anchor=W, bg="Lightblue")
Wcondition_label.grid(column=4, sticky=W,row=rowo)
##### increment row number
rowo += 1

# Date Selection Frame

#### end of paste

HTH

Shaun 27th October 2020 12:04 AM

I have almost finished this app, pretty happy with it, just have a small issue i can't resolve.

normally when returning data you will have key pairs to work with but the results are not exactly the same.

Code:
"results":[ [ 8 ], [ 4 ], [ 2 ], [ 9 ] ],


how can i return the number?

Shaun 27th October 2020 12:25 PM

Here is an almost finished project exe, it is missing a few things like race start time and results and maybe some instructions.

Just run it, select "Today" or "Tomorrow" highlight the "M-Code" for the meeting you want then put in a race number and press "Get Race"

It gives you some info in regards to ratings used on tab site, i also noted they show the same fixed prices for all the sites.

This is the first program i have written in like 30 years and the first in python, it may be a simple program to some but i am pretty pleased with my efforts as it gave me a better understanding of python i guess, the source code is not pretty and am sure it could be tidied up as there are a few errors.

the program is in my One Drive folder in my signature called "Tab_Prices" there is also a text doc with the python code in there.

Shaun 28th October 2020 12:48 AM

I added a 30 second refresh, you can still switch races.

Shaun 7th November 2020 08:15 AM

This program now collects the results if known and updates every 15 seconds, i would like to colour code the results 1st to 4th, i have tried a few ways but unsuccessful, i have updated the code script if anyone has ideas.

I noticed a bug, will update file when fixed

Playlife 7th November 2020 04:21 PM

Quote:
Originally Posted by Shaun
Here is an almost finished project exe, it is missing a few things like race start time and results and maybe some instructions.

Just run it, select "Today" or "Tomorrow" highlight the "M-Code" for the meeting you want then put in a race number and press "Get Race"

It gives you some info in regards to ratings used on tab site, i also noted they show the same fixed prices for all the sites.

This is the first program i have written in like 30 years and the first in python, it may be a simple program to some but i am pretty pleased with my efforts as it gave me a better understanding of python i guess, the source code is not pretty and am sure it could be tidied up as there are a few errors.

the program is in my One Drive folder in my signature called "Tab_Prices" there is also a text doc with the python code in there.



EDIT, I do apologise, this only seems to work for VIC.


Hi Shaun, great job.

Unfortunately the move to this new API killed my excel/VBA work as well. I'm new to python, slowly learning the ropes.

It is as clunky as hell, and is manually coded, but using your script I have added the start time. Programmers will wince at how bad this is (sorry!). There's easier ways to do timezone conversions so I have read but cannot wrap my head around it yet.


**** inserted into # race info ****
race_StartTime = race1["raceStartTime"]
****
d1 = datetime.datetime.strptime(race_StartTime,"%Y-%m-%dT%H:%M:%S.%fZ")
new_format = "%H:%M"
HourOnly = "%H"
MinuteOnly = "%M"
Hour = str(int(d1.strftime(HourOnly))+11) # This is for Victoria AEDT (+11 hrs GMT)
Minute = d1.strftime(MinuteOnly)
race_StartTime = "Jump:" + Hour + ":" + Minute

raceStartTime = Label(inputFrame, text=str(race_StartTime), width=25, bg="darkblue", fg="white", font=("bold", 11), anchor=W)
raceStartTime.grid(row=0, column=20)

****

Shaun 7th November 2020 11:31 PM

Quote:
Originally Posted by Playlife
EDIT, I do apologise, this only seems to work for VIC.


Hi Shaun, great job.

Unfortunately the move to this new API killed my excel/VBA work as well. I'm new to python, slowly learning the ropes.

It is as clunky as hell, and is manually coded, but using your script I have added the start time. Programmers will wince at how bad this is (sorry!). There's easier ways to do timezone conversions so I have read but cannot wrap my head around it yet.


**** inserted into # race info ****
race_StartTime = race1["raceStartTime"]
****
d1 = datetime.datetime.strptime(race_StartTime,"%Y-%m-%dT%H:%M:%S.%fZ")
new_format = "%H:%M"
HourOnly = "%H"
MinuteOnly = "%M"
Hour = str(int(d1.strftime(HourOnly))+11) # This is for Victoria AEDT (+11 hrs GMT)
Minute = d1.strftime(MinuteOnly)
race_StartTime = "Jump:" + Hour + ":" + Minute

raceStartTime = Label(inputFrame, text=str(race_StartTime), width=25, bg="darkblue", fg="white", font=("bold", 11), anchor=W)
raceStartTime.grid(row=0, column=20)

****


Cheers, this is the same reason i didn't add the time as yet because of time zones, but anyone could adjust this code to suit there own time zone, that issue i was having with the bug had to do with refreshing, the problem i had was when you change races it started another time refresh sequence, probably a simple fix when i work it out.

chook 10th November 2020 07:21 AM

cookbook
 
O'Reilley python cookbook 3 Beazley & Jones
advise using UTC for your time calcs and then moving to local timezone.

chapter 3.16, P 110 in third ed.

from datetime import datetime
#get your UTC date time
dt = datetime(2020,12,20,9,31,22)

from pytz import timezone
nsw = timezone( 'Australia/NSW' )
# = nsw.localize( your UTC date time )
ndt = nsw.localize( dt )

an alternative is to use Queensland time and check to see if you are in summer, by looking at your localtime.
i have done that before
or, move to Queensland

gsdanger 10th November 2020 03:38 PM

Tab_Prices - On your One Drive (Shaun)...
 
Hi Shaun,
Good to see you are progressing very well with the new python programming language.
You have made the python file available on your One Drive..That's great.!
My problem is that I cannot locate your One drive option here.(I had this problem a while ago, and you sent me a direct link to your drive, which allowed me to access the drive).
Can you please supply me with the link to your drive, so I can access the "TAB_Prices" file.

I am looking forward to using it and maybe assisting with enhancing it, although I am in the infancy of using the python language.

Please advise....Kind regards.

gsdanger

gsdanger 10th November 2020 10:20 PM

Tab_Prices - On your One Drive (Shaun)...
 
Hi Shaun,

Further to my last post...I managed to find a path to your One Drive...Hooray!

I assume the code needs to be downloaded and installed into the python area. (excuse my dumbness...).

Please advise.......Again please excuse my Dumbness....
Kind Regards....gsdanger

Shaun 11th November 2020 09:10 PM

As long as you have python 3 installed you can copy this code to your IDE or text editor and it should run the same as any code you use, you will need to be sure you have all the modules listed in import, i use Annaconda this has everything installed already.

gsdanger 12th November 2020 10:09 AM

TAB_Prices
 
Hi Shaun,
Thanks for your prompt response.
Thanks for this info. I have python and Anaconda installed, so I will cut and paste the code into my text editor and go from there.
You have done a great job in addressing the Unitab de-commissioning.
Shaun, is this new code for form analysis, or live price usage?

Kind Regards...

Please advise....gsdanger

Shaun 13th November 2020 10:40 AM

Just for live pricing and results for now, i did see a link for form but haven't had the time to investigate what it offers, as i have said in an earlier post i was trying to create an all in one app but you could still download this data to excel, there is lots of info on how to get data in to and out of excel on youtube.

Shaun 18th December 2020 01:36 AM

I just fixed some issues with this program, if you click my one drive link there is a folder "Tab Prices" contains 2 items, one is TabPrices.exe that is the app, download it, open it up, click on "Today" or "Tomorrow" select your meeting by clicking the "M-Code" type the race number in the box and press "Get Race" the race info will be displayed, if the race has been run you will see the top 4 places listed.

To select another race just put in another number and press the button or you can select a new meeting with the M-Code.

This version doesn't auto refresh, i am still working on that one, just press "Get Race" to refresh current race.

gsdanger 19th December 2020 10:49 AM

Where is you One Drive Path?....again...
 
Hi Shaun,

You have made your python file available on your One Drive..That's great.!
My problem is that I cannot locate your One drive option here.(I had this problem a while ago, and you sent me a direct link to your drive, which allowed me to access the drive).
I still cannot work out why I cannot see your One Drive option.....beats me!!!
Can you please supply me with the link to your drive, so I can access the "TAB_Prices" file.

Please advise....Kind regards.

gsdanger

walkermac 19th December 2020 09:24 PM

Quote:
Originally Posted by gsdanger
Hi Shaun,

You have made your python file available on your One Drive..That's great.!
My problem is that I cannot locate your One drive option here.(I had this problem a while ago, and you sent me a direct link to your drive, which allowed me to access the drive).
I still cannot work out why I cannot see your One Drive option.....beats me!!!
Can you please supply me with the link to your drive, so I can access the "TAB_Prices" file.

Please advise....Kind regards.

gsdanger
The link is in his signature. I think you may have played around with your user options so that it doesn't appear for you. Try this:
  • Scroll up to the top of the page
  • At the top left of the Menu Bar going across the page is the 'User CP' link (http://www.ozmium.com.au/forums/usercp.php?); click it
  • On the resulting page, the Control Panel options are listed down the left. In the 'Settings & Options' section, click on the 'Edit Options' link (http://www.ozmium.com.au/forums/pro...?do=editoptions)
  • Once the new page loads, scroll down to the 'Thread Display Options' section. Ensure each of the checkboxes under 'Visible Post Elements' are selected
  • Scroll to the bottom of the page and click the 'Save Changes' button

gsdanger 20th December 2020 08:18 AM

Where is you One Drive Path?....again...
 
To Walkerman....Thank you for your expert advice, education and direction.
I now have visibility of the One Drive options.

Have a great day, and Christmas greetings to you, Shaun and all other forum users.

Regards...gsdanger

Shaun 20th December 2020 11:25 PM

Quote:
Originally Posted by gsdanger
To Walkerman....Thank you for your expert advice, education and direction.
I now have visibility of the One Drive options.

Have a great day, and Christmas greetings to you, Shaun and all other forum users.

Regards...gsdanger


Glad you got it sorted, thanks Walkerman

The only thing left on this program to do is get the auto refresh sorted, although my code is sloppy i have learned a great deal.

Looking forward to my next project.

Shaun 26th December 2020 03:11 PM

There are a couple bug fixes that i made while testing, i won't post everythime i make a change but i have added a version number that represents the date i make changes, so if any one is interested in keeping up with this or any other project i may do just compare what version you have with the current one, i did update the code posted also here.

Shaun 15th January 2021 01:09 AM

I have made a couple updates, the current program uses the T/Points as a rating and converts them to a price R/Price so you can look for overs or unders in the top couple runners.

I also found an api link to the form so i can start adding form information.

Martinw 19th January 2021 01:36 AM

TAB api
 
Have TAB changed their conditions for accessing their api? On their webpage they have an application form in order to connect to TAB. I applied a few years ago but got refused with no explanation.

Looking again, under How it works the api seems to be available.
So what is happening?
Any clarification would be great.
I am still using the Tatts api but TAB have turned off the account features and so I cannot place bets automatically.
Ta,
Martin

Shaun 19th January 2021 01:45 PM

I haven't looked at placing bets but i know i have access to all prices and form, this is just my experiment in learning to program a functional replacement for excel as i still use gruss to place my bets.

For the moment i am providing all my python code so others can learn.

Martinw 19th January 2021 03:28 PM

Re TAB
 
Thanks for that. I will look at moving across to TAB's api as soon as I can. Ta, Martin

ballybeg 19th January 2021 04:43 PM

The TAB api is accessible to pull down race data and odds and so on, but to place bets - and any access to the accounting api - you need to be approved by TAB - you will be given a client token that is used to create access tokens each time you place a bet.


When it started you needed to be Silver or (Gold?) status to get betting access to the api - that meant turnover of about $25k per year.

Not sure what the situation is now :confused:

Martinw 23rd January 2021 02:15 PM

Thanks for that. I don't want to have to throw 25k down the loo on bets I am not sure of. And I do not want to sit at my computer all day, every day to use my software and place bets manually. They have made it too hard if that is still the case. Ta, Martin

Shaun 5th March 2021 11:31 AM

I am slowly getting python to replace what i used to do in excel, so far i can pull race data and results info, i can also get past form but only what is available on race day but still useful, i have also implemented one of my black book systems to make selections and print out those selections to txt doc.

i am having one issue when getting results if they are not available it throws a KeyError

I have looked at a few options for this error but none work, all i need is if no results just to skip this section, the program still runs regardless but better to not have errors i guess.

Code:
def check_results(): global res1, res2, res3, res4 urlR = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings/R/" + \ str(listbox1.get(ANCHOR)) + "/races/" + str(venue_numberbox.get()) + "?jurisdiction=NSW" result = requests.get(urlR) result1 = json.loads(result.content) res1 = "" res2 = "" res3 = "" res4 = "" try: res1 = result1["results"][0][0] except IndexError: pass try: res2 = result1["results"][1][0] except IndexError: pass try: res3 = result1["results"][2][0] except IndexError: pass try: res4 = result1["results"][3][0] except IndexError: pass return def results1(): global res, colour colour = "black" try: if res == "1st": colour = "darkgreen" except KeyError: pass try: if res == "2nd": colour = ("gold") except KeyError: pass try: if res == "3rd": colour = ("blue") except KeyError: pass try: if res == "4th": colour = ("purple") except KeyError: pass listbox3.itemconfig(END, fg=colour) listbox4.itemconfig(END, fg=colour) listbox5.itemconfig(END, fg=colour) listbox6.itemconfig(END, fg=colour) listbox7.itemconfig(END, fg=colour) listbox8.itemconfig(END, fg=colour) listbox9.itemconfig(END, fg=colour) listbox10.itemconfig(END, fg=colour) listbox11.itemconfig(END, fg=colour) listbox12.itemconfig(END, fg=colour) listbox13.itemconfig(END, fg=colour) listbox14.itemconfig(END, fg=colour) listbox15.itemconfig(END, fg=colour) listbox16.itemconfig(END, fg=colour) listbox17.itemconfig(END, fg=colour) listbox18.itemconfig(END, fg=colour) listbox25.itemconfig(END, fg=colour)

chook 13th March 2021 04:42 AM

Shaun: try colour like this?
a_res = **** "1st":'darkgreen', "2nd":'gold', "3rd":'blue', "4th":'purple' ****

colour = 'black'
if res in a_res:
colour = a_res[res]

key error happens if your key is not in the dictionary.

Shaun 16th May 2021 11:06 PM

Time for an update.

I have spent many hours practicing my python skills, my work is pretty average but functional.

my latest creation that can be found in my link is "BSP - 16-05-21" there is an exe plus a txt with code.

As with my other programs this will allow you to access the TAB website and gather race info, it collects race results if known.

I have included 5 systems, these aren't the holy grail but more ideas on what is possibly with python and some imagination.

The program prints out the system bets in a format that can be imported to excel, i also included a timezone list so races are listed in your timezone.

There is an info tab that explains how to run things.

have fun and any thoughts appreciated.


All times are GMT +10. The time now is 08:07 AM.

Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.