5th March 2021, 10:31 AM
|
Member
|
|
Join Date: Jan 1970
Location: Western Australia
Posts: 3,457
|
|
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)
__________________
One Drive
"If the corporates are treating you poorly , just go elsewhere."
"If they need you , they will soon find out."
"If you need them , you will soon find out." --moeee
_______________________________________________
|