api call limits and transitions
This commit is contained in:
parent
2bee635511
commit
54edfb0d1b
222
api_caller.py
222
api_caller.py
@ -96,8 +96,13 @@ def updateUpdate(NY_time):
|
||||
f.write(NY_str + '\n')
|
||||
f.close()
|
||||
|
||||
def updateStockPrices(symbols):
|
||||
def updateStockPrices():
|
||||
finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub
|
||||
finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub
|
||||
finnhubClient = finnhub.Client(api_key=finnhubAPIkey)
|
||||
|
||||
|
||||
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
||||
try:
|
||||
quotes = [finnhubClient.quote(symbol) for symbol in symbols]
|
||||
current_prices = [quote['c'] for quote in quotes]
|
||||
@ -120,7 +125,11 @@ def updateStockPrices(symbols):
|
||||
apiCalledError = True
|
||||
|
||||
|
||||
def updateStockPricesIEX(symbols):
|
||||
def updateStockPricesIEX():
|
||||
iexAPIkey = 'pk_68ef6a15902c41f887f0b544a0ca17cf' #IEX
|
||||
iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b'
|
||||
max_stocks = 200
|
||||
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
||||
try:
|
||||
symbols_str = ','.join(symbols)
|
||||
method = 'GET'
|
||||
@ -179,7 +188,10 @@ def updateStockPricesIEX(symbols):
|
||||
print(e)
|
||||
|
||||
|
||||
def updateCrypto(coins, coin_info, unique_bases):
|
||||
def updateCrypto():
|
||||
coingecko_client = CoinGeckoAPI()
|
||||
|
||||
coins, coin_info, unique_bases = readCryptoCSV('csv/crypto.csv', max_crypto)
|
||||
try:
|
||||
response = coingecko_client.get_price(ids=','.join(coins), vs_currencies = unique_bases, include_24hr_change=True)
|
||||
|
||||
@ -225,7 +237,9 @@ def updateNews():
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
def updateWeather(api_key):
|
||||
def updateWeather():
|
||||
|
||||
api_key = 'bd5d5096a5ba30bbcfb57ead42ab3fee'
|
||||
try:
|
||||
f = open( "csv/weather_location.txt", 'r' )
|
||||
location = f.read()
|
||||
@ -277,8 +291,8 @@ def updateWeather(api_key):
|
||||
print(e)
|
||||
|
||||
|
||||
def updateCurrencies(api_key):
|
||||
|
||||
def updateForex():
|
||||
api_key = '862dbb6d1101ce0c5136'
|
||||
try:
|
||||
base = 'USD'
|
||||
yesterday = datetime.now() - timedelta(1)
|
||||
@ -401,105 +415,96 @@ def updateLeagueEvents(api_key, league_id, time):
|
||||
|
||||
json.dump(events, open( "csv/sports/{}/{}_games.json".format(league, time), 'w+' ))
|
||||
|
||||
def updateSports():
|
||||
#read user settings to decide which sprots to update
|
||||
api_key = '97436974'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def updateSports(api_key):
|
||||
prem_id = '4328' #prem
|
||||
NHL_id = '4380'
|
||||
NBA_id = '4387' #prem
|
||||
NFL_id = '4391'
|
||||
|
||||
for i in [NHL_id, NBA_id, NFL_id]:
|
||||
for i in [NHL_id]:
|
||||
updateLeagueEvents(api_key, i, 'live')
|
||||
updateLeagueEvents(api_key, i, 'past')
|
||||
updateLeagueEvents(api_key, i, '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/v2/json/{}/livescore.php?l=4380'.format(api_key) #live scores
|
||||
|
||||
|
||||
def checkStocks(last_update, update_frequency):
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
opening = NY_time.replace(hour=9, minute=30, second=0, microsecond=0).replace(tzinfo=None)
|
||||
closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0).replace(tzinfo=None)
|
||||
|
||||
|
||||
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
||||
|
||||
updated = False
|
||||
|
||||
diff = (NY_time - last_update).total_seconds()/60 #minutes
|
||||
if opening < NY_time < closing and datetime.today().weekday() < 5: # we need to do real time updating
|
||||
|
||||
|
||||
if diff >= update_frequency:
|
||||
updated = True
|
||||
updateStockPrices()
|
||||
|
||||
|
||||
elif emptyInfo(symbols, stock_info): # if theres any empty stocks
|
||||
updated = True
|
||||
updateStockPrices()
|
||||
|
||||
|
||||
else:
|
||||
# update if last update was before the previous days closing
|
||||
yday_closing = closing - dt.timedelta(days=1)
|
||||
yday_str = yday_closing.strftime("%d/%m/%Y %H:%M:%S")
|
||||
yday_closing = datetime.strptime(yday_str, "%d/%m/%Y %H:%M:%S")
|
||||
|
||||
if last_update < yday_closing:
|
||||
updated = True
|
||||
updateStockPrices(symbols)
|
||||
|
||||
return updated
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
||||
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
|
||||
|
||||
|
||||
finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub
|
||||
finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub
|
||||
stock_time = 2 #minutes
|
||||
crypto_time = 10 #minutes
|
||||
news_time = 30 #minutes
|
||||
weather_time = 10 #minutes
|
||||
|
||||
# TODO: different update times for stocks, weather and news
|
||||
finnhubClient = finnhub.Client(api_key=finnhubAPIkey)
|
||||
max_stocks = 200
|
||||
max_crypto = 100
|
||||
|
||||
iexAPIkey = 'pk_68ef6a15902c41f887f0b544a0ca17cf' #IEX
|
||||
iexSandboxAPIkey = 'Tpk_0078dff413ef4f979137f7111452dc4b'
|
||||
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
|
||||
|
||||
#updateStockPricesIEX(symbols)
|
||||
|
||||
finnhubClient = finnhub.Client(api_key=finnhubAPIkey)
|
||||
|
||||
coingecko_client = CoinGeckoAPI()
|
||||
update_frequencies = {'stocks':2, 'crypto':10, 'news':60, 'weather': 10} #minutes
|
||||
|
||||
NY_zone = pytz.timezone('America/New_York')
|
||||
|
||||
NY_time = datetime.now(NY_zone)
|
||||
opening = NY_time.replace(hour=9, minute=30, second=0, microsecond=0)
|
||||
closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0)
|
||||
CET_zone = pytz.timezone('Europe/Berlin')
|
||||
|
||||
NY_time = datetime.now(NY_zone)
|
||||
|
||||
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
||||
updateStockPrices(symbols)
|
||||
updateUpdate(NY_time)
|
||||
coins, coin_info, unique_bases = readCryptoCSV('csv/crypto.csv', max_crypto)
|
||||
CET_time = datetime.now(CET_zone)
|
||||
|
||||
weather_key = 'bd5d5096a5ba30bbcfb57ead42ab3fee'
|
||||
NY_str = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
CET_str = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
|
||||
currency_key = '862dbb6d1101ce0c5136'
|
||||
sports_key = '97436974'
|
||||
#f = open('csv/last_updates.json', 'w+')
|
||||
#update_times = {'stocks':NY_str, 'crypto':NY_str, 'news':NY_str, 'weather': NY_str, 'forex': CET_str} # all in NY time apart from forex in CET
|
||||
#json.dump(update_times, f)
|
||||
#f.close()
|
||||
|
||||
updateSports(sports_key)
|
||||
|
||||
|
||||
|
||||
|
||||
updateCurrencies(currency_key)
|
||||
|
||||
|
||||
updateWeather( weather_key)
|
||||
|
||||
updateCrypto(coins, coin_info, unique_bases)
|
||||
|
||||
updateNews()
|
||||
f = open('csv/last_updates.json', 'r')
|
||||
last_updates = json.load(f)
|
||||
f.close()
|
||||
|
||||
t = time.time()
|
||||
|
||||
@ -508,55 +513,66 @@ if __name__ == '__main__':
|
||||
try:
|
||||
while True:
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
|
||||
msg = getInput()
|
||||
if msg == 'R' or time.time() - t > stock_time*60:
|
||||
|
||||
#stocks
|
||||
stock_time = datetime.strptime(last_updates['stocks'], "%d/%m/%Y %H:%M:%S")
|
||||
stock_frequency = update_frequencies['stocks']
|
||||
if checkStocks(stock_time, stock_frequency):
|
||||
stock_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
last_updates['stocks'] = stock_time
|
||||
|
||||
# crypto
|
||||
crypto_time = datetime.strptime(last_updates['crypto'], "%d/%m/%Y %H:%M:%S")
|
||||
crypto_frequency = update_frequencies['crypto']
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - crypto_time).total_seconds()/60 #minutes
|
||||
if diff >= update_frequencies['crypto']:
|
||||
crypto_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
updateCrypto()
|
||||
last_updates['crypto'] = crypto_time
|
||||
|
||||
|
||||
# weather
|
||||
weather_time = datetime.strptime(last_updates['weather'], "%d/%m/%Y %H:%M:%S")
|
||||
weather_frequency = update_frequencies['weather']
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - weather_time).total_seconds()/60 #minutes
|
||||
if diff >= update_frequencies['weather']:
|
||||
weather_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
updateWeather()
|
||||
last_updates['weather'] = weather_time
|
||||
|
||||
|
||||
coins, coin_info, unique_bases = readCryptoCSV('csv/crypto.csv', max_stocks)
|
||||
# weather
|
||||
news_time = datetime.strptime(last_updates['news'], "%d/%m/%Y %H:%M:%S")
|
||||
news_frequency = update_frequencies['news']
|
||||
|
||||
updateCrypto(coins, coin_info, unique_bases)
|
||||
updateCurrencies(currency_key)
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - weather_time).total_seconds()/60 #minutes
|
||||
if diff >= update_frequencies['news']:
|
||||
news_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
updateNews()
|
||||
updateWeather(weather_location, weather_key)
|
||||
updateSports(sports_key)
|
||||
last_updates['news'] = news_time
|
||||
|
||||
NY_time = datetime.now(NY_zone)
|
||||
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
||||
if opening < NY_time < closing and datetime.today().weekday() < 5: # we need to do real time updating
|
||||
print('market open')
|
||||
#forex updates once every 24hours at 1700 CET
|
||||
|
||||
updateStockPrices(symbols)
|
||||
updateUpdate(NY_time)
|
||||
# update if last update was before the previous days closing
|
||||
forex_time = datetime.strptime(last_updates['forex'], "%d/%m/%Y %H:%M:%S")
|
||||
CET_time = datetime.now(CET_zone)
|
||||
yday_update = (CET_time.replace(hour=17, minute=00, second=0, microsecond=0) - dt.timedelta(days=1)).replace(tzinfo=None)
|
||||
|
||||
elif emptyInfo(symbols, stock_info): # if theres any empty stocks
|
||||
if forex_time < yday_update:
|
||||
forex_time = CET_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
last_updates['forex'] = forex_time
|
||||
updateForex()
|
||||
|
||||
updateStockPrices(symbols)
|
||||
updateUpdate(NY_time)
|
||||
|
||||
else:
|
||||
# update if last update was before the previous days closing
|
||||
|
||||
f = open('csv/last_update.csv', 'r')
|
||||
CSV = csv.reader(f)
|
||||
last_update_str = next(CSV)[0]
|
||||
|
||||
last_update = datetime.strptime(last_update_str, "%d/%m/%Y %H:%M:%S")
|
||||
|
||||
yday_closing = closing - dt.timedelta(days=1)
|
||||
yday_str = yday_closing.strftime("%d/%m/%Y %H:%M:%S")
|
||||
yday_closing = datetime.strptime(yday_str, "%d/%m/%Y %H:%M:%S")
|
||||
|
||||
|
||||
|
||||
if last_update < yday_closing:
|
||||
|
||||
updateStockPrices(symbols)
|
||||
|
||||
updateUpdate(NY_time)
|
||||
t = time.time()
|
||||
except Exception as e:
|
||||
logf.write(srt(e))
|
||||
logf.write(str(e))
|
||||
print(e)
|
||||
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
symbol,name,base,current,24hr change
|
||||
BTC,bitcoin,usd,32955,0.18795236810340699
|
||||
ETH,ethereum,gbp,1388.1,-1.2416916112022245
|
||||
BTC,bitcoin,usd,32675,3.7239980392362217
|
||||
ETH,ethereum,gbp,1317.79,1.854985374746106
|
||||
|
|
@ -1 +1 @@
|
||||
{"main_weather": "Clouds", "description": "overcast clouds", "temp": 26.64, "min_temp": 25.58, "max_temp": 27.4, "feels_like": 26.64, "humidity": 90, "clouds": 100, "wind_speed": 0.45, "wind_direction": 135, "visibility": 10000, "uv": 0, "rain_chance": 1}
|
||||
{"main_weather": "Rain", "description": "heavy intensity rain", "temp": 29.82, "min_temp": 28.3, "max_temp": 31.03, "feels_like": 36.82, "humidity": 86, "clouds": 100, "wind_speed": 0.45, "wind_direction": 16, "visibility": 10000, "uv": 0.45, "rain_chance": 0.39}
|
@ -1 +1 @@
|
||||
[{"main_weather": "Rain", "description": "heavy intensity rain", "min_temp": 24.83, "max_temp": 27.8}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 25.07, "max_temp": 26.83}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 26.55, "max_temp": 29}, {"main_weather": "Rain", "description": "light rain", "min_temp": 27.75, "max_temp": 29.78}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.93, "max_temp": 29.4}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 26.61, "max_temp": 28.14}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.57, "max_temp": 28.14}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 26.69, "max_temp": 28.13}]
|
||||
[{"main_weather": "Rain", "description": "heavy intensity rain", "min_temp": 28.09, "max_temp": 29.87}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.22, "max_temp": 28.97}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.19, "max_temp": 29.57}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.21, "max_temp": 29.37}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.28, "max_temp": 29.31}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.27, "max_temp": 29.43}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.03, "max_temp": 29.7}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 27.9, "max_temp": 29.98}]
|
@ -1 +1 @@
|
||||
22/06/2021 15:05:29
|
||||
27/06/2021 06:04:41
|
||||
|
|
1
csv/last_updates.json
Normal file
1
csv/last_updates.json
Normal file
@ -0,0 +1 @@
|
||||
{"stocks": "27/06/2021 07:05:39", "crypto": "27/06/2021 07:05:39", "news": "27/06/2021 07:05:39", "weather": "27/06/2021 07:05:39", "forex": "27/06/2021 07:05:39"}
|
1
csv/league.txt
Normal file
1
csv/league.txt
Normal file
@ -0,0 +1 @@
|
||||
NHL
|
40
csv/news.csv
40
csv/news.csv
@ -1,21 +1,21 @@
|
||||
headline,source,date,time
|
||||
‘I am not a vector’: Oireachtas committee hears from children affected by the pandemic - TheJournal.ie,TheJournal.ie,2021-06-22,18:30:00Z
|
||||
Liability conceded in case of couple ‘wrongly advised’ to terminate pregnancy - The Irish Times,The Irish Times,2021-06-22,18:15:58Z
|
||||
Delta COVID-19 variant greatest threat to US pandemic response - Fauci - GMA News Online,GMA News,2021-06-22,18:10:22Z
|
||||
LIVE WTC Final IND vs NZ Live Cricket Score^ Today Match DAY 5 Updates: Kohli-Pujara in; India Lead New Zeala - India.com,India.com,2021-06-22,18:08:55Z
|
||||
Prime Day headphone deals you shouldn't miss on AirPods^ Bose^ Beats^ Sony^ Samsung and more - CNET,CNET,2021-06-22,18:03:00Z
|
||||
Jack Grealish^ Bukayo Saka and Harry Maguire start for England against Czech Republic - Sky Sports,Sky Sports,2021-06-22,18:01:14Z
|
||||
Mother's gestational diabetes is an independent risk factor for fetal hypoxia during labor - News-Medical.Net,News-Medical.Net,2021-06-22,18:01:00Z
|
||||
Amazon sees Prime Day sales boost amid supply chain snags - CNA,CNA,2021-06-22,18:00:37Z
|
||||
Twitter opens applications for Ticketed Spaces and Super Follows test - The Verge,The Verge,2021-06-22,18:00:00Z
|
||||
Mastercard Foundation Appoints Robin Washington to Board of Directors - Guardian,Guardian Nigeria,2021-06-22,18:00:00Z
|
||||
Trudeau says border restrictions will be further relaxed 'in the coming weeks' if all goes well - CBC.ca,CBC News,2021-06-22,17:58:29Z
|
||||
Euro 2020 LIVE: Grealish and Maguire start for England^ Mount and Chilwell out of Czech Republic clash^... - talkSPORT.com,TalkSport,2021-06-22,17:47:23Z
|
||||
Quarter of a million children in England missed school last week due to Covid - The Guardian,The Guardian,2021-06-22,17:46:00Z
|
||||
'I am appalled': Billie Eilish apologizes for mouthing racial slur in resurfaced video - CBC.ca,CBC News,2021-06-22,17:45:46Z
|
||||
U.S. to narrowly miss Biden’s July 4 vaccination goal^ White House says - The Washington Post,The Washington Post,2021-06-22,17:45:00Z
|
||||
Vin Diesel explains feud with Dwayne Johnson: 'A lot of tough love' - Fox News,Fox News,2021-06-22,17:41:14Z
|
||||
Today’s coronavirus news: Two-thirds of Canadians say governments shouldn’t lift all restrictions; Construction complete on new vaccine-manufacturing plant in Montreal; Ontario reporting 296 cases - Toronto Star,Toronto Star,2021-06-22,17:37:30Z
|
||||
‘Tembisa 10’: Piet Rampedi pens apology to Independent Media staff for baby saga - News24,News24,2021-06-22,17:33:26Z
|
||||
Stinging secret: research reveals how venom from Australian caterpillars could be used in medicines - The Guardian,The Guardian,2021-06-22,17:31:00Z
|
||||
Doc Rivers not giving up on Ben Simmons^ says 76ers have a plan in place to improve his shooting struggles - CBS Sports,CBS Sports,2021-06-22,17:28:00Z
|
||||
China's Zhurong rover returns landing footage and sounds from Mars - SpaceNews,SpaceNews,2021-06-27,08:42:29Z
|
||||
Jammu Airport Blasts LIVE Updates: NIA Likely to Probe Case^ Flight Ops Normal; IAF Stations in Punjab & Srinagar on High Alert - News18,News18,2021-06-27,08:41:51Z
|
||||
Lacson bares what he expects to hear from Duterte's final SONA - GMA News Online,GMA News,2021-06-27,08:37:03Z
|
||||
A-League grand final LIVE updates: Red-hot City lead 2-1 over 10-man Sydney FC - The Sydney Morning Herald,The Sydney Morning Herald,2021-06-27,08:30:20Z
|
||||
Why most people who now die with Covid in England have been vaccinated - The Guardian,The Guardian,2021-06-27,08:22:00Z
|
||||
Some families frustrated by pace of search and rescue efforts in Florida building collapse - CNN ,CNN,2021-06-27,08:11:00Z
|
||||
PH’s COVID-19 cases nears 1.4 million-mark with 6^096 new infections - INQUIRER.net,Inquirer.net,2021-06-27,08:04:00Z
|
||||
How to use Alexa Whisper Mode on an Amazon Echo - TechRadar,TechRadar,2021-06-27,08:00:00Z
|
||||
Low vitamin D can raise death risk from Covid by 20% - ETHealthworld.com,The Times of India,2021-06-27,07:58:20Z
|
||||
M5.0 quake strikes near Surigao del Sur - SunStar Philippines,Sunstar.com.ph,2021-06-27,07:56:05Z
|
||||
Statesmen think of the next generation^ not the next election - Rafidah blasts MCO inconsistency - Malaysiakini,Malaysiakini,2021-06-27,07:54:50Z
|
||||
Long Covid: 'I've blood clots^ a braced leg and damaged heart... but I'm home' - The Samford Crimson,Samfordcrimson.com,2021-06-27,07:54:34Z
|
||||
Guns of the west: Hot Dogs dominate Eagles in Perth - AFL,Afl.com.au,2021-06-27,07:53:00Z
|
||||
China releases videos of rover on Mars - Yahoo News,Yahoo Entertainment,2021-06-27,07:53:00Z
|
||||
Five dead^ 156 still missing in Florida building collapse as searchers race against time - News24,News24,2021-06-27,07:44:27Z
|
||||
Singapore detects 14 new COVID-19 cases; 12 in community - Yahoo Singapore News,Yahoo Entertainment,2021-06-27,07:44:23Z
|
||||
Indonesia commends JTF Tawi-Tawi for rescue of 4 kidnap victims - GMA News Online,GMA News,2021-06-27,07:41:53Z
|
||||
Don't copy Bollywood: Imran Khan's advice to Pakistani filmmakers - Hindustan Times,Hindustan Times,2021-06-27,07:41:00Z
|
||||
Rugby league: New Zealand Warriors to lose Euan Aitken and Josh Curran for two weeks after Covid-19 scare - New Zealand Herald,New Zealand Herald,2021-06-27,07:39:23Z
|
||||
Watch the incredible moment Massey High School player sinks wild three-point buzzer-beater - Stuff.co.nz,Stuff.co.nz,2021-06-27,07:39:00Z
|
||||
|
|
@ -1 +1 @@
|
||||
[{"date": "2021-06-23", "time": "01:00:00", "round": "0", "home_team": "Phoenix Suns", "home_score": null, "away_team": "Los Angeles Clippers", "away_score": null}, {"date": "2021-06-24", "time": "00:30:00", "round": "0", "home_team": "Milwaukee Bucks", "home_score": null, "away_team": "Atlanta Hawks", "away_score": null}, {"date": "2021-06-25", "time": "01:00:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": null, "away_team": "Phoenix Suns", "away_score": null}, {"date": "2021-06-26", "time": "00:30:00", "round": "0", "home_team": "Milwaukee Bucks", "home_score": null, "away_team": "Atlanta Hawks", "away_score": null}, {"date": "2021-06-27", "time": "01:00:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": null, "away_team": "Phoenix Suns", "away_score": null}, {"date": "2021-06-28", "time": "00:30:00", "round": "0", "home_team": "Atlanta Hawks", "home_score": null, "away_team": "Milwaukee Bucks", "away_score": null}, {"date": "2021-06-30", "time": "00:30:00", "round": "0", "home_team": "Atlanta Hawks", "home_score": null, "away_team": "Milwaukee Bucks", "away_score": null}]
|
||||
[{"date": "2021-06-27", "time": "01:00:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": "80", "away_team": "Phoenix Suns", "away_score": "84"}, {"date": "2021-06-28", "time": "00:30:00", "round": "0", "home_team": "Atlanta Hawks", "home_score": null, "away_team": "Milwaukee Bucks", "away_score": null}, {"date": "2021-06-29", "time": "01:00:00", "round": "0", "home_team": "Phoenix Suns", "home_score": null, "away_team": "Los Angeles Clippers", "away_score": null}, {"date": "2021-06-30", "time": "00:30:00", "round": "0", "home_team": "Atlanta Hawks", "home_score": null, "away_team": "Milwaukee Bucks", "away_score": null}]
|
@ -1 +1 @@
|
||||
[]
|
||||
[{"date": "2021-06-27", "time": "01:00", "progess": "", "status": "FT", "home_team": "Los Angeles Clippers", "home_score": "80", "away_team": "Phoenix Suns", "away_score": "84"}]
|
@ -1 +1 @@
|
||||
[{"date": "2021-06-21", "time": "00:00:00", "round": "0", "home_team": "Philadelphia 76ers", "home_score": "96", "away_team": "Atlanta Hawks", "away_score": "103"}, {"date": "2021-06-20", "time": "19:30:00", "round": "0", "home_team": "Phoenix Suns", "home_score": "120", "away_team": "Los Angeles Clippers", "away_score": "114"}, {"date": "2021-06-20", "time": "00:30:00", "round": "0", "home_team": "Brooklyn Nets", "home_score": "111", "away_team": "Milwaukee Bucks", "away_score": "115"}, {"date": "2021-06-19", "time": "02:00:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": "131", "away_team": "Utah Jazz", "away_score": "119"}, {"date": "2021-06-18", "time": "23:30:00", "round": "0", "home_team": "Atlanta Hawks", "home_score": "99", "away_team": "Philadelphia 76ers", "away_score": "104"}, {"date": "2021-06-18", "time": "00:30:00", "round": "0", "home_team": "Milwaukee Bucks", "home_score": "104", "away_team": "Brooklyn Nets", "away_score": "89"}, {"date": "2021-06-17", "time": "02:00:00", "round": "0", "home_team": "Utah Jazz", "home_score": "111", "away_team": "Los Angeles Clippers", "away_score": "119"}, {"date": "2021-06-16", "time": "00:30:00", "round": "0", "home_team": "Brooklyn Nets", "home_score": "114", "away_team": "Milwaukee Bucks", "away_score": "108"}, {"date": "2021-06-16", "time": "23:30:00", "round": "0", "home_team": "Philadelphia 76ers", "home_score": "106", "away_team": "Atlanta Hawks", "away_score": "109"}, {"date": "2021-06-15", "time": "02:00:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": "118", "away_team": "Utah Jazz", "away_score": "104"}, {"date": "2021-06-14", "time": "23:30:00", "round": "0", "home_team": "Atlanta Hawks", "home_score": "103", "away_team": "Philadelphia 76ers", "away_score": "100"}, {"date": "2021-06-14", "time": "00:00:00", "round": "0", "home_team": "Denver Nuggets", "home_score": "118", "away_team": "Phoenix Suns", "away_score": "125"}, {"date": "2021-06-13", "time": "00:30:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": "132", "away_team": "Utah Jazz", "away_score": "106"}, {"date": "2021-06-13", "time": "19:00:00", "round": "0", "home_team": "Milwaukee Bucks", "home_score": "107", "away_team": "Brooklyn Nets", "away_score": "96"}, {"date": "2021-06-12", "time": "02:00:00", "round": "0", "home_team": "Denver Nuggets", "home_score": "102", "away_team": "Phoenix Suns", "away_score": "116"}]
|
||||
[{"date": "2021-06-26", "time": "00:30:00", "round": "0", "home_team": "Milwaukee Bucks", "home_score": "125", "away_team": "Atlanta Hawks", "away_score": "91"}, {"date": "2021-06-25", "time": "01:00:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": "106", "away_team": "Phoenix Suns", "away_score": "92"}, {"date": "2021-06-24", "time": "00:30:00", "round": "0", "home_team": "Milwaukee Bucks", "home_score": "113", "away_team": "Atlanta Hawks", "away_score": "116"}, {"date": "2021-06-23", "time": "01:00:00", "round": "0", "home_team": "Phoenix Suns", "home_score": "104", "away_team": "Los Angeles Clippers", "away_score": "103"}, {"date": "2021-06-21", "time": "00:00:00", "round": "0", "home_team": "Philadelphia 76ers", "home_score": "96", "away_team": "Atlanta Hawks", "away_score": "103"}, {"date": "2021-06-20", "time": "19:30:00", "round": "0", "home_team": "Phoenix Suns", "home_score": "120", "away_team": "Los Angeles Clippers", "away_score": "114"}, {"date": "2021-06-20", "time": "00:30:00", "round": "0", "home_team": "Brooklyn Nets", "home_score": "111", "away_team": "Milwaukee Bucks", "away_score": "115"}, {"date": "2021-06-19", "time": "02:00:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": "131", "away_team": "Utah Jazz", "away_score": "119"}, {"date": "2021-06-18", "time": "23:30:00", "round": "0", "home_team": "Atlanta Hawks", "home_score": "99", "away_team": "Philadelphia 76ers", "away_score": "104"}, {"date": "2021-06-18", "time": "00:30:00", "round": "0", "home_team": "Milwaukee Bucks", "home_score": "104", "away_team": "Brooklyn Nets", "away_score": "89"}, {"date": "2021-06-17", "time": "02:00:00", "round": "0", "home_team": "Utah Jazz", "home_score": "111", "away_team": "Los Angeles Clippers", "away_score": "119"}, {"date": "2021-06-16", "time": "00:30:00", "round": "0", "home_team": "Brooklyn Nets", "home_score": "114", "away_team": "Milwaukee Bucks", "away_score": "108"}, {"date": "2021-06-16", "time": "23:30:00", "round": "0", "home_team": "Philadelphia 76ers", "home_score": "106", "away_team": "Atlanta Hawks", "away_score": "109"}, {"date": "2021-06-15", "time": "02:00:00", "round": "0", "home_team": "Los Angeles Clippers", "home_score": "118", "away_team": "Utah Jazz", "away_score": "104"}, {"date": "2021-06-14", "time": "23:30:00", "round": "0", "home_team": "Atlanta Hawks", "home_score": "103", "away_team": "Philadelphia 76ers", "away_score": "100"}]
|
@ -1 +1 @@
|
||||
[{"date": "2021-06-22", "time": "00:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "8", "away_team": "New York Islanders", "away_score": "0"}, {"date": "2021-06-23", "time": "01:00:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": null, "away_team": "Montreal Canadiens", "away_score": null}, {"date": "2021-06-24", "time": "00:00:00", "round": "0", "home_team": "New York Islanders", "home_score": null, "away_team": "Tampa Bay Lightning", "away_score": null}, {"date": "2021-06-25", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": null, "away_team": "Vegas Golden Knights", "away_score": null}]
|
||||
[]
|
@ -1 +1 @@
|
||||
[{"date": "2021-06-22", "time": "00:00", "progess": "", "status": "FT", "home_team": "Tampa Bay Lightning", "home_score": "8", "away_team": "New York Islanders", "away_score": "0"}]
|
||||
[]
|
@ -1 +1 @@
|
||||
[{"date": "2021-06-21", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": "1", "away_team": "Vegas Golden Knights", "away_score": "2"}, {"date": "2021-06-20", "time": "00:00:00", "round": "0", "home_team": "New York Islanders", "home_score": "3", "away_team": "Tampa Bay Lightning", "away_score": "2"}, {"date": "2021-06-19", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": "3", "away_team": "Vegas Golden Knights", "away_score": "2"}, {"date": "2021-06-18", "time": "00:00:00", "round": "0", "home_team": "New York Islanders", "home_score": "1", "away_team": "Tampa Bay Lightning", "away_score": "2"}, {"date": "2021-06-17", "time": "01:00:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": "2", "away_team": "Montreal Canadiens", "away_score": "3"}, {"date": "2021-06-16", "time": "00:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "4", "away_team": "New York Islanders", "away_score": "2"}, {"date": "2021-06-15", "time": "01:00:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": "4", "away_team": "Montreal Canadiens", "away_score": "1"}, {"date": "2021-06-13", "time": "19:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "1", "away_team": "New York Islanders", "away_score": "2"}, {"date": "2021-06-11", "time": "01:00:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": "6", "away_team": "Colorado Avalanche", "away_score": "3"}, {"date": "2021-06-09", "time": "23:30:00", "round": "0", "home_team": "New York Islanders", "home_score": "6", "away_team": "Boston Bruins", "away_score": "2"}, {"date": "2021-06-09", "time": "01:00:00", "round": "0", "home_team": "Colorado Avalanche", "home_score": "2", "away_team": "Vegas Golden Knights", "away_score": "3"}, {"date": "2021-06-08", "time": "22:30:00", "round": "0", "home_team": "Carolina Hurricanes", "home_score": "0", "away_team": "Tampa Bay Lightning", "away_score": "2"}, {"date": "2021-06-08", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": "3", "away_team": "Winnipeg Jets", "away_score": "2"}, {"date": "2021-06-07", "time": "22:30:00", "round": "0", "home_team": "Boston Bruins", "home_score": "4", "away_team": "New York Islanders", "away_score": "5"}, {"date": "2021-06-07", "time": "00:30:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": "5", "away_team": "Colorado Avalanche", "away_score": "1"}]
|
||||
[{"date": "2021-06-26", "time": "00:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "1", "away_team": "New York Islanders", "away_score": "0"}, {"date": "2021-06-25", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": "3", "away_team": "Vegas Golden Knights", "away_score": "2"}, {"date": "2021-06-24", "time": "00:00:00", "round": "0", "home_team": "New York Islanders", "home_score": "3", "away_team": "Tampa Bay Lightning", "away_score": "2"}, {"date": "2021-06-23", "time": "01:00:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": "1", "away_team": "Montreal Canadiens", "away_score": "4"}, {"date": "2021-06-22", "time": "00:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "8", "away_team": "New York Islanders", "away_score": "0"}, {"date": "2021-06-21", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": "1", "away_team": "Vegas Golden Knights", "away_score": "2"}, {"date": "2021-06-20", "time": "00:00:00", "round": "0", "home_team": "New York Islanders", "home_score": "3", "away_team": "Tampa Bay Lightning", "away_score": "2"}, {"date": "2021-06-19", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": "3", "away_team": "Vegas Golden Knights", "away_score": "2"}, {"date": "2021-06-18", "time": "00:00:00", "round": "0", "home_team": "New York Islanders", "home_score": "1", "away_team": "Tampa Bay Lightning", "away_score": "2"}, {"date": "2021-06-17", "time": "01:00:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": "2", "away_team": "Montreal Canadiens", "away_score": "3"}, {"date": "2021-06-16", "time": "00:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "4", "away_team": "New York Islanders", "away_score": "2"}, {"date": "2021-06-15", "time": "01:00:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": "4", "away_team": "Montreal Canadiens", "away_score": "1"}, {"date": "2021-06-13", "time": "19:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "1", "away_team": "New York Islanders", "away_score": "2"}, {"date": "2021-06-11", "time": "01:00:00", "round": "0", "home_team": "Vegas Golden Knights", "home_score": "6", "away_team": "Colorado Avalanche", "away_score": "3"}, {"date": "2021-06-09", "time": "23:30:00", "round": "0", "home_team": "New York Islanders", "home_score": "6", "away_team": "Boston Bruins", "away_score": "2"}]
|
1
csv/table_league.txt
Normal file
1
csv/table_league.txt
Normal file
@ -0,0 +1 @@
|
||||
premier_league
|
@ -1,4 +1,4 @@
|
||||
name,current,opening
|
||||
MSFT,265.24,262.72
|
||||
NFLX,511.198,498.54
|
||||
GOOG,2536.73,2529
|
||||
MSFT,265.02,266.23
|
||||
NFLX,527.07,528.84
|
||||
GOOG,2539.9,2539.14
|
||||
|
|
Binary file not shown.
BIN
display_images/daily_weather.ppm
Normal file
BIN
display_images/daily_weather.ppm
Normal file
Binary file not shown.
Binary file not shown.
BIN
display_images/league_games.ppm
Normal file
BIN
display_images/league_games.ppm
Normal file
Binary file not shown.
BIN
display_images/league_table.ppm
Normal file
BIN
display_images/league_table.ppm
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
display_images/today_weather.ppm
Normal file
BIN
display_images/today_weather.ppm
Normal file
Binary file not shown.
2
setup.sh
2
setup.sh
@ -7,7 +7,7 @@ pip3 install pexpect
|
||||
sudo apt-get install libopenjp2-7
|
||||
sudo apt-get install libtiff5
|
||||
|
||||
chmod ugo+rwx display_images/*
|
||||
chmod -R ugo+rwx display_images
|
||||
cd rpi-rgb-led-matrix
|
||||
sudo apt-get update && sudo apt-get install python3-dev python3-pillow -y
|
||||
make build-python PYTHON=$(which python3)
|
||||
|
204
stockTicker.py
204
stockTicker.py
@ -219,14 +219,15 @@ class StockTicker():
|
||||
|
||||
def scrollFunctionsAnimated(self, options, animation = 'continuous'):
|
||||
# scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed
|
||||
self.updateMultiple(options)
|
||||
|
||||
self.updateMultiple([options[0]])
|
||||
|
||||
print('done update')
|
||||
kill = False
|
||||
i = 0 # keep track of which image we are displaying
|
||||
while True:
|
||||
|
||||
update_process = Process(target = self.updateMultiple, args = (options,))
|
||||
update_process = Process(target = self.updateMultiple, args = ([options[(i+1) % len(options)]],))
|
||||
update_process.start()
|
||||
print('display_images/' + options[i % len(options)] +'.ppm')
|
||||
|
||||
@ -244,26 +245,31 @@ class StockTicker():
|
||||
#first scroll image in from bottom
|
||||
|
||||
if animation == 'up':
|
||||
offset_y = 32
|
||||
offset_y = 33
|
||||
while offset_y > 0:
|
||||
|
||||
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
offset_y -= 1
|
||||
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
time.sleep(self.delay)
|
||||
kill = self.checkKilled()
|
||||
if kill: break
|
||||
time.sleep(1)
|
||||
|
||||
elif animation == 'down':
|
||||
offset_y = -32
|
||||
offset_y = -33
|
||||
while offset_y < 0:
|
||||
|
||||
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
offset_y += 1
|
||||
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
time.sleep(self.delay)
|
||||
kill = self.checkKilled()
|
||||
if kill: break
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -302,7 +308,7 @@ class StockTicker():
|
||||
i+=1
|
||||
|
||||
|
||||
def textImage(self, text, font, r = 255, g = 255, b = 255, matrix_height = False, buff = 0):
|
||||
def textImage(self, text, font, r = 255, g = 255, b = 255, matrix_height = False, w_buff = 3, h_buff = 3):
|
||||
'''
|
||||
creates and returns a ppm image containing the text in the supplied font and colour
|
||||
'''
|
||||
@ -311,7 +317,7 @@ class StockTicker():
|
||||
|
||||
if matrix_height:
|
||||
height = 32
|
||||
img = Image.new('RGB', (width + buff + 3, height+3))
|
||||
img = Image.new('RGB', (width + w_buff, height + h_buff))
|
||||
d = ImageDraw.Draw(img)
|
||||
|
||||
d.text((0, 0), text, fill=(r, g, b), font=font)
|
||||
@ -336,64 +342,6 @@ class StockTicker():
|
||||
img = self.textImage(text, font, int(r), int(g), int(b), True, buff = 50)
|
||||
return img
|
||||
|
||||
|
||||
def getNewsImage(self):
|
||||
headline_font = ImageFont.load("./fonts/10x20.pil")
|
||||
source_font = ImageFont.load("./fonts/10x20.pil")
|
||||
|
||||
image_list = []
|
||||
|
||||
headlines = []
|
||||
source_date_times = []
|
||||
|
||||
f = open('csv/news.csv', 'r')
|
||||
CSV = csv.reader(f)
|
||||
next(CSV)
|
||||
for row in CSV:
|
||||
headline, source, date, time = row
|
||||
headlines.append(headline)
|
||||
source_date_times.append(source + ': ' + date + ' ' + time)
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
for i, headline in enumerate(headlines):
|
||||
headline = headline.replace("^", ",")
|
||||
headline = headline.replace("’", "'")
|
||||
headline = headline.replace("‘", "'")
|
||||
headline = headline.replace('“', '"')
|
||||
headline = headline.replace('”', '"')
|
||||
|
||||
headline_img = self.textImage(headline, headline_font, matrix_height = True)
|
||||
source_img = self.textImage(source_date_times[i], source_font, r=255, g=255, b=0, matrix_height = True)
|
||||
|
||||
|
||||
try:
|
||||
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'news_logos')
|
||||
|
||||
logo = Image.open(os.path.join(logos_path, 'techcrunch' + '.png'))
|
||||
|
||||
img = Image.new('RGB', (headline_img.size[0], 32))
|
||||
img.paste(headline_img, (2, -3))
|
||||
img.paste(source_img, (2,16))
|
||||
|
||||
img= self.stitchImage([logo,img])
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
img = Image.new('RGB', (headline_img.size[0], 32))
|
||||
img.paste(headline_img, (0,0))
|
||||
img.paste(source_img, (0,16))
|
||||
|
||||
image_list.append(img)
|
||||
|
||||
news_image = self.stitchImage(image_list)
|
||||
|
||||
return news_image
|
||||
|
||||
|
||||
|
||||
def displayGIF(self, gif):
|
||||
# To iterate through the entire gif
|
||||
i = 0
|
||||
@ -696,11 +644,78 @@ class StockTicker():
|
||||
return finalDisplayImage
|
||||
|
||||
|
||||
def getLeagueImage(self, league, time):
|
||||
def getNewsImage(self):
|
||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||
title_img = self.textImage('NEWS', font, matrix_height = True)
|
||||
|
||||
|
||||
|
||||
headline_font = ImageFont.load("./fonts/10x20.pil")
|
||||
source_font = ImageFont.load("./fonts/10x20.pil")
|
||||
|
||||
image_list = [title_img]
|
||||
|
||||
headlines = []
|
||||
source_date_times = []
|
||||
|
||||
f = open('csv/news.csv', 'r')
|
||||
CSV = csv.reader(f)
|
||||
next(CSV)
|
||||
for row in CSV:
|
||||
headline, source, date, time = row
|
||||
headlines.append(headline)
|
||||
source_date_times.append(source + ': ' + date + ' ' + time)
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
for i, headline in enumerate(headlines):
|
||||
headline = headline.replace("^", ",")
|
||||
headline = headline.replace("’", "'")
|
||||
headline = headline.replace("‘", "'")
|
||||
headline = headline.replace('“', '"')
|
||||
headline = headline.replace('”', '"')
|
||||
|
||||
headline_img = self.textImage(headline, headline_font, matrix_height = True)
|
||||
source_img = self.textImage(source_date_times[i], source_font, r=255, g=255, b=0, matrix_height = True)
|
||||
|
||||
|
||||
try:
|
||||
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'news_logos')
|
||||
|
||||
logo = Image.open(os.path.join(logos_path, 'techcrunch' + '.png'))
|
||||
|
||||
img = Image.new('RGB', (headline_img.size[0], 32))
|
||||
img.paste(headline_img, (2, -3))
|
||||
img.paste(source_img, (2,16))
|
||||
|
||||
img= self.stitchImage([logo,img])
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
img = Image.new('RGB', (headline_img.size[0], 32))
|
||||
img.paste(headline_img, (0,0))
|
||||
img.paste(source_img, (0,16))
|
||||
|
||||
image_list.append(img)
|
||||
|
||||
news_image = self.stitchImage(image_list)
|
||||
|
||||
return news_image
|
||||
|
||||
def getLeagueImage(self, league=False, time = 'past'):
|
||||
|
||||
if not league:
|
||||
f = open( "csv/league.txt", 'r' )
|
||||
league = f.read().replace('\n', '')
|
||||
f.close()
|
||||
|
||||
img = Image.new('RGB', (10000, 32))
|
||||
league_info = json.load(open('csv/sports/{}/{}_games.json'.format(league, time), 'r'))
|
||||
|
||||
print(league_info[0].keys())
|
||||
|
||||
small_font = ImageFont.load("./fonts/5x7.pil")
|
||||
med_font = ImageFont.load("./fonts/7x14B.pil")
|
||||
large_font = ImageFont.load("./fonts/9x18B.pil")
|
||||
@ -743,16 +758,7 @@ class StockTicker():
|
||||
away_logo = self.textImage(away_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
|
||||
print(e)
|
||||
|
||||
|
||||
|
||||
|
||||
#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 = 255)
|
||||
#round_timage = self.textImage('round:' + rond, small_font, r = 255, g = 255, b = 255)
|
||||
|
||||
|
||||
|
||||
|
||||
img.paste(home_logo, (x_offset,0))
|
||||
|
||||
@ -761,9 +767,6 @@ class StockTicker():
|
||||
|
||||
if time == 'future':
|
||||
img.paste(date_timage, (x_offset+5, 0))
|
||||
#vs_timage = self.textImage(sports_info[home_team]['code'] + 'vs' + sports_info[away_team]['code'], med_font, r = 255, g = 255, b = 255)
|
||||
|
||||
#img.paste(vs_timage, (x_offset, 12))
|
||||
|
||||
h_colour = mcolors.to_rgb(sports_info[home_team]['colour'].replace(' ', ''))
|
||||
a_colour = mcolors.to_rgb(sports_info[away_team]['colour'].replace(' ', ''))
|
||||
@ -779,9 +782,7 @@ class StockTicker():
|
||||
x_offset += max( date_timage.size[0], hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0])
|
||||
else:
|
||||
|
||||
|
||||
|
||||
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, h_buff = 5, r = 255, g = 255, b = 255)
|
||||
|
||||
#vs_timage = self.textImage(sports_info[home_team]['code'] + 'vs' + sports_info[away_team]['code'], small_font, r = 255, g = 255, b = 255)
|
||||
|
||||
@ -832,10 +833,18 @@ class StockTicker():
|
||||
x_offset += buff_size
|
||||
img = img.crop((0,0,x_offset ,32))
|
||||
|
||||
return img
|
||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||
title_img = self.textImage(time.upper() + ' GAMES', font, matrix_height = True)
|
||||
|
||||
def getTeamsImage(self, league):
|
||||
return self.stitchImage([title_img, img])
|
||||
|
||||
def getLeagueTableImage(self, league = False):
|
||||
|
||||
|
||||
if not league:
|
||||
f = open( "csv/table_league.txt", 'r' )
|
||||
league = f.read().replace('\n', '')
|
||||
f.close()
|
||||
img = Image.new('RGB', (10000, 32))
|
||||
team_info = json.load(open('csv/sports/{}/team_stats.json'.format(league), 'r'))
|
||||
|
||||
@ -886,7 +895,10 @@ class StockTicker():
|
||||
|
||||
img = img.crop((0,0,x_offset ,32))
|
||||
|
||||
return img
|
||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||
title_img = self.textImage('LEAGUE TABLE', font, matrix_height = True)
|
||||
|
||||
return self.stitchImage([title_img, img])
|
||||
|
||||
|
||||
def getTodayWeatherImage(self):
|
||||
@ -993,7 +1005,10 @@ class StockTicker():
|
||||
vtext_img = self.textImage(str(current_weather['visibility']/1000) + 'km', small_font)
|
||||
img.paste(vtext_img, (168, 22))
|
||||
|
||||
return img
|
||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||
title_img = self.textImage('WEATHER', font, matrix_height = True)
|
||||
|
||||
return self.stitchImage([title_img, img])
|
||||
|
||||
def getDailyWeatherImageAlt(self):
|
||||
|
||||
@ -1313,9 +1328,11 @@ class StockTicker():
|
||||
|
||||
img1 = img.crop((0,0,x_offset ,32))
|
||||
|
||||
# add the image text
|
||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||
title_img = self.textImage('WEATHER', font, matrix_height = True)
|
||||
|
||||
|
||||
return img1
|
||||
return self.stitchImage([title_img, img1])
|
||||
|
||||
|
||||
#Retrieve symbols and stock info from the csv file
|
||||
@ -1503,8 +1520,8 @@ class StockTicker():
|
||||
|
||||
stock_ticker.scrollImageTransition(['display_images/league.ppm', 'display_images/league.ppm'], stocks = False)
|
||||
|
||||
elif msg == 't': #teams
|
||||
img = self.getTeamsImage('premier_league')
|
||||
elif msg == 't': #legue tble
|
||||
img = self.getLeagueTableImage('premier_league')
|
||||
img.save('display_images/teams.ppm')
|
||||
|
||||
stock_ticker.scrollImageTransition(['display_images/teams.ppm', 'display_images/teams.ppm'], stocks = False)
|
||||
@ -1512,9 +1529,10 @@ class StockTicker():
|
||||
elif msg == 'A': #everything
|
||||
|
||||
self.functions = {'stocks': self.getStockImage, 'crypto': self.getCryptoImage, 'forex': self.getForexImage,
|
||||
'weather':self.getDailyWeatherImage} #put this somewhere else
|
||||
'daily_weather':self.getDailyWeatherImage, 'today_weather': self.getDailyWeatherImage, 'league_table': self.getLeagueTableImage,
|
||||
'league_games': self.getLeagueImage, 'news':self.getNewsImage} #put this somewhere else
|
||||
|
||||
userSettings = ['stocks', 'crypto', 'forex'] # these wil be read from csv, just for demo
|
||||
userSettings = ['stocks', 'crypto', 'forex', 'today_weather', 'daily_weather', 'league_table', 'league_games', 'news'] # these wil be read from csv, just for demo
|
||||
#userSettings = ['stocks', 'crypto'] # these wil be read from csv, just for demo
|
||||
#userSettings = [ 'forex', 'weather'] # these wil be read from csv, just for demo
|
||||
|
||||
@ -1530,7 +1548,7 @@ if __name__ == '__main__':
|
||||
stock_ticker = StockTicker()
|
||||
|
||||
#stock_ticker.process_msg('P')
|
||||
#stock_ticker.process_msg('A')
|
||||
stock_ticker.process_msg('P')
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user