From 02daa21adcbdc911d85cfe3f608236dc5d850e32 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 23 Mar 2023 16:30:58 +0800 Subject: [PATCH] liv golf --- database_caller.py | 68 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/database_caller.py b/database_caller.py index 7a53641..f68b66f 100755 --- a/database_caller.py +++ b/database_caller.py @@ -845,7 +845,7 @@ def updateLeagueEvents(api_key, time, logf): for league in all_data.keys(): ten_or_fifteen = slice(None) events = [] - if (league == 'PGA') or (league == 'LPGA') or (league == 'PGA_EU'): + if (league == 'PGA') or (league == 'LPGA') or (league == 'PGA_EU') or (league == 'LIV'): ten_or_fifteen = slice(3) else: ten_or_fifteen = slice(None) @@ -857,7 +857,7 @@ def updateLeagueEvents(api_key, time, logf): event['progess'] = d['strProgress'] event['status'] = d['strStatus'] else: - if (league == 'PGA') or (league == 'LPGA') or (league == 'PGA_EU'): + if (league == 'PGA') or (league == 'LPGA') or (league == 'PGA_EU') or (league == 'LIV'): event['date'] = d['dateEvent'] event['event'] = d['strEvent'].replace("\u2019","'") event['venue'] = d['strVenue'].replace("\u2019","'") @@ -906,6 +906,60 @@ def updateLeagueEvents(api_key, time, logf): players.append(result.rstrip()) event['golf_standings'] = players + + + elif (league == 'LIV'): + event['golf_standings'] = d['strResult'] + + rank = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6', 'n7', 'n8', 'n9', 'n10', 'T1', 'T2', 'T3', 'T4', 'T5', + 'T6', 'T7', 'T8', 'T9', 'T10'] + + def convert(string): + string = repr(string).replace('/', '') + li = list(string.split('\\')) + return li + + try: + str3 = convert(event['golf_standings'].split('--------------------------------------')[0]) + strTeams = convert(event['golf_standings'].split('--------------------------------------')[1]) + except: + pass + + players = [] + teams = [] + + try: + for each in str3: + each = each.replace('nT', 'T', 1) + if each[:2] in rank: + try: + first_space = each.find(' ', 1) + second_space = each.find(' ', 4) + first_name = each[first_space:second_space].lstrip() + initial = first_name[0] + '.' + each = each.replace(first_name,initial) + except: + pass + interator = each.find('-') + if interator < 0: + interator = 0 + interator2 = each[interator:interator + 3] + result = each.split(interator2, 1)[0] + interator2 + players.append(result.rstrip()) + + for each in strTeams: + each = each.replace('nT', 'T', 1) + if each[:2] in rank: + each = each.split('GC') + score = each[1].rfind('-') + score2 = each[1][score:score+3] + each2 = each[0] + score2 + teams.append(each2) + except: + pass + + event['golf_standings'] = [players] + [teams] + else: event['away_score'] = d['intAwayScore'] event['home_score'] = d['intHomeScore'] @@ -919,15 +973,7 @@ def updateLeagueEvents(api_key, time, logf): f.close() except: pass - #logf = open('log.txt', "a") - #exc_type, exc_obj, exc_tb = sys.exc_info() - #fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] - #logf.write(str(e)) - #logf.write('. file: ' + fname) - #logf.write('. line: ' + str(exc_tb.tb_lineno)) - #logf.write('. type: ' + str(exc_type)) - #logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))) - #logf.close() + def updateSports(api_key, logf):