I am trying to build a sports betting ticker that streams the game match up with the current odds("line"). I am retrieving the data from a JSON via requests. I want to update the data at a fixed rate (every 2-3 mins) so that my odds are current. Here is the code I have pieced together. I have no coding training so pretty much used google-fu and stackoverflow for this.
Side note: I want to change the text color of each match up so it is easier to differentiate between games (red,green,yellow,red,etc..).
import requests
from PIL import Image, ImageDraw, ImageFont
import os
res = requests.get("myurl")
data = res.json()
games = []
for game in data['games']:
for info in data['games'][game]:
v1 = data['games'][game]['awayTeam'] + ' vs '
v2 = data['games'][game]['homeTeam'] + ' '
v3 = data['games'][game]['gameSpreadHomeHandicap'] + ' '
games.append(v1 + v2 + v3)
with open('yourfile.txt', 'w') as file:
file.write(' '.join(games))
with open('yourfile.txt', 'r') as file:
output = file.readline()
im = Image.new("RGB", (8600, 16), "black")
draw = ImageDraw.Draw(im)
font = ImageFont.truetype(r'/usr/share/fonts/truetype/msttcorefonts/Arial.ttf', 13)
draw.text((0, 0), output, (0, 255, 0), font=font)
im.save("ticker.ppm")
os.system("sudo ./demo -D 1 --led-rows=16 --led-chain=3 ticker.ppm")
Thank you for your help.