added NHL support
@@ -297,22 +297,23 @@ def updateCurrencies(api_key):
|
|||||||
print(c_dict)
|
print(c_dict)
|
||||||
json.dump([base, c_dict], open( "csv/currency.json", 'w+' ))
|
json.dump([base, c_dict], open( "csv/currency.json", 'w+' ))
|
||||||
|
|
||||||
|
def updateLeagueTable(api_key, league_id):
|
||||||
def updateSports(api_key):
|
url = 'https://www.thesportsdb.com/api/v1/json/{}/lookuptable.php?l={}&s=2020-2021'.format(api_key, league_id)
|
||||||
url = 'https://www.thesportsdb.com/api/v1/json/{}/lookuptable.php?l=4328&s=2020-2021'.format(api_key) # premier league table
|
|
||||||
'https://www.thesportsdb.com/api/v1/json/{}/eventsnext.php?id=133602'.format(api_key) # next five events by team ID (paid) use this for upcoming team games
|
|
||||||
|
|
||||||
|
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
all_data = r.json()
|
all_data = r.json()
|
||||||
|
|
||||||
print([all_data['table'][i]['intRank'] for i in range(len(all_data['table']))])
|
|
||||||
|
|
||||||
premier_teams = []
|
premier_teams = []
|
||||||
print(all_data['table'][0].keys())
|
print(all_data['table'])
|
||||||
|
|
||||||
for i in range(len(all_data['table'])):
|
for i in range(len(all_data['table'])):
|
||||||
team = {}
|
team = {}
|
||||||
|
|
||||||
|
if all_data['table'][i]['strTeam'] == "Calgary Flames":
|
||||||
|
print(all_data['table'][i]['dateUpdated'], all_data['table'][i]['intPoints'])
|
||||||
|
|
||||||
team['name'] = all_data['table'][i]['strTeam']
|
team['name'] = all_data['table'][i]['strTeam']
|
||||||
team['wins'] = all_data['table'][i]['intWin']
|
team['wins'] = all_data['table'][i]['intWin']
|
||||||
team['loss'] = all_data['table'][i]['intLoss']
|
team['loss'] = all_data['table'][i]['intLoss']
|
||||||
@@ -323,27 +324,36 @@ def updateSports(api_key):
|
|||||||
|
|
||||||
premier_teams.append(team)
|
premier_teams.append(team)
|
||||||
|
|
||||||
json.dump(premier_teams, open( "csv/sports/premier_league/team_stats.json", 'w+' ))
|
|
||||||
|
if league_id == '4328':
|
||||||
|
league = 'premier_league'
|
||||||
|
elif league_id == '4380':
|
||||||
|
league = 'NHL'
|
||||||
|
|
||||||
|
json.dump(premier_teams, open( "csv/sports/{}/team_stats.json".format(league), 'w+' ))
|
||||||
|
|
||||||
|
def updateLeagueEvents(api_key, league_id, time):
|
||||||
|
|
||||||
|
if time == 'past':
|
||||||
|
url ='https://www.thesportsdb.com/api/v1/json/{}/eventspastleague.php?id={}'.format(api_key, league_id) #last 15 events on the league (premium only)
|
||||||
|
else:
|
||||||
|
url ='https://www.thesportsdb.com/api/v1/json/{}/eventsnextleague.php?id={}'.format(api_key, league_id) #next 15 events on the league (premium only)
|
||||||
|
|
||||||
|
|
||||||
#url = 'https://www.thesportsdb.com/api/v1/json/{}/eventsseason.php?id=4328&s=2020-2021'.format(api_key) # all past events in premier league
|
|
||||||
|
|
||||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventspastleague.php?id=4328'.format(api_key) #last 15 events on the league (premium only)
|
|
||||||
|
|
||||||
print(url)
|
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
all_data = r.json()
|
all_data = r.json()
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print(all_data['events'][0])
|
#print(all_data['events'][0].keys())
|
||||||
#print([all_data['events'][i]['strTimestamp'] for i in range(len(all_data['events']))])
|
#print([all_data['events'][i]['strTimestamp'] for i in range(len(all_data['events']))])
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
|
if not all_data['events'] is None:
|
||||||
for i in range(len(all_data['events'])):
|
for i in range(len(all_data['events'])):
|
||||||
event = {}
|
event = {}
|
||||||
event['date'] = all_data['events'][i]['dateEvent']
|
event['date'] = all_data['events'][i]['dateEvent']
|
||||||
print(event['date'])
|
|
||||||
event['time'] = all_data['events'][i]['strTime']
|
event['time'] = all_data['events'][i]['strTime']
|
||||||
event['home_team'] = all_data['events'][i]['strHomeTeam']
|
event['home_team'] = all_data['events'][i]['strHomeTeam']
|
||||||
event['home_score'] = all_data['events'][i]['intHomeScore']
|
event['home_score'] = all_data['events'][i]['intHomeScore']
|
||||||
@@ -353,13 +363,41 @@ def updateSports(api_key):
|
|||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
|
|
||||||
json.dump(events, open( "csv/sports/premier_league/past_games.json", 'w+' ))
|
if league_id == '4328':
|
||||||
|
league = 'premier_league'
|
||||||
|
elif league_id == '4380':
|
||||||
|
league = 'NHL'
|
||||||
|
|
||||||
|
json.dump(events, open( "csv/sports/{}/{}_games.json".format(league, time), 'w+' ))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def updateSports(api_key):
|
||||||
|
prem_id = '4328' #prem
|
||||||
|
NHL_id = '4380'
|
||||||
|
|
||||||
|
#updateLeagueTable(api_key, prem_id) #prem
|
||||||
|
updateLeagueEvents(api_key, prem_id, 'past')
|
||||||
|
updateLeagueEvents(api_key, NHL_id, 'future')
|
||||||
|
|
||||||
|
updateLeagueTable(api_key, NHL_id)
|
||||||
|
updateLeagueTable(api_key, prem_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
'https://www.thesportsdb.com/api/v1/json/{}/eventsnext.php?id=133602'.format(api_key) # next five events by team ID (paid) use this for upcoming team games
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#url = 'https://www.thesportsdb.com/api/v1/json/{}/eventsseason.php?id=4328&s=2020-2021'.format(api_key) # all past events in premier league
|
||||||
|
|
||||||
|
|
||||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventsnextleague.php?id=4328'.format(api_key) #next 15 events on the league (premium only)
|
|
||||||
|
|
||||||
url = 'https://www.thesportsdb.com/api/v2/json/{}/livescore.php?l=4380'.format(api_key) #live scores
|
url = 'https://www.thesportsdb.com/api/v2/json/{}/livescore.php?l=4380'.format(api_key) #live scores
|
||||||
print(all_data)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1 +1 @@
|
|||||||
17/06/2021 13:46:59
|
17/06/2021 15:03:04
|
||||||
|
|
BIN
csv/sports/NHL/__MACOSX/Team Icon/._.DS_Store
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._avalanche.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._blackhawks.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._blue-jackets.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._blues.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._bruins.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._canadiens.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._canucks.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._capitals.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._coyotes.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._devils.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._ducks.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._flames.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._flyers.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._hurricanes.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._islanders.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._jets.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._kings.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._knights.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._lightning.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._maple-leafs.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._oilers.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._panthers.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._penguins.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._predators.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._rangers.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._red-wings.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._sabres.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._senators.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._sharks.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._stars.png
Normal file
BIN
csv/sports/NHL/__MACOSX/Team Icon/._wild.png
Normal file
1
csv/sports/NHL/future_games.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[{"date": "2021-06-17", "time": "01:00:00", "home_team": "Vegas Golden Knights", "home_score": "2", "away_team": "Montreal Canadiens", "away_score": "3", "round": "0"}, {"date": "2021-06-18", "time": "00:00:00", "home_team": "New York Islanders", "home_score": null, "away_team": "Tampa Bay Lightning", "away_score": null, "round": "0"}, {"date": "2021-06-19", "time": "00:00:00", "home_team": "Montreal Canadiens", "home_score": null, "away_team": "Vegas Golden Knights", "away_score": null, "round": "0"}, {"date": "2021-06-20", "time": "00:00:00", "home_team": "New York Islanders", "home_score": null, "away_team": "Tampa Bay Lightning", "away_score": null, "round": "0"}, {"date": "2021-06-21", "time": "00:00:00", "home_team": "Montreal Canadiens", "home_score": null, "away_team": "Vegas Golden Knights", "away_score": null, "round": "0"}]
|
1
csv/sports/NHL/past_games.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[{"date": "2021-06-16", "time": "00:00:00", "home_team": "Tampa Bay Lightning", "home_score": "4", "away_team": "New York Islanders", "away_score": "2", "round": "0"}, {"date": "2021-06-15", "time": "01:00:00", "home_team": "Vegas Golden Knights", "home_score": "4", "away_team": "Montreal Canadiens", "away_score": "1", "round": "0"}, {"date": "2021-06-13", "time": "19:00:00", "home_team": "Tampa Bay Lightning", "home_score": "1", "away_team": "New York Islanders", "away_score": "2", "round": "0"}, {"date": "2021-06-11", "time": "01:00:00", "home_team": "Vegas Golden Knights", "home_score": "6", "away_team": "Colorado Avalanche", "away_score": "3", "round": "0"}, {"date": "2021-06-09", "time": "23:30:00", "home_team": "New York Islanders", "home_score": "6", "away_team": "Boston Bruins", "away_score": "2", "round": "0"}, {"date": "2021-06-09", "time": "01:00:00", "home_team": "Colorado Avalanche", "home_score": "2", "away_team": "Vegas Golden Knights", "away_score": "3", "round": "0"}, {"date": "2021-06-08", "time": "22:30:00", "home_team": "Carolina Hurricanes", "home_score": "0", "away_team": "Tampa Bay Lightning", "away_score": "2", "round": "0"}, {"date": "2021-06-08", "time": "00:00:00", "home_team": "Montreal Canadiens", "home_score": "3", "away_team": "Winnipeg Jets", "away_score": "2", "round": "0"}, {"date": "2021-06-07", "time": "22:30:00", "home_team": "Boston Bruins", "home_score": "4", "away_team": "New York Islanders", "away_score": "5", "round": "0"}, {"date": "2021-06-07", "time": "00:30:00", "home_team": "Vegas Golden Knights", "home_score": "5", "away_team": "Colorado Avalanche", "away_score": "1", "round": "0"}, {"date": "2021-06-06", "time": "22:00:00", "home_team": "Montreal Canadiens", "home_score": "5", "away_team": "Winnipeg Jets", "away_score": "1", "round": "0"}, {"date": "2021-06-05", "time": "23:15:00", "home_team": "New York Islanders", "home_score": "4", "away_team": "Boston Bruins", "away_score": "1", "round": "0"}, {"date": "2021-06-05", "time": "20:00:00", "home_team": "Tampa Bay Lightning", "home_score": "6", "away_team": "Carolina Hurricanes", "away_score": "4", "round": "0"}, {"date": "2021-06-05", "time": "02:00:00", "home_team": "Vegas Golden Knights", "home_score": "3", "away_team": "Colorado Avalanche", "away_score": "2", "round": "0"}, {"date": "2021-06-04", "time": "23:30:00", "home_team": "Winnipeg Jets", "home_score": "0", "away_team": "Montreal Canadiens", "away_score": "1", "round": "0"}]
|
32
csv/sports/NHL/team_info.csv
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
Full Team Name,Team ID,3 Letter ID,Logo File name,Team Color
|
||||||
|
Arizona Coyotes,134847,ARI,coyotes.png,Red
|
||||||
|
Anaheim Ducks,134846,ANA,ducks.png,Gold
|
||||||
|
Boston Bruins,134830,BOS,bruins.png,Yellow
|
||||||
|
Colorado Avalanche,134855,COL,avalanche.png,Red
|
||||||
|
Chicago Blackhawks,134854,CHI,blackhawks.png,"Orange, Yellow, Red"
|
||||||
|
Columbus Blue Jackets,134839,CBJ,blue-jackets.png,"Red, Blue"
|
||||||
|
St. Louis Blues,134859,STL,blues.png,Blue
|
||||||
|
Montreal Canadiens,134834,MTL,canadiens.png,Red
|
||||||
|
Vancouver Canucks,134850,VAN,canucks.png,Blue
|
||||||
|
Washington Capitals,134845,WSH,capitals.png,"Red, Blue"
|
||||||
|
New Jersey Devils,134840,NJD,devils.png,Red
|
||||||
|
Calgary Flames,134848,CGY,flames.png,Orange
|
||||||
|
Philadelphia Flyers,134843,PHI,flyers.png,White
|
||||||
|
Carolina Hurricanes,134838,CAR,hurricanes.png,"Red, white"
|
||||||
|
New York Islanders,134841,NYI,islanders.png,Orange
|
||||||
|
Winnipeg Jets,134851,WPG,jets.png,
|
||||||
|
Los Angeles Kings,134852,LAK,kings.png,
|
||||||
|
Vegas Golden Knights,135913,VGK,knights.png,
|
||||||
|
Tampa Bay Lightning,134836,TBL,lightning.png,
|
||||||
|
Toronto Maple Leafs,134837,TOR,maple-leafs.png,
|
||||||
|
Edmonton Oilers,134849,EDM,oilers.png,
|
||||||
|
Florida Panthers,134833,FLA,panthers.png,
|
||||||
|
Pittsburgh Penguins,134844,PIT,penguins.png,
|
||||||
|
Nashville Predators,134858,NSH,predators.png,
|
||||||
|
New York Rangers,134842,NYR,rangers.png,
|
||||||
|
Detroit Red Wings,134832,DET,red-wings.png,
|
||||||
|
Buffalo Sabres,134831,BUF,sabres.png,
|
||||||
|
Ottawa Senators,134835,OTT,senators.png,
|
||||||
|
San Jose Sharks,134853,SJS,sharks.png,
|
||||||
|
Dallas Stars,134856,DAL,stars.png,
|
||||||
|
Minnesota Wild,134857,MIN,wild.png,
|
|
1
csv/sports/NHL/team_stats.json
Normal file
1
csv/sports/premier_league/future_games.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[]
|
@@ -1,4 +1,4 @@
|
|||||||
name,current,opening
|
name,current,opening
|
||||||
MSFT,261.2757,256.065
|
MSFT,260.94,256.065
|
||||||
NFLX,501.3899,490.25
|
NFLX,499,490.25
|
||||||
GOOG,2536.02,2510.46
|
GOOG,2535.55,2510.46
|
||||||
|
|
BIN
league.ppm
BIN
logos/sports/NHL/avalanche.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
logos/sports/NHL/blackhawks.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
logos/sports/NHL/blue-jackets.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
logos/sports/NHL/blues.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
logos/sports/NHL/bruins.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
logos/sports/NHL/canadiens.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
logos/sports/NHL/canucks.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
logos/sports/NHL/capitals.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
logos/sports/NHL/coyotes.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
logos/sports/NHL/devils.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
logos/sports/NHL/ducks.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
logos/sports/NHL/flames.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
logos/sports/NHL/flyers.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
logos/sports/NHL/hurricanes.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
logos/sports/NHL/islanders.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
logos/sports/NHL/jets.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
logos/sports/NHL/kings.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
logos/sports/NHL/knights.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
logos/sports/NHL/lightning.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
logos/sports/NHL/maple-leafs.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
logos/sports/NHL/oilers.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
logos/sports/NHL/panthers.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
logos/sports/NHL/penguins.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
logos/sports/NHL/predators.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
logos/sports/NHL/rangers.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
logos/sports/NHL/red-wings.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
logos/sports/NHL/sabres.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
logos/sports/NHL/senators.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
logos/sports/NHL/sharks.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
logos/sports/NHL/stars.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
logos/sports/NHL/wild.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
118
stockTicker.py
@@ -585,15 +585,20 @@ class StockTicker():
|
|||||||
finalDisplayImage.save('final1.ppm')
|
finalDisplayImage.save('final1.ppm')
|
||||||
|
|
||||||
|
|
||||||
def getLeagueImage(self):
|
def getLeagueImage(self, league, time):
|
||||||
|
|
||||||
img = Image.new('RGB', (10000, 32))
|
img = Image.new('RGB', (10000, 32))
|
||||||
league_info = json.load(open('csv/sports/premier_league/past_games.json', 'r'))
|
league_info = json.load(open('csv/sports/{}/{}_games.json'.format(league, time), 'r'))
|
||||||
print(league_info[0].keys())
|
print(league_info[0].keys())
|
||||||
small_font = ImageFont.load("./fonts/5x7.pil")
|
small_font = ImageFont.load("./fonts/5x7.pil")
|
||||||
large_font = ImageFont.load("./fonts/10x20.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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
buff_size = 20
|
buff_size = 20
|
||||||
x_offset = 0
|
x_offset = 0
|
||||||
print(len(league_info))
|
print(len(league_info))
|
||||||
@@ -611,38 +616,53 @@ class StockTicker():
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
home_logo = Image.open('logos/sports/premier_league/' + home_team +'.png')
|
if league == 'NHL':
|
||||||
|
home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[home_team]['logo']))
|
||||||
|
elif league == 'premier_league':
|
||||||
|
home_logo = Image.open('logos/sports/{}/{}.png'.format(league, home_team))
|
||||||
except:
|
except:
|
||||||
home_logo = self.textImage(home_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
|
home_logo = self.textImage(home_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
|
||||||
print(home_team)
|
print(home_team)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
away_logo = Image.open('logos/sports/premier_league/' + away_team +'.png')
|
if league == 'NHL':
|
||||||
|
away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[away_team]['logo']))
|
||||||
|
elif league == 'premier_league':
|
||||||
|
away_logo = Image.open('logos/sports/{}/{}.png'.format(league, away_team))
|
||||||
except:
|
except:
|
||||||
away_logo = self.textImage(away_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
|
away_logo = self.textImage(away_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
home_timage = self.textImage(home_team, small_font, r = 255, g = 255, b = 255)
|
home_timage = self.textImage(sports_info[home_team]['code'], small_font, r = 255, g = 255, b = 255)
|
||||||
away_timage = self.textImage(away_team, small_font, r = 255, g = 255, b = 255)
|
away_timage = self.textImage(sports_info[away_team]['code'], small_font, r = 255, g = 255, b = 255)
|
||||||
|
|
||||||
date_timage = self.textImage(date, small_font, r = 255, g = 255, b = 0)
|
date_timage = self.textImage(date, small_font, r = 255, g = 255, b = 0)
|
||||||
round_timage = self.textImage('round:' + rond, small_font, r = 255, g = 255, b = 255)
|
round_timage = self.textImage('round:' + rond, small_font, r = 255, g = 255, b = 255)
|
||||||
|
|
||||||
|
if time == 'past':
|
||||||
score_image = self.textImage(home_score + '-' + away_score, large_font, r = 255, g = 255, b = 255)
|
score_image = self.textImage(home_score + '-' + away_score, large_font, r = 255, g = 255, b = 255)
|
||||||
|
img.paste(score_image, (x_offset+10, 15))
|
||||||
|
|
||||||
|
|
||||||
img.paste(home_logo, (x_offset,0))
|
img.paste(home_logo, (x_offset,0))
|
||||||
|
|
||||||
x_offset += home_logo.size[0] + 2
|
x_offset += home_logo.size[0] + 2
|
||||||
|
|
||||||
#img.paste(home_timage, (x_offset, 0))
|
#if league == 'NHL':
|
||||||
#img.paste(away_timage, (x_offset, 5))
|
# img.paste(home_timage, (x_offset, 0))
|
||||||
|
# img.paste(away_timage, (x_offset, 5))
|
||||||
|
|
||||||
img.paste(date_timage, (x_offset, 0))
|
img.paste(date_timage, (x_offset, 0))
|
||||||
img.paste(round_timage, (x_offset+ 7, 8))
|
img.paste(round_timage, (x_offset+ 7, 8))
|
||||||
img.paste(score_image, (x_offset+10, 15))
|
|
||||||
|
|
||||||
#x_offset += max(home_timage.size[0], away_timage.size[0], date_timage.size[0], round_timage.size[0], score_image.size[0])
|
#x_offset += max(home_timage.size[0], away_timage.size[0], date_timage.size[0], round_timage.size[0], score_image.size[0])
|
||||||
|
if time == 'past':
|
||||||
x_offset += max( date_timage.size[0], round_timage.size[0], score_image.size[0])
|
x_offset += max( date_timage.size[0], round_timage.size[0], score_image.size[0])
|
||||||
|
else:
|
||||||
|
x_offset += max( date_timage.size[0], round_timage.size[0])
|
||||||
|
|
||||||
img.paste(away_logo, (x_offset,0))
|
img.paste(away_logo, (x_offset,0))
|
||||||
|
|
||||||
@@ -652,23 +672,34 @@ class StockTicker():
|
|||||||
|
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def getTeamsImage(self):
|
def getTeamsImage(self, league):
|
||||||
|
|
||||||
img = Image.new('RGB', (10000, 32))
|
img = Image.new('RGB', (10000, 32))
|
||||||
team_info = json.load(open('csv/sports/premier_league/team_stats.json', 'r'))
|
team_info = json.load(open('csv/sports/{}/team_stats.json'.format(league), 'r'))
|
||||||
|
|
||||||
small_font = ImageFont.load("./fonts/5x7.pil")
|
small_font = ImageFont.load("./fonts/5x7.pil")
|
||||||
med_font = ImageFont.load("./fonts/7x14.pil")
|
med_font = ImageFont.load("./fonts/7x14.pil")
|
||||||
large_font = ImageFont.load("./fonts/10x20.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)
|
||||||
|
|
||||||
buff_size = 20
|
buff_size = 20
|
||||||
x_offset = 0
|
x_offset = 0
|
||||||
for team in team_info:
|
for team in team_info:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logo = Image.open('logos/sports/premier_league/' + team['name'] +'.png')
|
if league == 'NHL':
|
||||||
|
|
||||||
|
logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo']))
|
||||||
|
elif league == 'premier_league':
|
||||||
|
|
||||||
|
logo = Image.open('logos/sports/{}/{}.png'.format(league, team['name']))
|
||||||
img.paste(logo, (x_offset, 0))
|
img.paste(logo, (x_offset, 0))
|
||||||
x_offset += logo.size[0] + 2
|
x_offset += logo.size[0] + 2
|
||||||
except:
|
except Exception as e:
|
||||||
print('no logo for:', team['name'])
|
print('no logo for:', team['name'])
|
||||||
|
print(e)
|
||||||
|
|
||||||
name_timage = self.textImage(team['name'], med_font, r = 255, g = 255, b = 0)
|
name_timage = self.textImage(team['name'], med_font, r = 255, g = 255, b = 0)
|
||||||
wins_timage = self.textImage('Wins:' + team['wins'], small_font, r = 0, g = 255, b = 0)
|
wins_timage = self.textImage('Wins:' + team['wins'], small_font, r = 0, g = 255, b = 0)
|
||||||
@@ -1161,6 +1192,21 @@ class StockTicker():
|
|||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def readSportsCSV(self, league):
|
||||||
|
|
||||||
|
team_info = {}
|
||||||
|
f = open('csv/sports/{}/team_info.csv'.format(league), 'r')
|
||||||
|
CSV = csv.reader(f)
|
||||||
|
next(CSV)
|
||||||
|
for row in CSV:
|
||||||
|
|
||||||
|
team_info[row[0]] = {}
|
||||||
|
team_info[row[0]]['id'] = row[1]
|
||||||
|
team_info[row[0]]['code'] = row[2]
|
||||||
|
team_info[row[0]]['logo'] = row[3]
|
||||||
|
team_info[row[0]]['colour'] = row[4]
|
||||||
|
|
||||||
|
return team_info
|
||||||
|
|
||||||
def displayDailyWeatherAlt(self):
|
def displayDailyWeatherAlt(self):
|
||||||
img0, img1 = self.getDailyWeatherImageAlt()
|
img0, img1 = self.getDailyWeatherImageAlt()
|
||||||
@@ -1267,13 +1313,13 @@ class StockTicker():
|
|||||||
self.scrollImageTransition(['weather.ppm', 'weather.ppm'], stocks = False)
|
self.scrollImageTransition(['weather.ppm', 'weather.ppm'], stocks = False)
|
||||||
|
|
||||||
elif msg == 'L': # league
|
elif msg == 'L': # league
|
||||||
img = self.getLeagueImage()
|
img = self.getLeagueImage('NHL', 'future')
|
||||||
img.save('league.ppm')
|
img.save('league.ppm')
|
||||||
|
|
||||||
stock_ticker.scrollImageTransition(['league.ppm', 'league.ppm'], stocks = False)
|
stock_ticker.scrollImageTransition(['league.ppm', 'league.ppm'], stocks = False)
|
||||||
|
|
||||||
elif msg == 't': #teams
|
elif msg == 't': #teams
|
||||||
img = self.getTeamsImage()
|
img = self.getTeamsImage('premier_league')
|
||||||
img.save('teams.ppm')
|
img.save('teams.ppm')
|
||||||
|
|
||||||
stock_ticker.scrollImageTransition(['teams.ppm', 'teams.ppm'], stocks = False)
|
stock_ticker.scrollImageTransition(['teams.ppm', 'teams.ppm'], stocks = False)
|
||||||
@@ -1287,51 +1333,9 @@ if __name__ == '__main__':
|
|||||||
with open('log.txt', "w") as log:
|
with open('log.txt', "w") as log:
|
||||||
try:
|
try:
|
||||||
stock_ticker = StockTicker()
|
stock_ticker = StockTicker()
|
||||||
#img = stock_ticker.getLeagueImage()
|
|
||||||
#img.save('league.ppm')
|
|
||||||
|
|
||||||
#stock_ticker.scrollImageTransition(['league.ppm', 'league.ppm'], stocks = False)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#img0, img1 = stock_ticker.getDailyWeatherImage()
|
|
||||||
#img = stock_ticker.getTodayWeatherImage()
|
|
||||||
#img.save('weather.ppm')
|
|
||||||
#stock_ticker.process_msg('S')
|
|
||||||
#stock_ticker.process_msg('W')
|
|
||||||
#stock_ticker.displayDailyWeather()
|
|
||||||
|
|
||||||
|
|
||||||
#stock_ticker.delay = 10
|
|
||||||
#stock_ticker.scrollImageTransition(['weather.ppm', 'weather.ppm'], stocks = False)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#stock_ticker.process_msg('G')
|
|
||||||
#stock_ticker.scrollImageTransition([os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_image'), os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_image')], stocks = False)
|
|
||||||
#stock_ticker.readCSV()
|
|
||||||
#stock_ticker.displayUserText()
|
|
||||||
#
|
|
||||||
|
|
||||||
#stock_ticker.displayNews()
|
|
||||||
#stock_ticker.displayGIF('/home/pi/Desktop/stock_ticker/gifs/open.gif')
|
|
||||||
|
|
||||||
#stock_ticker.displayGIF('/home/pi/Desktop/stock_ticker/gifs/close.gif')
|
|
||||||
|
|
||||||
|
|
||||||
#stock_ticker.process_msg(brightness)
|
|
||||||
#stock_ticker.process_msg(speed)
|
|
||||||
|
|
||||||
|
|
||||||
#stock_ticker.displayText()
|
|
||||||
#stock_ticker.getFullStockImage(1)
|
|
||||||
#stock_ticker.process_msg('f')
|
|
||||||
#stock_ticker.displayStocks()
|
|
||||||
#stock_ticker.displayStocks()
|
|
||||||
|
|
||||||
#stock_ticker.delay = 0.001
|
|
||||||
#stock_ticker.scrollImageTransition(['final.ppm', 'final.ppm'], offset_x = 0, offset_y = 0)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
msg = getInput()
|
msg = getInput()
|
||||||
stock_ticker.process_msg(msg)
|
stock_ticker.process_msg(msg)
|
||||||
|