diff --git a/database_caller.py b/database_caller.py index 39178e2..0f43ce2 100755 --- a/database_caller.py +++ b/database_caller.py @@ -5,6 +5,8 @@ # This code can not be copied and/or distributed without the express # permission of Fintic +import random +import pickle import finnhub import time import csv @@ -85,49 +87,37 @@ def updateUpdate(NY_time): -def updateStocks(api_key, logf): - - - try: - - - max_stocks = 200 - - f = open('csv/stocks_settings.json', 'r') - all_stocks_settings = json.load(f) - f.close() - stock_info = all_stocks_settings['symbols'] - symbols = list(stock_info.keys()) +# def updateStocks(api_key, logf): +# try: +# f = open('csv/stocks_settings.json', 'r') +# all_stocks_settings = json.load(f) +# f.close() +# stock_info = all_stocks_settings['symbols'] +# symbols = list(stock_info.keys()) - - url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/stocks?symbols=' +# url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/stocks?symbols=' - for symbol in symbols: - url += symbol + ',' +# for symbol in symbols: +# url += symbol + ',' - url += '&apiKey=' + api_key - response = requests.get(url) - data = response.json() - - - # stock_info = {} - if len(data) > 0: - for symbol in symbols: - for stock in data: - if stock['symbol'] == symbol: - stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']} - - - all_stocks_settings['symbols'] = stock_info - - - f = open('csv/stocks_settings.json', 'w+') - json.dump(all_stocks_settings, f) - f.close() +# url += '&apiKey=' + api_key +# response = requests.get(url) +# data = response.json() - except: - pass - +# # stock_info = {} +# if len(data) > 0: +# for symbol in symbols: +# for stock in data: +# if stock['symbol'] == symbol: +# stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']} + +# all_stocks_settings['symbols'] = stock_info +# f = open('csv/stocks_settings.json', 'w+') +# json.dump(all_stocks_settings, f) +# 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] @@ -139,10 +129,107 @@ def updateStocks(api_key, logf): #logf.close() -def updateStocksPrePost(api_key, logf): +def getCookiesnCrumb(): + headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'} + cookie_url = 'https://finance.yahoo.com' + crumb_url = 'https://query1.finance.yahoo.com/v1/test/getcrumb' + + session = requests.Session() + session.get(cookie_url, headers=headers) + crumb = session.get(crumb_url, headers=headers).content.decode('utf-8') + + with open('session.txt', 'wb') as f: + pickle.dump(session, f) + with open('crumb.txt', 'w') as f: + f.write(crumb) + + +def updateStocks(api_key, logf): + try: + f = open('csv/stocks_settings.json', 'r') + all_stocks_settings = json.load(f) + f.close() + stock_info = all_stocks_settings['symbols'] + symbols = list(stock_info.keys()) + + headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'} + # url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/stocks?symbols=' + url1 = 'https://query1.finance.yahoo.com/v7/finance/quote?fields=regularMarketPrice,regularMarketChangePercent,regularMarketChange®ion=US&lang=en-US&symbols=' + url2 = 'https://cloud.iexapis.com/v1/stock/market/batch?&types=quote&token=pk_aff870df1a984daa9dd43c71801c1936&symbols=' + url = random.choice([url1, url2]) + + for symbol in symbols: + url += symbol + ',' + # url += '&apiKey=' + api_key + + if 'cloud.iexapis.com' in url: + response = requests.get(url, headers=headers) + data = response.json() + if len(data) > 0: + for symbol in symbols: + stock_info[data[symbol]['quote']['symbol']] = {'current': data[symbol]['quote']['latestPrice'], 'change': data[symbol]['quote']['change'], 'percent_change':data[symbol]['quote']['changePercent'] * 100} + + all_stocks_settings['symbols'] = stock_info + f = open('csv/stocks_settings.json', 'w+') + json.dump(all_stocks_settings, f) + f.close() + + elif 'query1.finance.yahoo.com/v7' in url: + response = requests.get(url, headers=headers) + data = response.json() + if "'error': {'code'" in str(data): + while True: + try: + with open('session.txt', 'rb') as f: + session = pickle.load(f) + with open('crumb.txt', 'r') as f: + crumb = f.read() + except: + getCookiesnCrumb() + with open('session.txt', 'rb') as f: + session = pickle.load(f) + with open('crumb.txt', 'r') as f: + crumb = f.read() + params = {'crumb': crumb} + + data = session.get(url, headers=headers, params=params).json() + + if "'error': {'code'" not in str(data): + break + else: + getCookiesnCrumb() + time.sleep(5) + # stock_info = {} + if len(data) > 0: + for symbol in symbols: + for stock in data['quoteResponse']['result']: + if stock['symbol'] == symbol: + stock_info[stock['symbol']] = {'current': stock['regularMarketPrice'], 'change': stock['regularMarketChange'], 'percent_change':stock['regularMarketChangePercent']} + + all_stocks_settings['symbols'] = stock_info + f = open('csv/stocks_settings.json', 'w+') + json.dump(all_stocks_settings, f) + 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 updateStocksPrePost(api_key, logf): + try: f = open('csv/stocks_settings.json', 'r') all_stocks_settings = json.load(f) f.close() @@ -150,21 +237,40 @@ def updateStocksPrePost(api_key, logf): symbols = list(stock_info.keys()) #KEEP THIS JUST IN CASE V7 GOES DOWN prepost_url = 'https://query2.finance.yahoo.com/v6/finance/quote?symbols=' - prepost_url = 'https://query2.finance.yahoo.com/v7/finance/quote?symbols=' + prepost_url = 'https://query2.finance.yahoo.com/v6/finance/quote?symbols=' for symbol in symbols: prepost_url += symbol + ',' prepost_url += '&fields=regularMarketPreviousClose,regularMarketPrice,preMarketPrice,preMarketChangePercent,regularMarketChangePercent,regularMarketChange,preMarketChange,postMarketPrice,postMarketChange,postMarketChangePercent®ion=US&lang=en-US' - headers = { - 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' - } - prepost = requests.get(prepost_url, headers=headers) + headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'} + + prepost = requests.get(prepost_url, headers=headers).json() + if "'error': {'code'" in str(prepost): + while True: + try: + with open('session.txt', 'rb') as f: + session = pickle.load(f) + with open('crumb.txt', 'r') as f: + crumb = f.read() + except: + getCookiesnCrumb() + with open('session.txt', 'rb') as f: + session = pickle.load(f) + with open('crumb.txt', 'r') as f: + crumb = f.read() + params = {'crumb': crumb} + + prepost = session.get(prepost_url.replace('v6','v7'), headers=headers, params=params).json() + + if "'error': {'code'" not in str(prepost): + break + else: + getCookiesnCrumb() + time.sleep(5) - if 'Unauthorized' in str(prepost.json()): - prepost = requests.get(prepost_url.replace('v7','v6'), headers=headers) - - prepost_data = prepost.json()['quoteResponse']['result'] + prepost_data = prepost['quoteResponse']['result'] time_now = datetime.now(pytz.timezone('America/New_York')).strftime("%H:%M EST") if len(prepost_data) > 0: @@ -198,7 +304,6 @@ def updateStocksPrePost(api_key, logf): with open('csv/prepost_settings.json', 'w+') as f: json.dump(all_stocks_settings['symbols'], f) - except: pass @@ -661,74 +766,82 @@ def updateNews(api_key, logf): def updateWeather(api_key, logf): - max_cities = 30 - try: gn = geocoders.GeoNames(username='fintic') - + weather_codes = { + 0: ['Clear', 'Clear sky'], + 1: ['Clouds', 'few clouds'], 2: ['Clouds', 'scattered clouds'], 3: ['Clouds', 'overcast clouds'], + 45: ['Fog', 'Fog'], 48: ['Fog', 'depositing rime fog'], + 51: ['Drizzle', 'Light'], 53: ['Drizzle', 'moderate'], 55: ['Drizzle', 'dense'], 56: ['Drizzle', 'light'], 57: ['Drizzle', 'dense'], + 61: ['Rain', 'light rain'], 63: ['Rain', 'moderate rain'], 65: ['Rain', 'very heavy rain'], + 66: ['Rain', 'freezing rain'], 67: ['Rain', 'freezing rain'], + 71: ['Snow', 'slight'], 73: ['Snow', 'moderate'], 75: ['Snow', 'heavy'], 77: ['Snow', 'Snow grains'], 85: ['Snow', 'slight'], 86: ['Snow', 'heavy'], + 80: ['Rain', 'light intensity shower rain'], 81: ['Rain', 'shower rain'], 82: ['Rain', 'heavy intensity shower rain'], + 95: ['Thunderstorm', 'Slight or moderate'], 96: ['Thunderstorm', 'slight hail'], 99: ['Thunderstorm', 'heavy hail'] + } f = open('csv/daily_weather.json', 'r') all_daily_settings = json.load(f) f.close() - f = open('csv/current_weather.json', 'r') all_current_settings = json.load(f) f.close() - + current_locations = list(all_current_settings['locations'].keys()) daily_locations = list(all_daily_settings['locations'].keys()) - all_locations = list(set(current_locations + daily_locations)) - - - - + current_weathers = {} daily_weathers = {} - - - + for location in all_locations: loc = gn.geocode(location) current_weather = {} - + lat = loc.latitude lon = loc.longitude - url = 'https://api.openweathermap.org/data/2.5/onecall?lat={}&units=metric&lon={}&appid={}'.format(lat, lon, api_key) - r = requests.get(url) - - weather = r.json()['current'] - - current_weather['main_weather'] = weather['weather'][0]['main'] - current_weather['description'] = weather['weather'][0]['description'] - current_weather['temp'] = weather['temp'] - current_weather['min_temp'] = r.json()['daily'][0]['temp']['min'] - current_weather['max_temp'] = r.json()['daily'][0]['temp']['max'] - current_weather['feels_like'] = weather['feels_like'] - current_weather['humidity'] = weather['humidity'] - current_weather['clouds'] = weather['clouds'] - current_weather['wind_speed'] = weather['wind_speed'] - current_weather['wind_direction'] = weather['wind_deg'] - current_weather['visibility'] = weather['visibility'] - current_weather['uv'] = weather['uvi'] - current_weather['rain_chance'] = r.json()['hourly'][0]['pop'] - - + url = 'https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}&hourly=apparent_temperature,temperature_2m,relativehumidity_2m,precipitation_probability,weathercode,cloudcover,visibility,windspeed_10m,winddirection_10m,uv_index,is_day&daily=weathercode,temperature_2m_max,temperature_2m_min¤t_weather=true&timezone=UTC'.format(lat, lon) + r = requests.get(url).json() + + times = r['hourly']['time'] + hour_now = datetime.now(pytz.utc).strftime('%Y-%m-%dT%H:00') + index_pos = times.index(hour_now) + + main_weather_code = r['hourly']['weathercode'][index_pos] + current_weather['main_weather'] = weather_codes[main_weather_code][0] + current_weather['description'] = weather_codes[main_weather_code][1] + current_weather['temp'] = r['hourly']['temperature_2m'][index_pos] + current_weather['min_temp'] = r['daily']['temperature_2m_min'][0] + current_weather['max_temp'] = r['daily']['temperature_2m_max'][0] + current_weather['feels_like'] = r['hourly']['apparent_temperature'][index_pos] + current_weather['humidity'] = r['hourly']['relativehumidity_2m'][index_pos] + current_weather['clouds'] = r['hourly']['cloudcover'][index_pos] + if r['hourly']['visibility'][index_pos] > 10000: + current_weather['visibility'] = 10000 + else: + current_weather['visibility'] = r['hourly']['visibility'][index_pos] + current_weather['uv'] = r['hourly']['uv_index'][index_pos] + current_weather['rain_chance'] = r['hourly']['precipitation_probability'][index_pos] + current_weather['wind_speed'] = r['hourly']['windspeed_10m'][index_pos] + current_weather['wind_direction'] = r['hourly']['winddirection_10m'][index_pos] + current_weather['is_day'] = r['hourly']['is_day'][index_pos] + if location in current_locations: current_weathers[location] = current_weather - + daily_weather = [] - daily = r.json()['daily'] - - for day in daily: + daily = r['daily'] + + for i in range(0,7): dct = {} - dct['main_weather'] = day['weather'][0]['main'] - dct['description'] = day['weather'][0]['description'] - dct['min_temp'] = day['temp']['min'] - dct['max_temp'] = day['temp']['max'] + daily_weather_code = daily['weathercode'][i] + dct['main_weather'] = weather_codes[daily_weather_code][0] + dct['description'] = weather_codes[daily_weather_code][1] + dct['min_temp'] = daily['temperature_2m_min'][i] + dct['max_temp'] = daily['temperature_2m_max'][i] daily_weather.append(dct) - - #add relevant urrent information to first day in daily - daily_weather[0]['temp'] = weather['temp'] + + # add relevant urrent information to first day in daily + daily_weather[0]['temp'] = current_weather['temp'] daily_weather[0]['rain_chance'] = current_weather['rain_chance'] daily_weather[0]['humidity'] = current_weather['humidity'] daily_weather[0]['wind_speed'] = current_weather['wind_speed'] @@ -737,22 +850,20 @@ def updateWeather(api_key, logf): daily_weather[0]['wind_speed'] = current_weather['wind_speed'] daily_weather[0]['wind_direction'] = current_weather['wind_direction'] daily_weather[0]['visibility'] = current_weather['visibility'] - + if location in daily_locations: daily_weathers[location] = daily_weather - - all_current_settings['locations'] = current_weathers all_daily_settings['locations'] = daily_weathers - f = open( "csv/current_weather.json", 'w+' ) - json.dump( all_current_settings, f) + f = open("csv/current_weather.json", 'w+') + json.dump(all_current_settings, f) f.close() - - f = open( "csv/daily_weather.json", 'w+' ) - json.dump( all_daily_settings, f) + + f = open("csv/daily_weather.json", 'w+') + json.dump(all_daily_settings, f) f.close() - + except: pass #logf = open('log.txt', "a") @@ -791,30 +902,55 @@ def updateLeagueTables(api_key, logf): all_data = r.json() - - for i,l in enumerate(all_data): - league = list(l.keys())[0] - - teams = [] - - - for d in all_data[i][league]: - team = {} - - - - team['name'] = d['strTeam'] - team['wins'] = d['intWin'] - team['loss'] = d['intLoss'] - team['draw'] = d['intDraw'] - #team['played'] = d['intPlayed'] - team['standing'] = d['intRank'] - #team['points'] = d['intPoints'] - - teams.append(team) + if league == 'pga' or league == 'lpga': + logo_files = [] + for d in all_data[i][league]: + del d['_id'], d['updated'] + teams.append(d) + try: + if d['country'].split('/')[-1].split('&')[0] not in os.listdir('logos/ufc_countries/'): + urllib.request.urlretrieve(d['country'], 'logos/ufc_countries/' + d['country'].split('/')[-1].split('&')[0]) + except: + pass + try: + if league == 'pga': + if d['photo'].split('/')[-1].split('&')[0] not in os.listdir('logos/pga_rank/'): + urllib.request.urlretrieve(d['photo'],'logos/pga_rank/' + d['photo'].split('/')[-1].split('&')[0]) + elif league == 'lpga': + if d['photo'].split('/')[-1] not in os.listdir('logos/lpga_rank/'): + urllib.request.urlretrieve(d['photo'],'logos/lpga_rank/' + d['photo'].split('/')[-1]) + except: + pass + try: + if league == 'pga': + logo_files.append(d['photo'].split('/')[-1].split('&')[0]) + elif league == 'lpga': + logo_files.append(d['photo'].split('/')[-1]) + except: + pass + if league == 'pga': + for file in os.listdir('logos/pga_rank/'): + if file not in logo_files: + os.remove('logos/pga_rank/'+ file) + elif league == 'lpga': + for file in os.listdir('logos/lpga_rank/'): + if file not in logo_files: + os.remove('logos/lpga_rank/'+ file) + else: + for d in all_data[i][league]: + team = {} + team['name'] = d['strTeam'] + team['wins'] = d['intWin'] + team['loss'] = d['intLoss'] + team['draw'] = d['intDraw'] + #team['played'] = d['intPlayed'] + team['standing'] = d['intRank'] + #team['points'] = d['intPoints'] + teams.append(team) + leagues_info[league.upper()] = teams all_settings['leagues'] = leagues_info @@ -1041,6 +1177,12 @@ def updateLeagueEvents(api_key, time, logf): event['date2'] = d['dateEvent2'] except: pass + try: + event['total_yards'] = d['total_yards'] + event['shots_par'] = d['shots_par'] + event['purse'] = d['purse'] + except: + pass event['event'] = d['strEvent'].replace("\u2019","'") event['venue'] = d['strVenue'].replace("\u2019","'") event['city'] = d['strCity'].replace("\u2019","'") @@ -1054,98 +1196,107 @@ def updateLeagueEvents(api_key, time, logf): if time != 'upcoming': if (league == 'PGA') or (league == 'LPGA') or (league == 'PGA_EU'): - event['golf_standings'] = d['strResult'] + # event['golf_standings'] = d['strResult'] + event['golf_rankings'] = d['player_results'] + for player in event['golf_rankings']: + try: + if player['country'].split('/')[-1].split('&')[0] not in os.listdir('logos/ufc_countries/'): + urllib.request.urlretrieve(player['country'], 'logos/ufc_countries/' + player['country'].split('/')[-1].split('&')[0]) + except: + pass + # 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 - rank = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6', 'n7', 'n8', 'n9', 'n10', 'T1', 'T2', 'T3', 'T4', 'T5', - 'T6', 'T7', 'T8', 'T9', 'T10'] + # str3 = convert(event['golf_standings']) - def convert(string): - string = repr(string).replace('/', '') - li = list(string.split('\\')) - return li - - str3 = convert(event['golf_standings']) - - players = [] + # players = [] - 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 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()) - event['golf_standings'] = players + # event['golf_standings'] = players elif (league == 'LIV'): - event['golf_standings'] = d['strResult'] + # event['golf_standings'] = d['strResult'] + event['golf_rankings'] = d['player_results'] + for player in event['golf_rankings']: + try: + if player['country'].split('/')[-1].split('&')[0] not in os.listdir('logos/ufc_countries/'): + urllib.request.urlretrieve(player['country'], 'logos/ufc_countries/' + player['country'].split('/')[-1].split('&')[0]) + except: + pass + # 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 - rank = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6', 'n7', 'n8', 'n9', 'n10', 'T1', 'T2', 'T3', 'T4', 'T5', - 'T6', 'T7', 'T8', 'T9', 'T10'] + # try: + # str3 = convert(event['golf_standings'].split('--------------------------------------')[0]) + # strTeams = convert(event['golf_standings'].split('--------------------------------------')[1]) + # except: + # pass - def convert(string): - string = repr(string).replace('/', '') - li = list(string.split('\\')) - return li + # players = [] + # teams = [] - try: - str3 = convert(event['golf_standings'].split('--------------------------------------')[0]) - strTeams = convert(event['golf_standings'].split('--------------------------------------')[1]) - except: - pass + # 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()) - 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+4] - each2 = each[0] + score2 - teams.append(each2) - except: - pass - - event['golf_standings'] = [players] + [teams] + # 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+4] + # 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'] - + events.append(event) leagues_info[league.upper()] = events all_settings['leagues'] = leagues_info diff --git a/logos/lpga_rank/blank.rtf b/logos/lpga_rank/blank.rtf new file mode 100644 index 0000000..15e538c --- /dev/null +++ b/logos/lpga_rank/blank.rtf @@ -0,0 +1,6 @@ +{\rtf1\ansi\ansicpg1252\cocoartf2513 +\cocoatextscaling0\cocoaplatform0{\fonttbl} +{\colortbl;\red255\green255\blue255;} +{\*\expandedcolortbl;;} +\margl1440\margr1440\vieww10800\viewh8400\viewkind0 +} \ No newline at end of file diff --git a/logos/pga_rank/blank.rtf b/logos/pga_rank/blank.rtf new file mode 100644 index 0000000..15e538c --- /dev/null +++ b/logos/pga_rank/blank.rtf @@ -0,0 +1,6 @@ +{\rtf1\ansi\ansicpg1252\cocoartf2513 +\cocoatextscaling0\cocoaplatform0{\fonttbl} +{\colortbl;\red255\green255\blue255;} +{\*\expandedcolortbl;;} +\margl1440\margr1440\vieww10800\viewh8400\viewkind0 +} \ No newline at end of file diff --git a/logos/sports/league_logos/lpga_1.png b/logos/sports/league_logos/lpga_1.png new file mode 100644 index 0000000..e73c753 Binary files /dev/null and b/logos/sports/league_logos/lpga_1.png differ diff --git a/logos/sports/league_logos/pga_1.png b/logos/sports/league_logos/pga_1.png new file mode 100644 index 0000000..cae5efc Binary files /dev/null and b/logos/sports/league_logos/pga_1.png differ diff --git a/server.py b/server.py index dc089a5..60187c9 100755 --- a/server.py +++ b/server.py @@ -146,8 +146,8 @@ def index(): not_displaying = [f for f in all_features if f not in currently_displaying[0]] not_displaying2 = [f for f in all_features if f not in currently_displaying[1]] - with open('api_keys.txt', 'r') as f: - api_key2 = f.readlines() +# with open('api_keys.txt', 'r') as f: +# api_key2 = f.readlines() try: with open('movie_api_key.txt', 'r') as f: @@ -248,10 +248,10 @@ def index(): except: scheduler_settings = {"shutdown": {"hour": "00", "minute": "00", "enabled": False}, "reboot":{"hour": "00", "minute": "00", "enabled": False}, "timezone": "GMT", "brightness1":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness2":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness3":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness4":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}} - try: # incase this doesnt exist - api_keys = api_key2[1] - except: - api_keys = '' +# try: # incase this doesnt exist +# api_keys = api_key2[1] +# except: +# api_keys = '' try: movie_api_key = movie_api[0] @@ -299,7 +299,6 @@ def index(): 'message_settings':message_settings, 'professional':professional, 'general_settings':general_settings, - 'api_keys':api_keys, 'movie_api_key':movie_api_key, 'ipo_api_key':ipo_api_key, 'wifi_SSID':wifi_SSID, @@ -755,25 +754,25 @@ def hostname(): return index() -@app.route("/saveWeatherAPIKey", methods = ['PUT', 'POST']) -def saveWeatherAPIKey(): +# @app.route("/saveWeatherAPIKey", methods = ['PUT', 'POST']) +# def saveWeatherAPIKey(): - data= request.data.decode('utf-8') - settings = json.loads(data) +# data= request.data.decode('utf-8') +# settings = json.loads(data) - key = settings['api_key'] +# key = settings['api_key'] - with open('./api_keys.txt') as f: - lines = f.readlines() - if len(lines) == 1: - lines.append(str(key)) - elif len(lines) == 2: - lines[1] = str(key) +# with open('./api_keys.txt') as f: +# lines = f.readlines() +# if len(lines) == 1: +# lines.append(str(key)) +# elif len(lines) == 2: +# lines[1] = str(key) - with open('./api_keys.txt', 'w') as f: - for line in lines: - f.write(line) - return index() +# with open('./api_keys.txt', 'w') as f: +# for line in lines: +# f.write(line) +# return index() @@ -1334,6 +1333,29 @@ def saveSchedulerSettings(): return index() +@app.route("/setTop20or10", methods = ['PUT', 'POST']) +def setTop20or10(): + + data= request.data.decode('utf-8') + input_settings = json.loads(data) + + with open('csv/league_tables.json','r') as f: + league_settings = json.load(f) + + if input_settings == 'Top 20': + input_settings = 20 + elif input_settings == 'Top 10': + input_settings = 10 + else: + input_settings = 20 + + league_settings['top20'] = input_settings + + f = open('csv/league_tables.json', 'w') + json.dump(league_settings, f) + f.close() + + return index() if __name__ == "__main__": diff --git a/setup_config_files.sh b/setup_config_files.sh index 1a527be..1f7ced0 100755 --- a/setup_config_files.sh +++ b/setup_config_files.sh @@ -28,10 +28,10 @@ echo '{"feature": "Stocks", "speed": "medium","speed2": "medium", "animation": " echo '{"feature": "Stocks", "speed": "fast", "speed2": "fast", "animation": "down", "percent": true, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"BRENTOIL": {"current": "123.053", "unit": "bbl", "24hr_change": "1.0150", "percent_change": "0.83"}, "WTIOIL": {"current": "121.588", "unit": "bbl", "24hr_change": "0.8902", "percent_change": "0.74"}, "XAU": {"current": "1821.205", "unit": "oz", "24hr_change": "4.0045", "percent_change": "0.22"}, "XAG": {"current": "21.1034", "unit": "oz", "24hr_change": "-0.0550", "percent_change": "-0.26"}, "XCU": {"current": "0.2633", "unit": "oz", "24hr_change": "-0.0006", "percent_change": "-0.22"}, "NG": {"current": "8.6595", "unit": "mmbtu", "24hr_change": "-0.0236", "percent_change": "-0.27"}, "WHEAT": {"current": "393.123", "unit": "ton", "24hr_change": "-1.2642", "percent_change": "-0.32"}, "COTTON": {"current": "1.4494", "unit": "lb", "24hr_change": "0.0004", "percent_change": "0.03"}, "RICE": {"current": "16.3849", "unit": "cwt", "24hr_change": "0.0093", "percent_change": "0.06"}, "SUGAR": {"current": "0.1866", "unit": "lb", "24hr_change": "-0.0007", "percent_change": "-0.40"}, "COCOA": {"current": "2374.074", "unit": "ton", "24hr_change": "2.5206", "percent_change": "0.11"}, "LUMBER": {"current": "527.842", "unit": "oz", "24hr_change": "0.2641", "percent_change": "0.05"}, "SOYBEAN": {"current": "17.1621", "unit": "bu", "24hr_change": "0.0270", "percent_change": "0.16"}}}' >> commodities_settings.json echo '{"feature": "Stocks", "speed": "fast", "speed2": "slow", "animation": "up", "percent": true, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"^HSI": {"name": "HSI", "current": "18083.06", "point_change": "1003.55", "percent_change": "5.88"}, "^GSPC": {"name": "S&P 500", "current": "3790.93", "point_change": "112.50", "percent_change": "3.06"}, "^RUT": {"name": "RUSSELL 2000", "current": "1775.77", "point_change": "66.90", "percent_change": "3.91"}, "^GDAXI": {"name": "DAX", "current": "12648.95", "point_change": "-21.53", "percent_change": "-0.17"}, "^FTSE": {"name": "FTSE 100", "current": "7058.68", "point_change": "-27.82", "percent_change": "-0.39"}, "^FCHI": {"name": "CAC 40", "current": "6031.45", "point_change": "-8.24", "percent_change": "-0.14"}, "399001.SZ": {"name": "SZSE", "current": "10778.61", "point_change": "-140.83", "percent_change": "-1.29"}, "^STOXX50E": {"name": "STOXX 50", "current": "3476.55", "point_change": "-7.93", "percent_change": "-0.23"}, "^AXJO": {"name": "ASX 200", "current": "6815.70", "point_change": "116.40", "percent_change": "1.74"}, "^DJI": {"name": "DOW JONES", "current": "30316.32", "point_change": "825.43", "percent_change": "2.80"}, "^STOXX": {"name": "STOXX 600", "current": "402.33", "point_change": "-0.70", "percent_change": "-0.17"}}}' >> indices_settings.json -echo '{"feature": "Sports (Team Stats)", "speed": "medium", "speed2": "medium","animation": "down", "title": true, "leagues": {}}' >> league_tables.json -echo {\"feature\": \"Current Weather\", \"speed\": \"medium\", \"animation\": \"down\", \"temp\": \"celsius\", \"wind_speed\": \"miles/sec\", \"colour\": \"white\", \"city_colour\": \"yellow\", \"title\": true, \"locations\": {}, \"current_weather\": true} >> current_weather.json +echo '{"feature": "Sports (Team Stats)", "speed": "medium", "speed2": "medium","animation": "down", "title": true, "top20": 20, "leagues": {}}' >> league_tables.json +echo {\"feature\": \"Current Weather\", \"speed\": \"medium\", \"animation\": \"down\", \"temp\": \"celsius\", \"wind_speed\": \"miles/hour\", \"colour\": \"white\", \"city_colour\": \"yellow\", \"title\": true, \"locations\": {}, \"current_weather\": true} >> current_weather.json echo '{"feature": "Stocks", "speed": "medium", "speed2": "medium", "animation": "down", "percent": false, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"AAPL": {"current": "164.02", "change": "-1.59", "percent_change": "-0.97"}, "MSFT": {"current": "288.29", "change": "-1.32", "percent_change": "-0.46"}, "GOOG": {"current": "2586.74", "change": "-34.01", "percent_change": "-1.31"}, "NFLX": {"current": "380.52", "change": "-7.59", "percent_change": "-1.99"}}, "prepost": false}' >> stocks_settings.json -echo {\"feature\": \"Current Weather\", \"speed\": \"medium\", \"animation\": \"down\", \"temp\": \"celsius\", \"wind_speed\": \"miles/sec\", \"colour\": \"white\", \"city_colour\": \"yellow\", \"title\": true, \"locations\": {}, \"current_weather\": true} >> daily_weather.json +echo {\"feature\": \"Current Weather\", \"speed\": \"medium\", \"animation\": \"down\", \"temp\": \"celsius\", \"wind_speed\": \"miles/hour\", \"colour\": \"white\", \"city_colour\": \"yellow\", \"title\": true, \"locations\": {}, \"current_weather\": true} >> daily_weather.json echo '{"feature": "Sports (Live Games)", "speed": "medium", "speed2": "medium", "animation": "down", "title": true, "leagues": {}}' >> live_games.json echo '{"feature": "Sports (Live Games)", "speed": "medium", "speed2": "medium", "animation": "down", "title": true, "leagues": {"MLB": [[{"home_team": "Columbus Blue Jackets", "home_score": "4", "away_team": "Buffalo Sabres", "away_score": "9", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Philadelphia Flyers", "home_score": "1", "away_team": "Washington Capitals", "away_score": "4", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Calgary Flames", "home_score": "5", "away_team": "Minnesota Wild", "away_score": "3", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Colorado Avalanche", "home_score": "0", "away_team": "Boston Bruins", "away_score": "4", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Edmonton Oilers", "home_score": "8", "away_team": "Arizona Coyotes", "away_score": "2", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Vegas Golden Knights", "home_score": "1", "away_team": "New York Rangers", "away_score": "5", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "San Jose Sharks", "home_score": "5", "away_team": "Vancouver Canucks", "away_score": "6", "time": "Final/OT", "date": "2022-12-08", "isLive": "post"}], false, "no_live", "no_upcoming"]}}' >> live_mlb.json echo '{"feature": "Sports (Live Games)", "speed": "medium", "speed2": "medium", "animation": "down", "title": true, "leagues": {"MLS": [[{"home_team": "Columbus Blue Jackets", "home_score": "4", "away_team": "Buffalo Sabres", "away_score": "9", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Philadelphia Flyers", "home_score": "1", "away_team": "Washington Capitals", "away_score": "4", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Calgary Flames", "home_score": "5", "away_team": "Minnesota Wild", "away_score": "3", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Colorado Avalanche", "home_score": "0", "away_team": "Boston Bruins", "away_score": "4", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Edmonton Oilers", "home_score": "8", "away_team": "Arizona Coyotes", "away_score": "2", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "Vegas Golden Knights", "home_score": "1", "away_team": "New York Rangers", "away_score": "5", "time": "Final", "date": "2022-12-08", "isLive": "post"}, {"home_team": "San Jose Sharks", "home_score": "5", "away_team": "Vancouver Canucks", "away_score": "6", "time": "Final/OT", "date": "2022-12-08", "isLive": "post"}], false, "no_live", "no_upcoming"]}}' >> live_mls.json diff --git a/static/app.js b/static/app.js index 86a35d2..219724b 100755 --- a/static/app.js +++ b/static/app.js @@ -1252,14 +1252,12 @@ function getWeatherSettings(page) { let speed = getSelected(page.querySelectorAll(".wind-speed-select")[0]); let title = page.querySelectorAll(".title-select")[0].checked; - let api_key = page.querySelectorAll(".api-key")[0]; - + let settings = { temp: temp, wind_speed: speed, title: title, - api_key:api_key }; //only for daily weather @@ -1276,45 +1274,45 @@ function getWeatherSettings(page) { return settings; } -function saveWeatherAPIKey(){ - let featureSelector = document.getElementById("drop"); - feature = getSelected(featureSelector); - let features = [ - "Stocks", - "Crypto", - "Forex", - "Current Weather", - "Daily Forecast", - "News", - "Sports (Upcoming Games)", - "Sports (Past Games)", - "Sports (Live Games)", - "Sports (Team Stats)", - "Custom Images", - "Custom GIFs", - "Custom Messages", - "Commodities", - "Indices", - "Movies", - "IPO Calendar", - ]; - let pageNum = features.indexOf(feature) + 1; - let pageSelector = "Page" + pageNum.toString(); +// function saveWeatherAPIKey(){ +// let featureSelector = document.getElementById("drop"); +// feature = getSelected(featureSelector); +// let features = [ +// "Stocks", +// "Crypto", +// "Forex", +// "Current Weather", +// "Daily Forecast", +// "News", +// "Sports (Upcoming Games)", +// "Sports (Past Games)", +// "Sports (Live Games)", +// "Sports (Team Stats)", +// "Custom Images", +// "Custom GIFs", +// "Custom Messages", +// "Commodities", +// "Indices", +// "Movies", +// "IPO Calendar", +// ]; +// let pageNum = features.indexOf(feature) + 1; +// let pageSelector = "Page" + pageNum.toString(); - let page = document.getElementById(pageSelector); +// let page = document.getElementById(pageSelector); - let api_key = page.querySelectorAll(".api-key")[0].value; - let settings = { - api_key:api_key - }; +// let api_key = page.querySelectorAll(".api-key")[0].value; +// let settings = { +// api_key:api_key +// }; - console.log(settings); +// console.log(settings); - fetch("/saveWeatherAPIKey", { - method: "POST", - body: JSON.stringify(settings), - }); -} +// fetch("/saveWeatherAPIKey", { +// method: "POST", +// body: JSON.stringify(settings), +// }); +// } function saveMovieAPIKey(){ @@ -1404,8 +1402,8 @@ ipoAPIbtn.addEventListener("click", saveIpoAPIKey); var movieAPIbtn = document.getElementById("movie-api-btn"); movieAPIbtn.addEventListener("click", saveMovieAPIKey); -var weatherAPIbtn = document.getElementById("weather-api-btn"); -weatherAPIbtn.addEventListener("click", saveWeatherAPIKey); +// var weatherAPIbtn = document.getElementById("weather-api-btn"); +// weatherAPIbtn.addEventListener("click", saveWeatherAPIKey); function getNewsSettings(page) { @@ -1879,22 +1877,22 @@ function showDivTwo() { // Display message asking for restart of ticker when new API key added for weather -function showWeatherP() { - if(document.getElementById("api-key1").value==="") { +// function showWeatherP() { +// if(document.getElementById("api-key1").value==="") { - document.getElementById('weather-api-p').style.display = "none"; - } +// document.getElementById('weather-api-p').style.display = "none"; +// } - else if (document.getElementById("api-key1").value==="Weather API Key") { - document.getElementById('weather-api-p').style.display = "none"; +// else if (document.getElementById("api-key1").value==="Weather API Key") { +// document.getElementById('weather-api-p').style.display = "none"; - } +// } - else { - document.getElementById('weather-api-p').style.display = "block" - } +// else { +// document.getElementById('weather-api-p').style.display = "block" +// } - } +// } // Display message asking for restart of ticker when new API key added for movie @@ -1939,32 +1937,32 @@ function showIpoP() { // Disable adding cities when no API key detected - if(document.getElementById("api-key1").value==="") { - document.getElementById('inputTextBtn6').disabled = true; - } +// if(document.getElementById("api-key1").value==="") { +// document.getElementById('inputTextBtn6').disabled = true; +// } - else if (document.getElementById("api-key1").value==="Weather API Key") { - document.getElementById('inputTextBtn6').disabled = true; - } +// else if (document.getElementById("api-key1").value==="Weather API Key") { +// document.getElementById('inputTextBtn6').disabled = true; +// } - else { - document.getElementById('inputTextBtn6').disabled = false; - } +// else { +// document.getElementById('inputTextBtn6').disabled = false; +// } - if(document.getElementById("api-key").value==="") { - document.getElementById('inputTextBtn7').disabled = true; - } +// if(document.getElementById("api-key").value==="") { +// document.getElementById('inputTextBtn7').disabled = true; +// } - else if (document.getElementById("api-key").value==="Weather API Key") { - document.getElementById('inputTextBtn7').disabled = true; - } +// else if (document.getElementById("api-key").value==="Weather API Key") { +// document.getElementById('inputTextBtn7').disabled = true; +// } - else { - document.getElementById('inputTextBtn7').disabled = false; - } +// else { +// document.getElementById('inputTextBtn7').disabled = false; +// } // Stocks validation @@ -2695,3 +2693,13 @@ function saveSchedulerSettings() { document.getElementById('saved').style.display = "block"; } + +// CHANGE TOP 20 OR TOP 10 WORLD GOLF RANKING +function setTop20() { + let top20 = document.getElementById("golf-ranking-number").value; + fetch("/setTop20or10", { + method: "POST", + body: JSON.stringify(top20), + }); +} + diff --git a/stockTicker.py b/stockTicker.py index 2fe798f..ddb7a05 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -2663,75 +2663,74 @@ class StockTicker(): else: for match in league_info: + if match['isLive'] != 'pre': + dateEvent = match['time'] + date_timage = self.textImage(dateEvent, small_font, r=255, g=255, b=255) - dateEvent = match['time'] - date_timage = self.textImage(dateEvent, small_font, r=255, g=255, b=255) + strHomeTeam = match['home_team'] + strAwayTeam = match['away_team'] + intHomeScore = str(match['home_score']) + intAwayScore = str(match['away_score']) + + try: + home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strHomeTeam]['logo'])) + except Exception as e: + home_logo = self.textImage(strHomeTeam.replace(' ', '\n'), extra_small_font, r = 255, g = 255, b = 255) + + try: + away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strAwayTeam]['logo'])) + except Exception as e: + away_logo = self.textImage(strAwayTeam.replace(' ', '\n'), extra_small_font, r = 255, g = 255, b = 255) + + img.paste(away_logo, (x_offset,0)) + + x_offset += away_logo.size[0] + 4 + + score_image = self.textImage(intAwayScore + '-' + intHomeScore, large_font, h_buff = 5, r = 255, g = 255, b = 255) - strHomeTeam = match['home_team'] - strAwayTeam = match['away_team'] - intHomeScore = str(match['home_score']) - intAwayScore = str(match['away_score']) - - try: - home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strHomeTeam]['logo'])) - except Exception as e: - home_logo = self.textImage(strHomeTeam.replace(' ', '\n'), extra_small_font, r = 255, g = 255, b = 255) - - try: - away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strAwayTeam]['logo'])) - except Exception as e: - away_logo = self.textImage(strAwayTeam.replace(' ', '\n'), extra_small_font, r = 255, g = 255, b = 255) - - img.paste(away_logo, (x_offset,0)) - - x_offset += away_logo.size[0] + 4 - - score_image = self.textImage(intAwayScore + '-' + intHomeScore, large_font, h_buff = 5, r = 255, g = 255, b = 255) + try: + h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', '')) + except: + pass + try: + a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', '')) + except: + pass + try: + hc_timage = self.textImage(sports_info[strHomeTeam]['code'], small_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255)) + except Exception as e: + hc_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255) + try: + ac_timage = self.textImage(sports_info[strAwayTeam]['code'], small_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255)) + except Exception as e: + ac_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255) - try: - h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', '')) - except: - pass - try: - a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', '')) - except: - pass - try: - hc_timage = self.textImage(sports_info[strHomeTeam]['code'], small_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255)) - except Exception as e: - hc_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255) - try: - ac_timage = self.textImage(sports_info[strAwayTeam]['code'], small_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255)) - except Exception as e: - ac_timage = self.textImage('.', extra_small_font, r = 255, g = 255, b = 255) + vs_timage = self.textImage('VS', extra_small_font, r = 255, g = 255, b = 255) + + vs_size = hc_timage.size[0] + ac_timage.size[0] + vs_timage.size[0] - vs_timage = self.textImage('VS', extra_small_font, r = 255, g = 255, b = 255) - - vs_size = hc_timage.size[0] + ac_timage.size[0] + vs_timage.size[0] - - main_offset = x_offset + int(max(vs_size, date_timage.size[0], score_image.size[0])/2) - img.paste(date_timage,(main_offset - int(date_timage.size[0]/2),0)) - img.paste(vs_timage, (main_offset - int(vs_timage.size[0]/2),10)) - img.paste(ac_timage, (main_offset - int(vs_timage.size[0]/2) - ac_timage.size[0], 9)) - img.paste(score_image, (main_offset - int(score_image.size[0]/2), 15)) - if match['isLive'] == 'post': - if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore): - ua_image = Image.new("RGB", (hc_timage.size[0] -2, 1)) - ua_image1 = ImageDraw.Draw(ua_image) - ua_image1.line((0,0,hc_timage.size[0]-2,0), fill="red", width = 0) - img.paste(ua_image, (main_offset - int(vs_timage.size[0]/2)-ac_timage.size[0], ac_timage.size[1]+7)) - img.paste(hc_timage, (main_offset + int(vs_timage.size[0]/2),9)) - if match['isLive'] == 'post': - if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore): - u_image = Image.new("RGB", (ac_timage.size[0] -2, 1)) - u_image1 = ImageDraw.Draw(u_image) - u_image1.line((0,0,ac_timage.size[0]-2,0), fill="red", width = 0) - img.paste(u_image, (main_offset + int(vs_timage.size[0]/2), hc_timage.size[1]+7)) - x_offset = (main_offset + max(int(date_timage.size[0]/2), int(vs_timage.size[0]/2) + hc_timage.size[0], int(score_image.size[0]/2)) + 4) - - img.paste(home_logo, (x_offset,0)) - x_offset += home_logo.size[0] + buff_size + main_offset = x_offset + int(max(vs_size, date_timage.size[0], score_image.size[0])/2) + img.paste(date_timage,(main_offset - int(date_timage.size[0]/2),0)) + img.paste(vs_timage, (main_offset - int(vs_timage.size[0]/2),10)) + img.paste(ac_timage, (main_offset - int(vs_timage.size[0]/2) - ac_timage.size[0], 9)) + img.paste(score_image, (main_offset - int(score_image.size[0]/2), 15)) + if match['isLive'] == 'post': + if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore): + ua_image = Image.new("RGB", (hc_timage.size[0] -2, 1)) + ua_image1 = ImageDraw.Draw(ua_image) + ua_image1.line((0,0,hc_timage.size[0]-2,0), fill="red", width = 0) + img.paste(ua_image, (main_offset - int(vs_timage.size[0]/2)-ac_timage.size[0], ac_timage.size[1]+7)) + img.paste(hc_timage, (main_offset + int(vs_timage.size[0]/2),9)) + if match['isLive'] == 'post': + if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore): + u_image = Image.new("RGB", (ac_timage.size[0] -2, 1)) + u_image1 = ImageDraw.Draw(u_image) + u_image1.line((0,0,ac_timage.size[0]-2,0), fill="red", width = 0) + img.paste(u_image, (main_offset + int(vs_timage.size[0]/2), hc_timage.size[1]+7)) + x_offset = (main_offset + max(int(date_timage.size[0]/2), int(vs_timage.size[0]/2) + hc_timage.size[0], int(score_image.size[0]/2)) + 4) + img.paste(home_logo, (x_offset,0)) + x_offset += home_logo.size[0] + buff_size img = img.crop((0,0,x_offset,32)) imgs.append(img) except Exception as e: @@ -2955,19 +2954,32 @@ class StockTicker(): season = match['season'] if (time != 'future') and (league != 'LIV'): - golf_standings1 = match['golf_standings'][::2] - golf_standings2 = match['golf_standings'][1::2] + golf_standings1 = match['golf_rankings'][::2] + golf_standings2 = match['golf_rankings'][1::2] elif (time!= 'future') and (league == 'LIV'): - golf_standings1 = match['golf_standings'][0][::2] - golf_standings2 = match['golf_standings'][0][1::2] - golf_standings1_teams = match['golf_standings'][1][::2] - golf_standings2_teams = match['golf_standings'][1][1::2] + golf_standings1 = match['golf_rankings'][::2] + golf_standings2 = match['golf_rankings'][1::2] + #golf_standings1_teams = match['golf_standings'][1][::2] + #golf_standings2_teams = match['golf_standings'][1][1::2] img.paste(league_logo, (x_offset, 0)) x_offset += league_logo.size[0] + 2 - + try: + if match['purse'] != 'N/A' and match['purse'] != "" and match['purse'] != '0': + purse_timage = self.textImage(match['purse'], small_font, r=0,g=255,b=0) + except: + pass + try: + if match['shots_par'] != 'N/A' and match['shots_par'] != "" and match['shots_par'] != 0: + par_timage = self.textImage('Par' + str(match['shots_par']), small_font, r=255,g=127,b=80) + except: + pass + try: + if match['total_yards'] != 'N/A' and match['total_yards'] != "" and match['total_yards'] != 0: + yards_timage = self.textImage(str(match['total_yards']) + 'yds', small_font, r=255,g=127,b=80) + except: + pass if time == 'future': - event_timage = self.textImage(event, med_font, r=255, g=255, b=0) venue_timage = self.textImage(venue, small_font, r=0, g=255, b=0) city_timage = self.textImage(city, small_font, r=255, g=255, b=255) @@ -2976,24 +2988,52 @@ class StockTicker(): season1_timage = self.textImage('Season:', small_font, r=0, g=170, b=255) season_timage = self.textImage(season, small_font, r=255, g=255, b=255) + x_offset += 2 + x_offset_2nd = x_offset + x_offset_3rd = x_offset #date - img.paste(date1_timage, (x_offset + 2, 26)) - img.paste(date_timage, (x_offset + date1_timage.size[0] + 3, 26)) - #event - img.paste(event_timage, (x_offset + 2, 0)) - #venue - img.paste(venue_timage,(x_offset + 2, 16)) - #country - img.paste(country_timage,(x_offset + event_timage.size[0] + 5,5)) - #city - img.paste(city_timage,(x_offset + 15 + venue_timage.size[0], 16)) + img.paste(date1_timage, (x_offset, 26)) + x_offset += date1_timage.size[0] + img.paste(date_timage, (x_offset, 26)) + x_offset += date_timage.size[0] + 10 #season - img.paste(season1_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20,26)) - img.paste(season_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0],26)) + img.paste(season1_timage,(x_offset,26)) + x_offset += season1_timage.size[0] + img.paste(season_timage,(x_offset,26)) + x_offset += season_timage.size[0] + 3 + #event + img.paste(event_timage, (x_offset_2nd, 0)) + x_offset_2nd += event_timage.size[0] + 5 + #country + img.paste(country_timage,(x_offset_2nd, 5)) + x_offset_2nd += country_timage.size[0] + #venue + img.paste(venue_timage,(x_offset_3rd, 16)) + x_offset_3rd += venue_timage.size[0] + 10 + #city + img.paste(city_timage,(x_offset_3rd, 16)) + x_offset_3rd += city_timage.size[0] + try: + if match['total_yards'] != 'N/A' and match['total_yards'] != "" and match['total_yards'] != 0: + img.paste(yards_timage, (x_offset_3rd + 10, 16)) + x_offset_3rd += yards_timage.size[0] + 10 + except: + pass + try: + if match['shots_par'] != 'N/A' and match['shots_par'] != "" and match['shots_par'] != 0: + img.paste(par_timage, (x_offset_3rd + 5, 16)) + x_offset_3rd += par_timage.size[0] + 5 + except: + pass + try: + if match['purse'] != 'N/A' and match['purse'] != "" and match['purse'] != '0': + img.paste(purse_timage, (x_offset + 7, 25)) + x_offset += purse_timage.size[0] + 3 + 7 + except: + pass - x_offset += max(2 + event_timage.size[0] + country_timage.size[0] + 5, 2 + venue_timage.size[0] + city_timage.size[0] + 15, 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0] + season_timage.size[0] + 3) + x_offset = max(x_offset, x_offset_2nd, x_offset_3rd) x_offset += buff_size - else: event_timage = self.textImage(event, med_font, r=255, g=255, b=0) venue_timage = self.textImage(venue, small_font, r=0, g=255, b=0) @@ -3003,65 +3043,134 @@ class StockTicker(): season1_timage = self.textImage('Season:', small_font, r=0, g=170, b=255) season_timage = self.textImage(season, small_font, r=255, g=255, b=255) + x_offset += 2 + x_offset_2nd = x_offset + x_offset_3rd = x_offset #date - img.paste(date1_timage, (x_offset + 2, 26)) - img.paste(date_timage, (x_offset + date1_timage.size[0] + 3, 26)) - #event - img.paste(event_timage, (x_offset + 2, 0)) - #venue - img.paste(venue_timage,(x_offset + 2, 16)) - #country - img.paste(country_timage,(x_offset + event_timage.size[0] + 5,5)) - #city - img.paste(city_timage,(x_offset + 15 + venue_timage.size[0], 16)) + img.paste(date1_timage, (x_offset, 26)) + x_offset += date1_timage.size[0] + img.paste(date_timage, (x_offset, 26)) + x_offset += date_timage.size[0] + 10 #season - img.paste(season1_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20,26)) - img.paste(season_timage,(x_offset + 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0],26)) + img.paste(season1_timage,(x_offset,26)) + x_offset += season1_timage.size[0] + img.paste(season_timage,(x_offset,26)) + x_offset += season_timage.size[0] + 3 + #event + img.paste(event_timage, (x_offset_2nd, 0)) + x_offset_2nd += event_timage.size[0] + 5 + #country + img.paste(country_timage,(x_offset_2nd, 5)) + x_offset_2nd += country_timage.size[0] + #venue + img.paste(venue_timage,(x_offset_3rd, 16)) + x_offset_3rd += venue_timage.size[0] + 10 + #city + img.paste(city_timage,(x_offset_3rd, 16)) + x_offset_3rd += city_timage.size[0] + try: + if match['total_yards'] != 'N/A' and match['total_yards'] != "" and match['total_yards'] != 0: + img.paste(yards_timage, (x_offset_3rd + 10, 16)) + x_offset_3rd += yards_timage.size[0] + 10 + except: + pass + try: + if match['shots_par'] != 'N/A' and match['shots_par'] != "" and match['shots_par'] != 0: + img.paste(par_timage, (x_offset_3rd + 5, 16)) + x_offset_3rd += par_timage.size[0] + 5 + except: + pass + try: + if match['purse'] != 'N/A' and match['purse'] != "" and match['purse'] != '0': + img.paste(purse_timage, (x_offset + 7, 25)) + x_offset += purse_timage.size[0] + 3 + 7 + except: + pass - x_offset += max(2 + event_timage.size[0] + country_timage.size[0] + 5, 2 + venue_timage.size[0] + city_timage.size[0] + 15, 2 + date1_timage.size[0] + date_timage.size[0] + 20 + season1_timage.size[0] + season_timage.size[0] + 3) - x_offset2 = x_offset + x_offset = max(x_offset, x_offset_2nd, x_offset_3rd) + 5 + #x_offset2 = x_offset + symbol1_timage = self.textImage('|', small_font, r=255, g=255, b=0) - for each_player in golf_standings1: - symbol1_timage = self.textImage('|', small_font, r=255, g=255, b=0) - img.paste(symbol1_timage, (x_offset + 5, 7)) - golf_standings1_timage = self.textImage(each_player, small_font, r=255, g=255, b=255) - img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 7)) - x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7) + for each_player, each_player2 in zip(golf_standings1, golf_standings2): + img.paste(symbol1_timage, (x_offset, 7)) + img.paste(symbol1_timage, (x_offset, 20)) + x_offset += symbol1_timage.size[0] + 3 + golf1_offset = 0 + golf2_offset = 0 + try: + golf1_rank_timage = self.textImage(each_player['rank'], small_font, r=255, g=255, b=255) + golf1_offset += golf1_rank_timage.size[0] + 3 + img.paste(golf1_rank_timage,(x_offset, 7)) + try: + golf1_country = Image.open('logos/ufc_countries/{}'.format(each_player['country'].split('/')[-1].split('&')[0])) + golf1_country.thumbnail((9000,12)) + img.paste(golf1_country,(x_offset + golf1_rank_timage.size[0] + 3, 4)) + golf1_offset += golf1_country.size[0] + 3 + except: + pass + golf_standings1_timage = self.textImage(each_player['name'] + ' ' + each_player['score'], small_font, r=255, g=255, b=255) + img.paste(golf_standings1_timage, (x_offset + golf1_offset, 7)) + golf1_offset += golf_standings1_timage.size[0] + except: + pass + try: + golf2_rank_timage = self.textImage(each_player2['rank'], small_font, r=255, g=255, b=255) + golf2_offset += golf2_rank_timage.size[0] + 3 + img.paste(golf2_rank_timage,(x_offset, 20)) + try: + golf2_country = Image.open('logos/ufc_countries/{}'.format(each_player2['country'].split('/')[-1].split('&')[0])) + golf2_country.thumbnail((9000,12)) + img.paste(golf2_country,(x_offset + golf2_rank_timage.size[0] + 3, 17)) + golf2_offset += golf2_country.size[0] + 3 + except: + pass + golf_standings2_timage = self.textImage(each_player2['name'] + ' ' + each_player2['score'], small_font, r=255, g=255, b=255) + img.paste(golf_standings2_timage, (x_offset + golf2_offset, 20)) + golf2_offset += golf_standings2_timage.size[0] + except: + pass + x_offset += max(golf2_offset, golf1_offset) + 5 + #for each_player in golf_standings1: + # symbol1_timage = self.textImage('|', small_font, r=255, g=255, b=0) + # img.paste(symbol1_timage, (x_offset + 5, 7)) + # golf_standings1_timage = self.textImage(each_player, small_font, r=255, g=255, b=255) + # img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 7)) + # x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7) - for each_player2 in golf_standings2: - symbol2_timage = self.textImage('|', small_font, r=255, g=255, b=0) - img.paste(symbol2_timage, (x_offset2 + 5, 20)) - golf_standings2_timage = self.textImage(each_player2, small_font, r=255, g=255, b=255) - img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 20)) - x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7) + #for each_player2 in golf_standings2: + # symbol2_timage = self.textImage('|', small_font, r=255, g=255, b=0) + # img.paste(symbol2_timage, (x_offset2 + 5, 20)) + # golf_standings2_timage = self.textImage(each_player2, small_font, r=255, g=255, b=255) + # img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 20)) + # x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7) - if league == 'LIV': - if x_offset >= x_offset2: - x_offset += 10 - x_offset2 = x_offset - else: - x_offset2 += 10 - x_offset = x_offset2 + # if league == 'LIV': + # if x_offset >= x_offset2: + # x_offset += 10 + # x_offset2 = x_offset + # else: + # x_offset2 += 10 + # x_offset = x_offset2 - for each_team in golf_standings1_teams: - symbol1_timage = self.textImage('|', small_font, r=0, g=255, b=0) - img.paste(symbol1_timage, (x_offset + 5, 7)) - golf_standings1_timage = self.textImage(each_team, small_font, r=255, g=255, b=255) - img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 7)) - x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7) - for each_team2 in golf_standings2_teams: - symbol2_timage = self.textImage('|', small_font, r=0, g=255, b=0) - img.paste(symbol2_timage, (x_offset2 + 5, 20)) - golf_standings2_timage = self.textImage(each_team2, small_font, r=255, g=255, b=255) - img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 20)) - x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7) + #for each_team in golf_standings1_teams: + # symbol1_timage = self.textImage('|', small_font, r=0, g=255, b=0) + # img.paste(symbol1_timage, (x_offset + 5, 7)) + # golf_standings1_timage = self.textImage(each_team, small_font, r=255, g=255, b=255) + # img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 7)) + # x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7) + #for each_team2 in golf_standings2_teams: + # symbol2_timage = self.textImage('|', small_font, r=0, g=255, b=0) + # img.paste(symbol2_timage, (x_offset2 + 5, 20)) + # golf_standings2_timage = self.textImage(each_team2, small_font, r=255, g=255, b=255) + # img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 20)) + # x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7) - if x_offset >= x_offset2: - x_offset += buff_size - else: - x_offset = x_offset2 - x_offset += buff_size + #if x_offset >= x_offset2: + x_offset += buff_size + #else: + # x_offset = x_offset2 + # x_offset += buff_size else: strHomeTeam = match['home_team'] strAwayTeam = match['away_team'] @@ -3196,7 +3305,6 @@ class StockTicker(): all_settings = json.load(f) f.close() - leagues_info = all_settings['leagues'] leagues = list(leagues_info.keys()) @@ -3206,84 +3314,182 @@ class StockTicker(): imgs = [title_img, self.blank] else: imgs = [] - + ten_or_twenty = slice(None) for league in leagues: try: x_offset = 0 img = Image.new('RGB', (10000, 32)) - - - league_logo = Image.open('logos/sports/league_logos/{}.png'.format(league)).convert('RGB') + + if league == 'PGA': + league_logo = Image.open('logos/sports/league_logos/pga_1.png').convert('RGB') + try: + if all_settings['top20'] == 10: + ten_or_twenty = slice(10) + else: + ten_or_twenty = slice(None) + except: + ten_or_twenty = slice(None) + elif league == 'LPGA': + league_logo = Image.open('logos/sports/league_logos/lpga_1.png').convert('RGB') + try: + if all_settings['top20'] == 10: + ten_or_twenty = slice(10) + else: + ten_or_twenty = slice(None) + except: + ten_or_twenty = slice(None) + else: + league_logo = Image.open('logos/sports/league_logos/{}.png'.format(league)).convert('RGB') + ten_or_twenty = slice(None) + img.paste(league_logo, (x_offset,0)) x_offset += league_logo.size[0] +self.blank.size[0] - - - + team_info = leagues_info[league] - + small_font = ImageFont.load("./fonts/5x7.pil") med_font = ImageFont.load("./fonts/8x13B.pil") large_font = ImageFont.load("./fonts/10x20.pil") - - + #if league =='NHL': # read the NHl info from the csv, prem will need this as well - sports_info = self.readSportsCSV(league) # gets colour and symbol info etc from csv - + try: + sports_info = self.readSportsCSV(league) # gets colour and symbol info etc from csv + except: + pass buff_size = 20 - - for team in team_info: - - try: - - - logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo'])) + + for team in team_info[ten_or_twenty]: + if league == 'PGA' or league =='LPGA': + pga_font = ImageFont.load("./fonts/7x14.pil") + pga_small = ImageFont.load("./fonts/5x8.pil") + try: + if league == 'PGA': + player_img = Image.open('logos/pga_rank/' + team['photo'].split('/')[-1].split('&')[0]) + elif league == 'LPGA': + player_img = Image.open('logos/lpga_rank/' + team['photo'].split('/')[-1]) + player_img.thumbnail((9000,32)) + try: + img.paste(player_img, (x_offset, 0), mask=player_img) + except: + img.paste(player_img, (x_offset, 0)) + x_offset += player_img.size[0] + 2 + except: + pass + x_offset2 = x_offset + if league == 'LPGA': + if str(abs(team['rank_change'])) != '-' and str(abs(team['rank_change'])) != '0': + if int(team['rank_change']) > 0: + rank_change_img = self.textImage(str(abs(team['rank_change'])), pga_font, r = 0, g = 255, b = 0) + elif int(team['rank_change']) < 0: + rank_change_img = self.textImage(str(abs(team['rank_change'])), pga_font, r = 255, g = 0, b = 0) + elif league == 'PGA': + if str(team['rank_change']) != '-': + if int(team['rank_change']) > 0: + rank_change_img = self.textImage(str(abs(int(team['rank_change']))), pga_font, r = 0, g = 255, b = 0) + elif int(team['rank_change']) < 0: + rank_change_img = self.textImage(str(abs(int(team['rank_change']))), pga_font, r = 255, g = 0, b = 0) + + country_img = Image.open('logos/ufc_countries/' + team['country'].split('/')[-1].split('&')[0]) + country_img.thumbnail((9000,13)) + img.paste(country_img, (x_offset, 0)) + x_offset += country_img.size[0] + 2 + rank_img = self.textImage('#' + str(team['rank']), pga_font, r = 255, g=255, b=0) + img.paste(rank_img, (x_offset, 0)) + x_offset += rank_img.size[0] + 2 + name_img = self.textImage(team['first_name'].upper()[0] + '. ' + team['last_name'].upper(), pga_font, r= 255, g = 255, b = 255) + img.paste(name_img, (x_offset, 0)) + x_offset += name_img.size[0] + 5 + + if league == 'LPGA': + if str(abs(int(team['rank_change']))) != '-' and str(abs(int(team['rank_change']))) != '0': + try: + x_offset = x_offset - 3 + up_img = Image.open('logos/up-tiny.png') + down_img = Image.open('logos/down-tiny.png') + if int(team['rank_change']) > 0: + img.paste(up_img, (x_offset, 6)) + x_offset += up_img.size[0] + 2 + elif int(team['rank_change']) < 0: + img.paste(down_img, (x_offset, 6)) + x_offset += down_img.size[0] + 2 + img.paste(rank_change_img, (x_offset, 0)) + x_offset += rank_change_img.size[0] + 5 + except: + pass + elif league == 'PGA': + if str(team['rank_change']) != '-': + try: + x_offset = x_offset - 3 + up_img = Image.open('logos/up-tiny.png') + down_img = Image.open('logos/down-tiny.png') + if int(team['rank_change']) > 0: + img.paste(up_img, (x_offset, 6)) + x_offset += up_img.size[0] + 2 + elif int(team['rank_change']) < 0: + img.paste(down_img, (x_offset, 6)) + x_offset += down_img.size[0] + 2 + img.paste(rank_change_img, (x_offset, 0)) + x_offset += rank_change_img.size[0] + 5 + except: + pass + totalpts_img = self.textImage('Total:', pga_small, r = 255, g = 255, b = 255) + totalpts2_img = self.textImage(str(team['total_pts']), pga_small, r = 0, g = 255, b = 0) + img.paste(totalpts_img, (x_offset2, 14)) + img.paste(totalpts2_img, (x_offset2 + totalpts_img.size[0] + 2, 14)) + + avgpts_img = self.textImage('Avg:', pga_small, r = 255, g = 255, b = 255) + avgpts2_img = self.textImage(str(team['avg_pts']), pga_small, r = 0, g = 0, b = 255) + img.paste(avgpts_img, (x_offset2, 23)) + img.paste(avgpts2_img, (x_offset2 + 2 + avgpts_img.size[0], 23)) + events_img = self.textImage('Events:', pga_small, r= 255, g = 255, b = 255) + events2_img = self.textImage(str(team['events_played']), pga_small, r= 255, g = 128, b = 0) + img.paste(events_img, (x_offset2 + 10 + avgpts_img.size[0] + 2 + avgpts2_img.size[0], 23)) + img.paste(events2_img, (x_offset2 + 10 + avgpts_img.size[0] + 2 + avgpts2_img.size[0] + 2 + events_img.size[0], 23)) + try: + ptsgained_img = self.textImage('+'+str(team['gained_pts']), pga_small, r=0, g= 255, b=0) + ptslost_img = self.textImage(str(team['lost_pts']), pga_small, r=255, g= 0, b=0) + img.paste(ptsgained_img, (x_offset2 + totalpts_img.size[0] + 2 + totalpts2_img.size[0] + 5, 14)) + img.paste(ptslost_img, (x_offset2 + totalpts_img.size[0] + 2 + totalpts2_img.size[0] + 5 + ptsgained_img.size[0] + 3, 14)) + x_offset2 += max(avgpts_img.size[0] + 2 + avgpts2_img.size[0] + 10 + events_img.size[0] + 2 + events2_img.size[0], totalpts_img.size[0] + 2 + totalpts2_img.size[0] + 5 + ptsgained_img.size[0] + 3 + ptslost_img.size[0]) + except: + x_offset2 += max(avgpts_img.size[0] + 2 + avgpts2_img.size[0] + 10 + events_img.size[0] + 2 + events2_img.size[0], 2 + totalpts_img.size[0] + totalpts2_img.size[0]) + pass + + x_offset = max(x_offset, x_offset2) + 20 + + else: + try: + logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo'])) + img.paste(logo, (x_offset, 0)) + x_offset += logo.size[0] + 2 + except Exception as e: + pass + + name_timage = self.textImage(team['name'], med_font, r = 255, g = 255, b = 0) + wins_timage = self.textImage('Wins:' + str(team['wins']), small_font, r = 0, g = 255, b = 0) + loss_timage = self.textImage('Losses:' + str(team['loss']), small_font, r = 255, g = 0, b = 0) + draw_timage = self.textImage('Draws:' + str(team['draw']), small_font, r = 0, g = 0, b = 255) + standing_timage = self.textImage('Standing:' + str(team['standing']), small_font, r = 255, g = 255, b = 255) - - img.paste(logo, (x_offset, 0)) - x_offset += logo.size[0] + 2 - except Exception as e: - 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() + img.paste(name_timage, (x_offset, -1)) + img.paste(wins_timage, (x_offset, 12)) + img.paste(loss_timage, (x_offset, 19)) + img.paste(draw_timage, (x_offset, 26)) + x_offset += max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + img.paste(standing_timage, (x_offset, 22)) - name_timage = self.textImage(team['name'], med_font, r = 255, g = 255, b = 0) - wins_timage = self.textImage('Wins:' + str(team['wins']), small_font, r = 0, g = 255, b = 0) - loss_timage = self.textImage('Losses:' + str(team['loss']), small_font, r = 255, g = 0, b = 0) - draw_timage = self.textImage('Draws:' + str(team['draw']), small_font, r = 0, g = 0, b = 255) - #points_timage = self.textImage('Points:' + team['points'], small_font, r = 255, g = 255, b = 255) - standing_timage = self.textImage('Standing:' + str(team['standing']), small_font, r = 255, g = 255, b = 255) - - - - img.paste(name_timage, (x_offset, -1)) - img.paste(wins_timage, (x_offset, 12)) - img.paste(loss_timage, (x_offset, 19)) - img.paste(draw_timage, (x_offset, 26)) - - x_offset += max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) - #img.paste(points_timage, (x_offset, 14)) - img.paste(standing_timage, (x_offset, 22)) - - - x_offset += standing_timage.size[0] - - if name_timage.size[0] > max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + standing_timage.size[0]: - x_offset += name_timage.size[0] - (max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + standing_timage.size[0]) - x_offset += buff_size - - + x_offset += standing_timage.size[0] + + if name_timage.size[0] > max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + standing_timage.size[0]: + x_offset += name_timage.size[0] - (max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + standing_timage.size[0]) + x_offset += buff_size + img = img.crop((0,0,x_offset ,32)) imgs.append(img) + except Exception as e: pass # logf = open('log.txt', "a") @@ -3304,7 +3510,6 @@ class StockTicker(): all_settings = json.load(f) f.close() - leagues_info = all_settings['leagues'] leagues = list(leagues_info.keys()) @@ -3314,78 +3519,185 @@ class StockTicker(): imgs = [title_img, self.blank] else: imgs = [] - - - for league in leagues: - + ten_or_twenty = slice(None) + for league in leagues: try: x_offset = 0 img = Image.new('RGB', (10000, 32)) - - league_logo = Image.open('logos/sports/league_logos/{}.png'.format(league)).convert('RGB') + if league == 'PGA': + league_logo = Image.open('logos/sports/league_logos/pga_1.png').convert('RGB') + try: + if all_settings['top20'] == 10: + ten_or_twenty = slice(10) + else: + ten_or_twenty = slice(None) + except: + ten_or_twenty = slice(None) + elif league == 'LPGA': + league_logo = Image.open('logos/sports/league_logos/lpga_1.png').convert('RGB') + try: + if all_settings['top20'] == 10: + ten_or_twenty = slice(10) + else: + ten_or_twenty = slice(None) + except: + ten_or_twenty = slice(None) + else: + league_logo = Image.open('logos/sports/league_logos/{}.png'.format(league)).convert('RGB') + ten_or_twenty = slice(None) width, height = league_logo.size league_logo2 = league_logo.resize((int(width/2), int(height/2))) img.paste(league_logo2, (x_offset,0)) x_offset += (league_logo2.size[0]+5) - team_info = leagues_info[league] font = ImageFont.load("./fonts/6x10.pil") - - - sports_info = self.readSportsCSV(league) + try: + sports_info = self.readSportsCSV(league) + except: + pass buff_size = 20 + for team in team_info[ten_or_twenty]: + if league == 'PGA' or league =='LPGA': + pga_small = ImageFont.load("./fonts/4x6.pil") + try: + if league == 'PGA': + player_img = Image.open('logos/pga_rank/' + team['photo'].split('/')[-1].split('&')[0]) + elif league == 'LPGA': + player_img = Image.open('logos/lpga_rank/' + team['photo'].split('/')[-1]) + player_img.thumbnail((9000,16)) + try: + img.paste(player_img, (x_offset, 0), mask=player_img) + except: + img.paste(player_img, (x_offset, 0)) + x_offset += player_img.size[0] + 2 + except: + pass + if league == 'LPGA': + if str(abs(team['rank_change'])) != '-' and str(abs(team['rank_change'])) != '0': + if int(team['rank_change']) > 0: + rank_change_img = self.textImage(str(abs(team['rank_change'])), font, r = 0, g = 255, b = 0) + elif int(team['rank_change']) < 0: + rank_change_img = self.textImage(str(abs(team['rank_change'])), font, r = 255, g = 0, b = 0) + elif league == 'PGA': + if str(team['rank_change']) != '-': + if int(team['rank_change']) > 0: + rank_change_img = self.textImage(str(abs(int(team['rank_change']))), font, r = 0, g = 255, b = 0) + elif int(team['rank_change']) < 0: + rank_change_img = self.textImage(str(abs(int(team['rank_change']))), font, r = 255, g = 0, b = 0) + x_offset2 = x_offset - for team in team_info: - - - name_timage = self.textImage(team['name'].upper(), font, r = 255, g = 255, b = 0) - wins_timage = self.textImage('W:' + str(team['wins']), font, r = 0, g = 255, b = 0) - loss_timage = self.textImage('L:' + str(team['loss']), font, r = 255, g = 0, b = 0) - draw_timage = self.textImage('D:' + str(team['draw']), font, r = 0, g = 0, b = 255) - standing_timage = self.textImage('#' + str(team['standing']), font, r = 255, g = 255, b = 255) - - - img.paste(standing_timage, (x_offset, 3)) - x_offset += (standing_timage.size[0]) + country_img = Image.open('logos/ufc_countries/' + team['country'].split('/')[-1].split('&')[0]) + country_img.thumbnail((9000,11)) + img.paste(country_img, (x_offset, -1)) + x_offset += country_img.size[0] + 2 + rank_img = self.textImage('#' + str(team['rank']), font, r = 255, g=255, b=0) + img.paste(rank_img, (x_offset, 0)) + x_offset += rank_img.size[0] + 2 + name_img = self.textImage(team['first_name'].upper()[0] + '. ' + team['last_name'].upper(), font, r= 255, g = 255, b = 255) + img.paste(name_img, (x_offset, 0)) + x_offset += name_img.size[0] + 2 - try: - - - logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo'])) - width, height = logo.size - logo2 = logo.resize((int(width/2), int(height/2))) - img.paste(logo2, (x_offset, 0)) - x_offset += (logo2.size[0] + 3) - except Exception as e: - pass + if league == 'LPGA': + if str(abs(int(team['rank_change']))) != '-' and str(abs(int(team['rank_change']))) != '0': + try: + up_img = Image.open('logos/up-tiny.png') + down_img = Image.open('logos/down-tiny.png') + if int(team['rank_change']) > 0: + img.paste(up_img, (x_offset, 3)) + x_offset += up_img.size[0] + 2 + elif int(team['rank_change']) < 0: + img.paste(down_img, (x_offset, 3)) + x_offset += down_img.size[0] + 2 + img.paste(rank_change_img, (x_offset, 0)) + x_offset += rank_change_img.size[0] + 2 + except: + pass + elif league == 'PGA': + if str(team['rank_change']) != '-': + try: + up_img = Image.open('logos/up-tiny.png') + down_img = Image.open('logos/down-tiny.png') + if int(team['rank_change']) > 0: + img.paste(up_img, (x_offset, 3)) + x_offset += up_img.size[0] + 2 + elif int(team['rank_change']) < 0: + img.paste(down_img, (x_offset, 3)) + x_offset += down_img.size[0] + 2 + img.paste(rank_change_img, (x_offset, 0)) + x_offset += rank_change_img.size[0] + 2 + except: + pass + try: + ptsgained_img = self.textImage('+'+str(team['gained_pts']), pga_small, r=0, g= 255, b=0) + ptslost_img = self.textImage(str(team['lost_pts']), pga_small, r=255, g= 0, b=0) + img.paste(ptsgained_img, (x_offset, 3)) + x_offset += ptsgained_img.size[0] + 2 + img.paste(ptslost_img, (x_offset, 3)) + x_offset += ptslost_img.size[0] + 2 + except: + pass + + totalpts_img = self.textImage('Total:', pga_small, r = 255, g = 255, b = 255) + totalpts2_img = self.textImage(str(team['total_pts']), pga_small, r = 0, g = 255, b = 0) + img.paste(totalpts_img, (x_offset2, 10)) + x_offset2 += totalpts_img.size[0] + img.paste(totalpts2_img, (x_offset2, 10)) + x_offset2 += totalpts2_img.size[0] + 3 + + avgpts_img = self.textImage('Avg:', pga_small, r = 255, g = 255, b = 255) + avgpts2_img = self.textImage(str(team['avg_pts']), pga_small, r = 0, g = 0, b = 255) + img.paste(avgpts_img, (x_offset2, 10)) + x_offset2 += avgpts_img.size[0] + img.paste(avgpts2_img, (x_offset2, 10)) + x_offset2 += avgpts2_img.size[0] + 3 + + events_img = self.textImage('Events:', pga_small, r= 255, g = 255, b = 255) + events2_img = self.textImage(str(team['events_played']), pga_small, r= 255, g = 128, b = 0) + img.paste(events_img, (x_offset2, 10)) + x_offset2 += events_img.size[0] + img.paste(events2_img, (x_offset2, 10)) + x_offset2 += events2_img.size[0] + 3 + + x_offsetfinal = max(x_offset2, x_offset) + + x_offset = x_offsetfinal + 15 + + else: + name_timage = self.textImage(team['name'].upper(), font, r = 255, g = 255, b = 0) + wins_timage = self.textImage('W:' + str(team['wins']), font, r = 0, g = 255, b = 0) + loss_timage = self.textImage('L:' + str(team['loss']), font, r = 255, g = 0, b = 0) + draw_timage = self.textImage('D:' + str(team['draw']), font, r = 0, g = 0, b = 255) + standing_timage = self.textImage('#' + str(team['standing']), font, r = 255, g = 255, b = 255) + + img.paste(standing_timage, (x_offset, 3)) + x_offset += (standing_timage.size[0]) + + try: + logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo'])) + width, height = logo.size + logo2 = logo.resize((int(width/2), int(height/2))) + img.paste(logo2, (x_offset, 0)) + x_offset += (logo2.size[0] + 3) + except Exception as e: + pass + + img.paste(name_timage, (x_offset, 3)) + x_offset += (name_timage.size[0] +2) + img.paste(wins_timage, (x_offset, 3)) + x_offset += (wins_timage.size[0] +2) + img.paste(loss_timage, (x_offset, 3)) + x_offset += (loss_timage.size[0] +2) + img.paste(draw_timage, (x_offset, 3)) + x_offset += (draw_timage.size[0]+10) - img.paste(name_timage, (x_offset, 3)) - x_offset += (name_timage.size[0] +2) - img.paste(wins_timage, (x_offset, 3)) - x_offset += (wins_timage.size[0] +2) - img.paste(loss_timage, (x_offset, 3)) - x_offset += (loss_timage.size[0] +2) - img.paste(draw_timage, (x_offset, 3)) - x_offset += (draw_timage.size[0]+10) - # x_offset += max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) - #img.paste(points_timage, (x_offset, 14)) - # img.paste(standing_timage, (x_offset, 22)) - - - # x_offset += standing_timage.size[0] - - # if name_timage.size[0] > max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + standing_timage.size[0]: - # x_offset += name_timage.size[0] - (max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0]) + standing_timage.size[0]) - # x_offset += buff_size - x_offset += 25 img1 = img.crop((0,0,x_offset ,16)) imgs.append(img1) @@ -3485,117 +3797,116 @@ class StockTicker(): x_offset += next_match.size[0] else: - for match in league_info: + if match['isLive'] != 'pre': + dateEvent = match['time'] + date_timage = self.textImage(dateEvent, small_font, r = 255, g = 255, b = 255) - dateEvent = match['time'] - date_timage = self.textImage(dateEvent, small_font, r = 255, g = 255, b = 255) + strHomeTeam = match['home_team'] + strAwayTeam = match['away_team'] + intHomeScore = str(match['home_score']) + intAwayScore = str(match['away_score']) - strHomeTeam = match['home_team'] - strAwayTeam = match['away_team'] - intHomeScore = str(match['home_score']) - intAwayScore = str(match['away_score']) + try: + home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strHomeTeam]['logo'])) + width1, height1 = home_logo.size + home_logo1 = home_logo.resize((int(width1/2), int(height1/2))) + except Exception as e: + home_logo1 = self.textImage(strHomeTeam, small_font, r = 255, g = 255, b = 255) + + try: + away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strAwayTeam]['logo'])) + width2, height2 = away_logo.size + away_logo1 = away_logo.resize((int(width2/2), int(height2/2))) + except Exception as e: + away_logo1 = self.textImage(strAwayTeam, small_font, r = 255, g = 255, b = 255) - try: - home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strHomeTeam]['logo'])) - width1, height1 = home_logo.size - home_logo1 = home_logo.resize((int(width1/2), int(height1/2))) - except Exception as e: - home_logo1 = self.textImage(strHomeTeam, small_font, r = 255, g = 255, b = 255) - - try: - away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[strAwayTeam]['logo'])) - width2, height2 = away_logo.size - away_logo1 = away_logo.resize((int(width2/2), int(height2/2))) - except Exception as e: - away_logo1 = self.textImage(strAwayTeam, small_font, r = 255, g = 255, b = 255) + error = False - error = False + img.paste(away_logo1, (x_offset,0)) + x_offset += (away_logo1.size[0] + 2) + + score_image = self.textImage(intAwayScore + '-' + intHomeScore, font, h_buff = 5, r = 255, g = 255, b = 255) + + try: + h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', '')) + except: + pass + try: + a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', '')) + except: + pass + try: + hc_timage = self.textImage(sports_info[strHomeTeam]['code'], font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255)) + except: + hc_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255) + error = True + try: + ac_timage = self.textImage(sports_info[strAwayTeam]['code'], font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255)) + except: + ac_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255) + error = True + + if date_timage.size[0] > (hc_timage.size[0] + 2 + score_image.size[0] + ac_timage.size[0]): + x_offset10 = x_offset + int((date_timage.size[0]/2)-(score_image.size[0]/2)-ac_timage.size[0]) + img.paste(date_timage,(x_offset, 0)) + img.paste(score_image, (x_offset + int((date_timage.size[0]/2)-(score_image.size[0]/2)), 5)) + x_offset += date_timage.size[0] + img.paste(ac_timage,(x_offset10, 5)) + if match['isLive'] == 'post': + if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore): + ua_image = Image.new("RGB", (ac_timage.size[0] -3, 1)) + ua_image1 = ImageDraw.Draw(ua_image) + ua_image1.line((0,0,ac_timage.size[0]-3,0), fill="red", width = 0) + img.paste(ua_image, (x_offset10, ac_timage.size[1]+4)) + x_offset10 += ac_timage.size[0] + score_image.size[0] + img.paste(hc_timage,(x_offset10, 5)) + if match['isLive'] == 'post': + if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore): + u_image = Image.new("RGB", (hc_timage.size[0] -3, 1)) + u_image1 = ImageDraw.Draw(u_image) + u_image1.line((0,0,hc_timage.size[0]-3,0), fill="red", width = 0) + img.paste(u_image, (x_offset10, hc_timage.size[1]+4)) + x_offset10 += hc_timage.size[0] + if error: + img.paste(home_logo1, (max(x_offset + date_timage.size[0], x_offset10),0)) + x_offset += (home_logo1.size[0] + date_timage.size[0]) + else: + img.paste(home_logo1, (max(x_offset,x_offset10),0)) + x_offset += home_logo1.size[0] - img.paste(away_logo1, (x_offset,0)) - x_offset += (away_logo1.size[0] + 2) - - score_image = self.textImage(intAwayScore + '-' + intHomeScore, font, h_buff = 5, r = 255, g = 255, b = 255) - - try: - h_colour = mcolors.to_rgb(sports_info[strHomeTeam]['colour'].replace(' ', '')) - except: - pass - try: - a_colour = mcolors.to_rgb(sports_info[strAwayTeam]['colour'].replace(' ', '')) - except: - pass - try: - hc_timage = self.textImage(sports_info[strHomeTeam]['code'], font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255)) - except: - hc_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255) - error = True - try: - ac_timage = self.textImage(sports_info[strAwayTeam]['code'], font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255)) - except: - ac_timage = self.textImage('.', small_font, r = 255, g = 255, b = 255) - error = True - if date_timage.size[0] > (hc_timage.size[0] + 2 + score_image.size[0] + ac_timage.size[0]): - x_offset10 = x_offset + int((date_timage.size[0]/2)-(score_image.size[0]/2)-ac_timage.size[0]) - img.paste(date_timage,(x_offset, 0)) - img.paste(score_image, (x_offset + int((date_timage.size[0]/2)-(score_image.size[0]/2)), 5)) - x_offset += date_timage.size[0] - img.paste(ac_timage,(x_offset10, 5)) - if match['isLive'] == 'post': - if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore): - ua_image = Image.new("RGB", (ac_timage.size[0] -3, 1)) - ua_image1 = ImageDraw.Draw(ua_image) - ua_image1.line((0,0,ac_timage.size[0]-3,0), fill="red", width = 0) - img.paste(ua_image, (x_offset10, ac_timage.size[1]+4)) - x_offset10 += ac_timage.size[0] + score_image.size[0] - img.paste(hc_timage,(x_offset10, 5)) - if match['isLive'] == 'post': - if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore): - u_image = Image.new("RGB", (hc_timage.size[0] -3, 1)) - u_image1 = ImageDraw.Draw(u_image) - u_image1.line((0,0,hc_timage.size[0]-3,0), fill="red", width = 0) - img.paste(u_image, (x_offset10, hc_timage.size[1]+4)) - x_offset10 += hc_timage.size[0] - if error: - img.paste(home_logo1, (max(x_offset + date_timage.size[0], x_offset10),0)) - x_offset += (home_logo1.size[0] + date_timage.size[0]) else: - img.paste(home_logo1, (max(x_offset,x_offset10),0)) - x_offset += home_logo1.size[0] + x_offset_date = (x_offset + ac_timage.size[0] + int(score_image.size[0]/2) - int(date_timage.size[0]/2)) + img.paste(date_timage, (x_offset_date,0)) + #img.paste(date_timage, (x_offset+20+int((score_image.size[0] - date_timage.size[0])/2),0)) + img.paste(ac_timage, (x_offset, 5)) - - else: - x_offset_date = (x_offset + ac_timage.size[0] + int(score_image.size[0]/2) - int(date_timage.size[0]/2)) - img.paste(date_timage, (x_offset_date,0)) - #img.paste(date_timage, (x_offset+20+int((score_image.size[0] - date_timage.size[0])/2),0)) - img.paste(ac_timage, (x_offset, 5)) - - if match['isLive'] == 'post': - if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore): - ua_image = Image.new("RGB", (ac_timage.size[0] -3, 1)) - ua_image1 = ImageDraw.Draw(ua_image) - ua_image1.line((0,0,ac_timage.size[0]-3,0), fill="red", width = 0) - img.paste(ua_image, (x_offset, ac_timage.size[1]+4)) - x_offset += ac_timage.size[0] - img.paste(score_image, (x_offset, 5)) - x_offset += score_image.size[0] - img.paste(hc_timage, (x_offset, 5)) - if match['isLive'] == 'post': - if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore): - u_image = Image.new("RGB", (hc_timage.size[0] -3, 1)) - u_image1 = ImageDraw.Draw(u_image) - u_image1.line((0,0,hc_timage.size[0]-3,0), fill="red", width = 0) - img.paste(u_image, (x_offset, hc_timage.size[1]+4)) - x_offset += hc_timage.size[0] - x_offset_date += date_timage.size[0] - if error: - img.paste(home_logo1, (max(x_offset + date_timage.size[0], x_offset_date),0)) - x_offset += (home_logo1.size[0] + date_timage.size[0]) - else: - img.paste(home_logo1, (max(x_offset,x_offset_date),0)) - x_offset += home_logo1.size[0] - x_offset += buff_size + if match['isLive'] == 'post': + if int(intHomeScore) < int(intAwayScore) or int(intHomeScore) == int(intAwayScore): + ua_image = Image.new("RGB", (ac_timage.size[0] -3, 1)) + ua_image1 = ImageDraw.Draw(ua_image) + ua_image1.line((0,0,ac_timage.size[0]-3,0), fill="red", width = 0) + img.paste(ua_image, (x_offset, ac_timage.size[1]+4)) + x_offset += ac_timage.size[0] + img.paste(score_image, (x_offset, 5)) + x_offset += score_image.size[0] + img.paste(hc_timage, (x_offset, 5)) + if match['isLive'] == 'post': + if int(intHomeScore) > int(intAwayScore) or int(intHomeScore) == int(intAwayScore): + u_image = Image.new("RGB", (hc_timage.size[0] -3, 1)) + u_image1 = ImageDraw.Draw(u_image) + u_image1.line((0,0,hc_timage.size[0]-3,0), fill="red", width = 0) + img.paste(u_image, (x_offset, hc_timage.size[1]+4)) + x_offset += hc_timage.size[0] + x_offset_date += date_timage.size[0] + if error: + img.paste(home_logo1, (max(x_offset + date_timage.size[0], x_offset_date),0)) + x_offset += (home_logo1.size[0] + date_timage.size[0]) + else: + img.paste(home_logo1, (max(x_offset,x_offset_date),0)) + x_offset += home_logo1.size[0] + x_offset += buff_size x_offset += 20 img = img.crop((0,0,x_offset ,16)) imgs.append(img) @@ -3774,19 +4085,30 @@ class StockTicker(): season = match['season'] if (time != 'future') and (league != 'LIV'): - golf_standings1 = match['golf_standings'][::2] - golf_standings2 = match['golf_standings'][1::2] + golf_standings1 = match['golf_rankings'][::2] + golf_standings2 = match['golf_rankings'][1::2] elif (time!= 'future') and (league == 'LIV'): - golf_standings1 = match['golf_standings'][0][::2] - golf_standings2 = match['golf_standings'][0][1::2] - golf_standings1_teams = match['golf_standings'][1][::2] - golf_standings2_teams = match['golf_standings'][1][1::2] + golf_standings1 = match['golf_rankings'][::2] + golf_standings2 = match['golf_rankings'][1::2] img.paste(league_logo2, (x_offset, 0)) x_offset += league_logo2.size[0] + 5 - + try: + if match['purse'] != 'N/A' and match['purse'] != "" and match['purse'] != '0': + purse_timage = self.textImage(match['purse'], small_font, r=0,g=255,b=0) + except: + pass + try: + if match['shots_par'] != 'N/A' and match['shots_par'] != "" and match['shots_par'] != 0: + par_timage = self.textImage('Par' + str(match['shots_par']), small_font, r=255,g=127,b=80) + except: + pass + try: + if match['total_yards'] != 'N/A' and match['total_yards'] != "" and match['total_yards'] != 0: + yards_timage = self.textImage(str(match['total_yards']) + 'yds', small_font, r=255,g=127,b=80) + except: + pass if time == 'future': - event_timage = self.textImage(event, small_font, r=255, g=255, b=0) venue_timage = self.textImage(venue, small_font, r=0, g=255, b=0) city_timage = self.textImage(city, small_font, r=255, g=255, b=255) @@ -3794,25 +4116,50 @@ class StockTicker(): season1_timage = self.textImage('Season:', small_font, r=0, g=170, b=255) season_timage = self.textImage(season, small_font, r=255, g=255, b=255) date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171) - #event img.paste(event_timage, (x_offset, 1)) #venue img.paste(venue_timage,(x_offset, 9)) x_offset += (max(event_timage.size[0], venue_timage.size[0]) + 5) + x_offset_2nd = x_offset #date img.paste(date1_timage, (x_offset, 1)) - img.paste(date_timage, (x_offset + date1_timage.size[0] + 2, 1)) + x_offset += date1_timage.size[0] + img.paste(date_timage, (x_offset, 1)) + x_offset += date_timage.size[0] + 5 #city - img.paste(city_timage,(x_offset, 9)) + img.paste(city_timage,(x_offset_2nd, 9)) + x_offset_2nd += city_timage.size[0] + 7 #country - img.paste(country_timage,(x_offset + city_timage.size[0] + 7,9)) + img.paste(country_timage,(x_offset_2nd,9)) + x_offset_2nd += country_timage.size[0] + 5 #season - img.paste(season1_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + 5,1)) - img.paste(season_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5,1)) - - x_offset += max(date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5 + season_timage.size[0], city_timage.size[0] + 7 + country_timage.size[0]) + img.paste(season1_timage,(x_offset,1)) + x_offset += season1_timage.size[0] + img.paste(season_timage,(x_offset,1)) + x_offset += season_timage.size[0] + 5 + try: + if match['purse'] != 'N/A' and match['purse'] != "" and match['purse'] != '0': + img.paste(purse_timage, (x_offset, 1)) + x_offset += purse_timage.size[0] + 5 + except: + pass + try: + if match['total_yards'] != 'N/A' and match['total_yards'] != "" and match['total_yards'] != 0: + img.paste(yards_timage, (x_offset_2nd, 9)) + x_offset_2nd += yards_timage.size[0] + 5 + except: + pass + try: + if match['shots_par'] != 'N/A' and match['shots_par'] != "" and match['shots_par'] != 0: + img.paste(par_timage, (x_offset_2nd, 9)) + x_offset_2nd += par_timage.size[0] + 5 + except: + pass + x_offset = max(x_offset, x_offset_2nd) + #x_offset += max(date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5 + season_timage.size[0], city_timage.size[0] + 7 + country_timage.size[0]) x_offset += (buff_size - 10) + else: event_timage = self.textImage(event, small_font, r=255, g=255, b=0) venue_timage = self.textImage(venue, small_font, r=0, g=255, b=0) @@ -3821,66 +4168,103 @@ class StockTicker(): season1_timage = self.textImage('Season:', small_font, r=0, g=170, b=255) season_timage = self.textImage(season, small_font, r=255, g=255, b=255) date1_timage = self.textImage('Date:', small_font, r=255, g=0, b=171) - #event img.paste(event_timage, (x_offset, 1)) #venue img.paste(venue_timage,(x_offset, 9)) x_offset += (max(event_timage.size[0], venue_timage.size[0]) + 5) + x_offset_2nd = x_offset #date img.paste(date1_timage, (x_offset, 1)) - img.paste(date_timage, (x_offset + date1_timage.size[0] + 2, 1)) + x_offset += date1_timage.size[0] + img.paste(date_timage, (x_offset, 1)) + x_offset += date_timage.size[0] + 5 #city - img.paste(city_timage,(x_offset, 9)) + img.paste(city_timage,(x_offset_2nd, 9)) + x_offset_2nd += city_timage.size[0] + 7 #country - img.paste(country_timage,(x_offset + city_timage.size[0] + 7,9)) + img.paste(country_timage,(x_offset_2nd,9)) + x_offset_2nd += country_timage.size[0] + 5 #season - img.paste(season1_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + 5,1)) - img.paste(season_timage,(x_offset + date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5,1)) - - x_offset += max(date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5 + season_timage.size[0], city_timage.size[0] + 7 + country_timage.size[0]) - x_offset2 = x_offset + img.paste(season1_timage,(x_offset,1)) + x_offset += season1_timage.size[0] + img.paste(season_timage,(x_offset,1)) + x_offset += season_timage.size[0] + 5 + try: + if match['purse'] != 'N/A' and match['purse'] != "" and match['purse'] != '0': + img.paste(purse_timage, (x_offset, 1)) + x_offset += purse_timage.size[0] + 5 + except: + pass + try: + if match['total_yards'] != 'N/A' and match['total_yards'] != "" and match['total_yards'] != 0: + img.paste(yards_timage, (x_offset_2nd, 9)) + x_offset_2nd += yards_timage.size[0] + 5 + except: + pass + try: + if match['shots_par'] != 'N/A' and match['shots_par'] != "" and match['shots_par'] != 0: + img.paste(par_timage, (x_offset_2nd, 9)) + x_offset_2nd += par_timage.size[0] + 5 + except: + pass + x_offset = max(x_offset, x_offset_2nd) + #x_offset += max(date1_timage.size[0] + 2 + date_timage.size[0] + season1_timage.size[0] + 5 + season_timage.size[0], city_timage.size[0] + 7 + country_timage.size[0]) + symbol1_timage = self.textImage('|', small_font, r=255, g=255, b=0) + for each_player, each_player2 in zip(golf_standings1, golf_standings2): + img.paste(symbol1_timage, (x_offset, 1)) + img.paste(symbol1_timage, (x_offset, 9)) + x_offset += symbol1_timage.size[0] + 2 + golf1_offset = 0 + golf2_offset = 0 + try: + golf1_rank_timage = self.textImage(each_player['rank'], small_font, r=255, g=255, b=255) + img.paste(golf1_rank_timage,(x_offset, 1)) + golf1_offset += golf1_rank_timage.size[0] + 2 + try: + golf1_country = Image.open('logos/ufc_countries/{}'.format(each_player['country'].split('/')[-1].split('&')[0])) + golf1_country.thumbnail((9000,9)) + img.paste(golf1_country,(golf1_offset + x_offset, -1)) + golf1_offset += golf1_country.size[0] + 2 + except: + pass + golf_standings1_timage = self.textImage(each_player['name'] + ' ' + each_player['score'], small_font, r=255, g=255, b=255) + img.paste(golf_standings1_timage, (x_offset + golf1_offset, 1)) + golf1_offset += golf_standings1_timage.size[0] + except: + pass + try: + golf2_rank_timage = self.textImage(each_player2['rank'], small_font, r=255, g=255, b=255) + golf2_offset += golf2_rank_timage.size[0] + 2 + img.paste(golf2_rank_timage,(x_offset, 9)) + try: + golf2_country = Image.open('logos/ufc_countries/{}'.format(each_player2['country'].split('/')[-1].split('&')[0])) + golf2_country.thumbnail((9000,9)) + img.paste(golf2_country,(x_offset + golf2_offset, 7)) + golf2_offset += golf2_country.size[0] + 2 + except: + pass + golf_standings2_timage = self.textImage(each_player2['name'] + ' ' + each_player2['score'], small_font, r=255, g=255, b=255) + img.paste(golf_standings2_timage, (x_offset + golf2_offset, 9)) + golf2_offset += golf_standings2_timage.size[0] + except: + pass + x_offset += max(golf2_offset, golf1_offset) + 5 +# for each_player in golf_standings1: +# symbol1_timage = self.textImage('|', small_font, r=255, g=255, b=0) +# img.paste(symbol1_timage, (x_offset + 5, 1)) +# golf_standings1_timage = self.textImage(each_player, small_font, r=255, g=255, b=255) +# img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 1)) +# x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7) +# +# for each_player2 in golf_standings2: +# symbol2_timage = self.textImage('|', small_font, r=255, g=255, b=0) +# img.paste(symbol2_timage, (x_offset2 + 5, 9)) +# golf_standings2_timage = self.textImage(each_player2, small_font, r=255, g=255, b=255) +# img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 9)) +# x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7) - for each_player in golf_standings1: - symbol1_timage = self.textImage('|', small_font, r=255, g=255, b=0) - img.paste(symbol1_timage, (x_offset + 5, 1)) - golf_standings1_timage = self.textImage(each_player, small_font, r=255, g=255, b=255) - img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 1)) - x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7) - - for each_player2 in golf_standings2: - symbol2_timage = self.textImage('|', small_font, r=255, g=255, b=0) - img.paste(symbol2_timage, (x_offset2 + 5, 9)) - golf_standings2_timage = self.textImage(each_player2, small_font, r=255, g=255, b=255) - img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 9)) - x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7) - - if league == 'LIV': - if x_offset >= x_offset2: - x_offset += 5 - x_offset2 = x_offset - else: - x_offset2 += 5 - x_offset = x_offset2 - - for each_team in golf_standings1_teams: - symbol1_timage = self.textImage('|', small_font, r=0, g=255, b=0) - img.paste(symbol1_timage, (x_offset + 5, 1)) - golf_standings1_timage = self.textImage(each_team, small_font, r=255, g=255, b=255) - img.paste(golf_standings1_timage, (x_offset + symbol1_timage.size[0] + 7, 1)) - x_offset += (golf_standings1_timage.size[0] + symbol1_timage.size[0] + 7) - for each_team2 in golf_standings2_teams: - symbol2_timage = self.textImage('|', small_font, r=0, g=255, b=0) - img.paste(symbol2_timage, (x_offset2 + 5, 9)) - golf_standings2_timage = self.textImage(each_team2, small_font, r=255, g=255, b=255) - img.paste(golf_standings2_timage, (x_offset2 + symbol2_timage.size[0] + 7, 9)) - x_offset2 += (golf_standings2_timage.size[0] + symbol2_timage.size[0] + 7) - - if x_offset >= x_offset2: - x_offset += (buff_size - 10) - else: - x_offset = x_offset2 - x_offset += (buff_size - 10) + x_offset += (buff_size - 10) else: strHomeTeam = match['home_team'] @@ -4084,14 +4468,14 @@ class StockTicker(): weekday = weekdays[datetime.today().weekday()] date_img = self.textImage((month + ' ' + date + ',' + weekday).upper(), small_font) rain_img = Image.open(weather_dir + '/rain-chance.png') - rtext_img = self.textImage(str(int(current_weather['rain_chance']*100)) + '%', small_font) + rtext_img = self.textImage(str(current_weather['rain_chance']) + '%', small_font) cloud_img = Image.open(weather_dir + '/clouds.png') ctext_img = self.textImage(str(current_weather['clouds']) + '%', small_font) wind_img = Image.open(weather_dir + '/wind.png') - w_speed = current_weather['wind_speed']*3.6 + w_speed = current_weather['wind_speed'] w_unit = 'K/H' if all_settings["wind_speed"] == "miles/hour": - w_speed = current_weather['wind_speed']*2.236936 + w_speed = current_weather['wind_speed']/1.609 w_unit = 'M/H' wtext_img = self.textImage("{0:.0f}".format(w_speed) + w_unit, small_font) wdir_img = self.textImage(self.degreesToCompass(current_weather['wind_direction']).upper(), small_font) @@ -4272,15 +4656,15 @@ class StockTicker(): rain_img = Image.open(weather_dir + '/rain-chance.png') - rtext_img = self.textImage(str(int(current_weather['rain_chance']*100)) + '%', font) + rtext_img = self.textImage(str(current_weather['rain_chance']) + '%', font) cloud_img = Image.open(weather_dir + '/clouds.png') ctext_img = self.textImage(str(current_weather['clouds']) + '%', font) wind_img = Image.open(weather_dir + '/wind.png') - w_speed = current_weather['wind_speed']*3.6 + w_speed = current_weather['wind_speed'] w_unit = 'K/H' if all_settings["wind_speed"] == "miles/hour": - w_speed = current_weather['wind_speed']*2.236936 + w_speed = current_weather['wind_speed']/1.609 w_unit = 'M/H' @@ -4520,7 +4904,7 @@ class StockTicker(): if daily_weathers['current_weather']: rain_img = Image.open(weather_dir + '/rain-chance.png') - rtext_img = self.textImage(str(int(daily_weather[0]['rain_chance']*100)) + '%', small_font) + rtext_img = self.textImage(str(daily_weather[0]['rain_chance']) + '%', small_font) hum_img = Image.open(weather_dir + '/humidity.png') htext_img = self.textImage(str(daily_weather[0]['humidity']) + '%', small_font) wind_img = Image.open(weather_dir + '/wind.png') @@ -4531,10 +4915,10 @@ class StockTicker(): ctext_img = self.textImage(str(daily_weather[0]['clouds']) + '%', small_font) wind_img = Image.open(weather_dir + '/wind.png') - w_speed = daily_weather[0]['wind_speed']*3.6 + w_speed = daily_weather[0]['wind_speed'] w_unit = 'K/H' if daily_weathers['wind_speed'] == "miles/hour": - w_speed = daily_weather[0]['wind_speed']*2.236936 + w_speed = daily_weather[0]['wind_speed']/1.609 w_unit = 'M/H' wtext_img = self.textImage("{0:.0f}".format(w_speed) + w_unit, small_font) diff --git a/templates/index.html b/templates/index.html index 8809cee..7407cf0 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,73 +1,45 @@ - - - - - - - Fintic - Web Control Panel - - - - - - - + @@ -127,7 +99,7 @@ -

Version 1.3.4

+

Version 1.3.5

Changelog

@@ -4054,43 +4026,25 @@ -
- +
@@ -4510,41 +4464,23 @@ -
- + -
- - + --> @@ -6181,17 +6117,10 @@
@@ -6220,14 +6149,10 @@ id="inputTransition10" - class="form-select animation-select" - - > + class="form-select animation-select"> - - @@ -6239,51 +6164,54 @@
-
- -
- -
- -
+ +
+
+ +
+
+ +
+
+ +
+
- +
@@ -6308,14 +6236,8 @@ id="flexCheckChecked24" - {% - - if - - team_stats.title%} - + {% if team_stats.title%} checked - {%endif%} /> @@ -8531,7 +8453,7 @@

© 2020-2023 Fintic Limited., All Rights Reserved. Contact Us.

-

Data Provided by IEX Cloud, Openweathermap, CoinGecko, Exchangerate-API, TheSportsDB, Google News, Yahoo Finance, ESPN, The Movie DB, Finnhub

+

Data Provided by IEX Cloud, Open-Meteo, CoinGecko, Exchangerate-API, TheSportsDB, Google News, Yahoo Finance, ESPN, The Movie DB, Finnhub

Useful resources: YouTube Tutorials , Formatting Guide & Info , Official Website

@@ -8545,7 +8467,7 @@ - +