bug fix and professional display started
This commit is contained in:
parent
2b3fff395a
commit
cc48129f69
@ -29,6 +29,7 @@ def readCSV(file_path, max_stocks):
|
||||
next(CSV)
|
||||
i = 0
|
||||
for row in CSV:
|
||||
|
||||
if i < max_stocks:
|
||||
i += 1
|
||||
|
||||
@ -60,26 +61,26 @@ def readCryptoCSV(file_path, max_crypto):
|
||||
unique_bases = []
|
||||
for row in CSV:
|
||||
print(row)
|
||||
if i >= max_stocks:
|
||||
break
|
||||
i += 1
|
||||
if i < max_crypto:
|
||||
|
||||
i += 1
|
||||
|
||||
try:
|
||||
symbol, name, base, current_price, opening_price = row
|
||||
symbols.append(symbol)
|
||||
names.append(name)
|
||||
stock_info[name] = [symbol, base, current_price, opening_price]
|
||||
if base not in unique_bases:
|
||||
unique_bases.append(base)
|
||||
except:
|
||||
symbol, name, base = row
|
||||
if base not in unique_bases:
|
||||
unique_bases.append(base)
|
||||
symbols.append(symbol)
|
||||
names.append(name)
|
||||
stock_info[name] = [symbol, base]
|
||||
try:
|
||||
symbol, name, base, current_price, opening_price = row
|
||||
symbols.append(symbol)
|
||||
names.append(name)
|
||||
stock_info[name] = [symbol, base, current_price, opening_price]
|
||||
if base not in unique_bases:
|
||||
unique_bases.append(base)
|
||||
except:
|
||||
symbol, name, base = row
|
||||
if base not in unique_bases:
|
||||
unique_bases.append(base)
|
||||
symbols.append(symbol)
|
||||
names.append(name)
|
||||
stock_info[name] = [symbol, base]
|
||||
else:
|
||||
print('max stocks exceeded')
|
||||
print(i, max_crypto, 'max crypto exceeded')
|
||||
break
|
||||
|
||||
f.close()
|
||||
@ -218,7 +219,7 @@ def updateStockPricesIEX():
|
||||
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])))
|
||||
raise e
|
||||
|
||||
sys.exit()
|
||||
|
||||
|
||||
@ -228,7 +229,7 @@ def updateCrypto():
|
||||
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)
|
||||
|
||||
print(response)
|
||||
CSV = open('csv/crypto.csv', 'w+')
|
||||
CSV.write('symbol,name,base,current,24hr change\n')
|
||||
|
||||
@ -464,7 +465,7 @@ def updateLeagueEvents(api_key, league_id, time):
|
||||
all_data = r.json()
|
||||
|
||||
print()
|
||||
#print(all_data['events'][0].keys())
|
||||
print(all_data['events'])
|
||||
#print([all_data['events'][i]['strTimestamp'] for i in range(len(all_data['events']))])
|
||||
|
||||
events = []
|
||||
@ -519,13 +520,13 @@ def updateSports():
|
||||
NBA_id = '4387' #prem
|
||||
NFL_id = '4391'
|
||||
|
||||
for i in [NHL_id]:
|
||||
for i in [NHL_id, prem_id]:
|
||||
updateLeagueEvents(api_key, i, 'live')
|
||||
updateLeagueEvents(api_key, i, 'past')
|
||||
updateLeagueEvents(api_key, i, 'future')
|
||||
|
||||
|
||||
|
||||
print('sports updated')
|
||||
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
|
||||
@ -588,9 +589,11 @@ if __name__ == '__main__':
|
||||
max_stocks = 200
|
||||
max_crypto = 100
|
||||
|
||||
|
||||
|
||||
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
|
||||
|
||||
update_frequencies = {'stocks':2, 'crypto':10, 'news':120, 'weather': 10} #minutes
|
||||
update_frequencies = {'stocks':2, 'crypto':10, 'news':120, 'weather': 10, 'sports': 120} #minutes
|
||||
|
||||
NY_zone = pytz.timezone('America/New_York')
|
||||
CET_zone = pytz.timezone('Europe/Berlin')
|
||||
@ -614,7 +617,6 @@ if __name__ == '__main__':
|
||||
t = time.time()
|
||||
|
||||
|
||||
|
||||
try:
|
||||
while True:
|
||||
|
||||
@ -631,7 +633,7 @@ if __name__ == '__main__':
|
||||
|
||||
# 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
|
||||
@ -643,7 +645,7 @@ if __name__ == '__main__':
|
||||
|
||||
# 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
|
||||
@ -655,7 +657,7 @@ if __name__ == '__main__':
|
||||
|
||||
# news
|
||||
news_time = datetime.strptime(last_updates['news'], "%d/%m/%Y %H:%M:%S")
|
||||
news_frequency = update_frequencies['news']
|
||||
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - news_time).total_seconds()/60 #minutes
|
||||
@ -664,6 +666,17 @@ if __name__ == '__main__':
|
||||
updateNews()
|
||||
last_updates['news'] = news_time
|
||||
|
||||
# sports
|
||||
sports_time = datetime.strptime(last_updates['sports'], "%d/%m/%Y %H:%M:%S")
|
||||
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - sports_time).total_seconds()/60 #minutes
|
||||
if diff >= update_frequencies['sports']:
|
||||
sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
updateSports()
|
||||
last_updates['sports'] = sports_time
|
||||
|
||||
#forex updates once every 24hours at 1700 CET
|
||||
|
||||
# update if last update was before the previous days closing
|
||||
@ -676,6 +689,10 @@ if __name__ == '__main__':
|
||||
last_updates['forex'] = forex_time
|
||||
updateForex()
|
||||
|
||||
f = open('csv/last_updates.json', 'w+')
|
||||
json.dump(last_updates, f)
|
||||
f.close()
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
|
@ -1,3 +1,4 @@
|
||||
symbol,name,base,current,24hr change
|
||||
BTC,bitcoin,usd,34390,4.744355545187088
|
||||
ETH,ethereum,gbp,1516.42,15.455756498827048
|
||||
BTC,bitcoin,usd,34115,-3.9390505068289396
|
||||
ETH,ethereum,gbp,1613.18,-5.164585106324053
|
||||
DOGE,dogecoin,usd,0.234738,-5.759603392786582
|
||||
|
|
@ -1 +1 @@
|
||||
{"main_weather": "Clouds", "description": "overcast clouds", "temp": 28.98, "min_temp": 28.22, "max_temp": 29.56, "feels_like": 35.98, "humidity": 91, "clouds": 100, "wind_speed": 0.45, "wind_direction": 320, "visibility": 10000, "uv": 0, "rain_chance": 0.98}
|
||||
{"main_weather": "Clouds", "description": "overcast clouds", "temp": 16.03, "min_temp": 13.39, "max_temp": 20.92, "feels_like": 15.75, "humidity": 79, "clouds": 100, "wind_speed": 4.12, "wind_direction": 150, "visibility": 10000, "uv": 0.1, "rain_chance": 0.19}
|
@ -1 +1 @@
|
||||
[{"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.22, "max_temp": 29.56}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28, "max_temp": 29.23}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.89, "max_temp": 28.93}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.05, "max_temp": 29.21}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.92, "max_temp": 29.19}, {"main_weather": "Rain", "description": "light rain", "min_temp": 27.92, "max_temp": 29.72}, {"main_weather": "Rain", "description": "light rain", "min_temp": 27.81, "max_temp": 29.87}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 27.61, "max_temp": 29.53}]
|
||||
[{"main_weather": "Rain", "description": "moderate rain", "min_temp": 13.39, "max_temp": 20.92}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 12.54, "max_temp": 17.84}, {"main_weather": "Rain", "description": "light rain", "min_temp": 13.1, "max_temp": 19.58}, {"main_weather": "Rain", "description": "light rain", "min_temp": 12.6, "max_temp": 22.73}, {"main_weather": "Rain", "description": "light rain", "min_temp": 14.49, "max_temp": 20.58}, {"main_weather": "Rain", "description": "light rain", "min_temp": 14.43, "max_temp": 20.19}, {"main_weather": "Rain", "description": "light rain", "min_temp": 14.57, "max_temp": 23.96}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 15.38, "max_temp": 22.74}]
|
@ -1 +0,0 @@
|
||||
{"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"}
|
40
csv/news.csv
40
csv/news.csv
@ -1,21 +1,21 @@
|
||||
headline,source,date,time
|
||||
Troops eliminate 12 terrorists in Borno | The Guardian Nigeria News - Nigeria and World News — Nigeria - Guardian,Guardian Nigeria,2021-06-28,18:29:00Z
|
||||
Interim government of Tigray flees as rebels advance on Mekelle - The Guardian,The Guardian,2021-06-28,18:27:00Z
|
||||
Winner of BrewDog’s ‘solid gold’ beer can finds prize is made largely of brass - The Guardian,The Guardian,2021-06-28,18:23:00Z
|
||||
LIVE updates as busy Tipperary motorway after man^ 80s^ dies in fatal crash - Irish Mirror,Irish Mirror,2021-06-28,18:22:30Z
|
||||
McKenna says leaving politics a ‘difficult decision’ but climate change remains focus - Global News,Global News,2021-06-28,18:19:46Z
|
||||
Iyabo Ojo^ Nkechi Blessing^ Jide Kosoko & 'Tapan' controversy for Yoruba movie industry - BBC News,BBC News,2021-06-28,18:11:54Z
|
||||
Missing Florida woman was on phone with husband^ as building came crumbling down - NBC News,NBC News,2021-06-28,18:11:05Z
|
||||
Motorway mayhem: Truck crash blocks highway into Auckland - New Zealand Herald,New Zealand Herald,2021-06-28,18:00:21Z
|
||||
Juul agrees to pay North Carolina $40 million to settle vaping accusations - The Washington Post,The Washington Post,2021-06-28,18:00:00Z
|
||||
Ethiopian Forces Retreat in Tigray^ and Rebels Enter the Capital - The New York Times,New York Times,2021-06-28,17:55:52Z
|
||||
Boris Johnson suggests he sacked Matt Hancock – despite refusing to dismiss him when scandal broke - The Independent,Independent,2021-06-28,17:45:43Z
|
||||
What's allowed under MECQ^ GCQ^ GCQ with heightened restrictions^ GCQ with some restrictions - GMA News Online,GMA News,2021-06-28,17:45:28Z
|
||||
No COVID-19 deaths in Manitoba on Monday^ 61 new cases - CTV News,Ctvnews.ca,2021-06-28,17:43:08Z
|
||||
Melanoma survivor fronts Consumer NZ campaign for more sunscreen testing - Stuff.co.nz,Stuff.co.nz,2021-06-28,17:35:00Z
|
||||
BCCI confirms 2021 T20 World Cup switch to UAE - ESPNcricinfo,ESPN Cric Info,2021-06-28,17:34:21Z
|
||||
Lawyers for SA's missing Bitcoin brothers 'terminated' - News24,News24,2021-06-28,17:33:19Z
|
||||
Mumbai's New 2^170-Bed Jumbo Covid Facility Built In Just 35 Days - NDTV,NDTV News,2021-06-28,17:30:56Z
|
||||
COVID lockdown Australia: mRNA vaccines may provide 'years long' immunity - The Australian Financial Review,Australian Financial Review,2021-06-28,17:28:00Z
|
||||
Love Island: With criticism over diversity^ LGBT+ representation and body image^ has the show lost its chemistry? - Sky News,Sky.com,2021-06-28,17:27:35Z
|
||||
Samsung One UI Watch first look raises expectations for Galaxy Watch 4 - SamMobile,SamMobile,2021-06-28,17:21:00Z
|
||||
'Gravitational slingshot' in star clusters may explain stellar streams - Siliconrepublic.com,Siliconrepublic.com,2021-07-05,16:27:31Z
|
||||
Number of children living in motels reaches record high despite Govt's pledge to combat child poverty - New Zealand Herald,New Zealand Herald,2021-07-05,16:25:58Z
|
||||
Baba Ijesha: Yomi Fabiyi under fire over new movie ‘Oko Iyabo’ - Punch Newspapers,The Punch,2021-07-05,16:24:26Z
|
||||
Rescue mission in 'hot pursuit' after gunmen kidnap scores of students in northwest Nigeria - CNN ,CNN,2021-07-05,16:17:00Z
|
||||
COVID-19: Almost all coronavirus rules - including face masks and home-working - to be ditched on 19 July^ PM says - Sky News,Sky.com,2021-07-05,16:07:30Z
|
||||
Gov't fully awards T-bills even as yields rise on inflation bets - BusinessWorld Online,BusinessWorld Online,2021-07-05,16:03:17Z
|
||||
Newark Airport evacuation: 'Security concern' sparks panic in New Jersey - 'Ran so fast' - Daily Express,Express,2021-07-05,16:02:20Z
|
||||
Province Confident Vaccinations Will Blunt Delta Variant - Discoverestevan.com - DiscoverEstevan.com,DiscoverEstevan.com,2021-07-05,16:00:29Z
|
||||
Nnamdi Kanu: We have evidence of Nigeria^ Kenya’s dirty deal to arrest our leader – IPOB - Daily Post Nigeria,Daily Post Nigeria,2021-07-05,16:00:10Z
|
||||
Stocks hold above 7^000 ahead of inflation data - Philstar.com,Philippine Star,2021-07-05,16:00:00Z
|
||||
Explorers Club Kicks Off 2021 Global Exploration Summit - PRNewswire,PRNewswire,2021-07-05,16:00:00Z
|
||||
Vaping could increase your risk of Covid-19 infection^ new study finds By IANS 0s ago - IOL,IOL,2021-07-05,15:59:56Z
|
||||
Astronomers discover an oversized black hole population in the star cluster Palomar 5 - Science Daily,Science Daily,2021-07-05,15:58:17Z
|
||||
Blake Shelton^ Gwen Stefani marry in intimate ceremony at church on singer’s sprawling estate: reports - Fox News,Fox News,2021-07-05,15:55:03Z
|
||||
Batanes^ Babuyan Islands still under Signal No. 1 as TD Emong moves away - INQUIRER.net,Inquirer.net,2021-07-05,15:54:00Z
|
||||
Microbes that feast on crushed rocks thrive in Antarctica's ice-covered lakes - Livescience.com,Live Science,2021-07-05,15:52:50Z
|
||||
New study attempts to characterize long-COVID in all its complexity - News-Medical.Net,News-Medical.Net,2021-07-05,15:47:00Z
|
||||
Megszakad a szív^ négy koporsó egy ravatalon: Utolsó útjára kísérték a tarpai orvost^ feleségét és két gyermekét – Megrázó fotók - Bors,Borsonline.hu,2021-07-05,15:45:00Z
|
||||
Scientists stunned to find vast collection of more than 100 black holes inside our own galaxy - The Independent,Independent,2021-07-05,15:42:01Z
|
||||
Samsung to bring the Thom Browne Edition of the Galaxy Z Flip3^ claims report - Times of India,The Times of India,2021-07-05,15:42:00Z
|
||||
|
|
@ -1 +1 @@
|
||||
[]
|
||||
[{"date": "2021-07-06", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": null, "away_team": "Tampa Bay Lightning", "away_score": null}]
|
@ -1 +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"}]
|
||||
[{"date": "2021-07-03", "time": "00:00:00", "round": "0", "home_team": "Montreal Canadiens", "home_score": "3", "away_team": "Tampa Bay Lightning", "away_score": "6"}, {"date": "2021-07-01", "time": "00:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "3", "away_team": "Montreal Canadiens", "away_score": "1"}, {"date": "2021-06-29", "time": "00:00:00", "round": "0", "home_team": "Tampa Bay Lightning", "home_score": "5", "away_team": "Montreal Canadiens", "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"}]
|
@ -1 +1 @@
|
||||
[]
|
||||
[{"date": "2021-08-13", "time": "19:00:00", "round": "1", "home_team": "Brentford", "home_score": null, "away_team": "Arsenal", "away_score": null}, {"date": "2021-08-14", "time": "14:00:00", "round": "1", "home_team": "Burnley", "home_score": null, "away_team": "Brighton", "away_score": null}, {"date": "2021-08-14", "time": "14:00:00", "round": "1", "home_team": "Chelsea", "home_score": null, "away_team": "Crystal Palace", "away_score": null}, {"date": "2021-08-14", "time": "14:00:00", "round": "1", "home_team": "Everton", "home_score": null, "away_team": "Southampton", "away_score": null}, {"date": "2021-08-14", "time": "14:00:00", "round": "1", "home_team": "Leicester", "home_score": null, "away_team": "Wolves", "away_score": null}, {"date": "2021-08-14", "time": "11:30:00", "round": "1", "home_team": "Man United", "home_score": null, "away_team": "Leeds", "away_score": null}, {"date": "2021-08-14", "time": "16:30:00", "round": "1", "home_team": "Norwich", "home_score": null, "away_team": "Liverpool", "away_score": null}, {"date": "2021-08-14", "time": "14:00:00", "round": "1", "home_team": "Watford", "home_score": null, "away_team": "Aston Villa", "away_score": null}, {"date": "2021-08-15", "time": "13:00:00", "round": "1", "home_team": "Newcastle", "home_score": null, "away_team": "West Ham", "away_score": null}, {"date": "2021-08-15", "time": "15:30:00", "round": "1", "home_team": "Tottenham", "home_score": null, "away_team": "Man City", "away_score": null}, {"date": "2021-08-21", "time": "14:00:00", "round": "2", "home_team": "Aston Villa", "home_score": null, "away_team": "Newcastle", "away_score": null}, {"date": "2021-08-21", "time": "16:30:00", "round": "2", "home_team": "Brighton", "home_score": null, "away_team": "Watford", "away_score": null}, {"date": "2021-08-21", "time": "14:00:00", "round": "2", "home_team": "Crystal Palace", "home_score": null, "away_team": "Brentford", "away_score": null}, {"date": "2021-08-21", "time": "14:00:00", "round": "2", "home_team": "Leeds", "home_score": null, "away_team": "Everton", "away_score": null}, {"date": "2021-08-21", "time": "11:30:00", "round": "2", "home_team": "Liverpool", "home_score": null, "away_team": "Burnley", "away_score": null}]
|
1
csv/sports/premier_league/live_games.json
Normal file
1
csv/sports/premier_league/live_games.json
Normal file
@ -0,0 +1 @@
|
||||
[]
|
@ -1,4 +1,4 @@
|
||||
name,current,opening
|
||||
MSFT,270.51,270.69
|
||||
NFLX,529.11,534.0551
|
||||
GOOG,2509.69,2513.0713
|
||||
MSFT,277.65,272.82
|
||||
NFLX,533.98,535.5
|
||||
GOOG,2574.38,2536.79
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
display_images/user_gif.ppm
Executable file
BIN
display_images/user_gif.ppm
Executable file
Binary file not shown.
After Width: | Height: | Size: 821 B |
Binary file not shown.
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
10
server.py
10
server.py
@ -202,8 +202,10 @@ def DisplayImage():
|
||||
print('No file selected')
|
||||
return hello()
|
||||
if fle and allowed_file(fle.filename):
|
||||
filename = 'display_image.ppm'
|
||||
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), filename))
|
||||
filename = 'user_image.ppm'
|
||||
print('asfdsdaf')
|
||||
print(fle)
|
||||
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)),os.path.join('display_images', filename)))
|
||||
global LastCommand
|
||||
LastCommand = 'Add a new logo file'
|
||||
ticker.sendline('K')
|
||||
@ -224,8 +226,8 @@ def DisplayGIF():
|
||||
return hello()
|
||||
if fle:
|
||||
print('in')
|
||||
filename = 'display_gif.ppm'
|
||||
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), filename))
|
||||
filename = 'user_gif.ppm'
|
||||
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)),os.path.join('display_images', filename)))
|
||||
global LastCommand
|
||||
LastCommand = 'Add a new logo file'
|
||||
ticker.sendline('K')
|
||||
|
167
stockTicker.py
167
stockTicker.py
@ -124,7 +124,7 @@ class StockTicker():
|
||||
kill = self.checkKilled()
|
||||
|
||||
time.sleep(self.delay)
|
||||
return False
|
||||
return kill
|
||||
|
||||
def scrollImageStacked(self, image, offset_x = 0, offset_y = 0):
|
||||
img_width, img_height = image.size
|
||||
@ -505,16 +505,21 @@ class StockTicker():
|
||||
|
||||
#Using change between min and day price give appropriate arrow
|
||||
#and set the overall change colour
|
||||
def getArrow(self, CHANGE):
|
||||
def getArrow(self, CHANGE, professional = False):
|
||||
self.greenORred
|
||||
logos_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos')
|
||||
if(CHANGE>0):
|
||||
Arrow = Image.open(os.path.join(logos_path, 'up.png'))
|
||||
self.greenORred = (0, 255, 0)
|
||||
return Arrow, CHANGE
|
||||
Arrow = Image.open(os.path.join(logos_path, 'down.png'))
|
||||
self.greenORred = (255, 0, 0)
|
||||
CHANGE = (CHANGE * -1)
|
||||
|
||||
else:
|
||||
Arrow = Image.open(os.path.join(logos_path, 'down.png'))
|
||||
self.greenORred = (255, 0, 0)
|
||||
CHANGE = (CHANGE * -1)
|
||||
|
||||
if professional:
|
||||
w, h = Arrow.size
|
||||
Arrow = Arrow.resize((int(w/2), int(h/2)))
|
||||
return Arrow, CHANGE
|
||||
|
||||
def get_text_dimensions(self, text_string, font):
|
||||
@ -534,8 +539,8 @@ class StockTicker():
|
||||
return width,height
|
||||
|
||||
#Draw Ticker, current and change onto one image
|
||||
def textToImage(self, TICKER, CURRENT, CHANGE, ARROW):
|
||||
font = ImageFont.load("./fonts/10x20.pil")
|
||||
def textToImage(self, TICKER, CURRENT, CHANGE, ARROW, font = ImageFont.load("./fonts/10x20.pil")):
|
||||
|
||||
text_width_current, text_height = self.get_text_dimensions(CURRENT, font)
|
||||
|
||||
img = Image.new('RGB', (text_width_current +100 , 32))
|
||||
@ -555,6 +560,28 @@ class StockTicker():
|
||||
|
||||
img = img.crop((0,0,newWidth,32))
|
||||
return img
|
||||
|
||||
def textToImageProf(self, TICKER, CURRENT, CHANGE, ARROW, font):
|
||||
|
||||
text_width_current, text_height = self.get_text_dimensions(CURRENT, font)
|
||||
|
||||
img = Image.new('RGB', (text_width_current +100 , 32))
|
||||
d = ImageDraw.Draw(img)
|
||||
|
||||
d.text((4, 0), TICKER, fill=(255, 255, 255), font=font)
|
||||
d.text((4, 8), CURRENT, fill=self.greenORred, font=font)
|
||||
|
||||
|
||||
|
||||
img.paste(ARROW, ((text_width_current + 7),10))
|
||||
d.text(((text_width_current+18), 8), CHANGE, fill=self.greenORred, font=font)
|
||||
|
||||
text_width_change, text_height = self.get_text_dimensions(CHANGE, font)
|
||||
|
||||
newWidth = text_width_current + text_width_change +30
|
||||
|
||||
img = img.crop((0,0,newWidth,32))
|
||||
return img
|
||||
|
||||
#Stitch the logo & prices picture into one image
|
||||
def stitchImage(self, image_list):
|
||||
@ -628,6 +655,59 @@ class StockTicker():
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
|
||||
return finalDisplayImage
|
||||
|
||||
def getCryptoProfessional(self):
|
||||
|
||||
image_list = []
|
||||
|
||||
|
||||
start = time.time()
|
||||
self.readCryptoCSV()
|
||||
self.blank = Image.new('RGB', (5, 16))
|
||||
for i, coin in enumerate(self.coins):
|
||||
|
||||
info = self.coin_info[coin]
|
||||
|
||||
change = float(info[3]) #TEXT
|
||||
ticker = info[0] #TEXT
|
||||
current = float(info[2]) #TEXT
|
||||
base = info[1].upper()
|
||||
|
||||
if self.points:
|
||||
# convert percent to points
|
||||
change = change/100 * current
|
||||
|
||||
current = '%.2f' % current
|
||||
|
||||
|
||||
arrow, change = self.getArrow(change, professional=True)
|
||||
change = '%.2f' % change
|
||||
midFrame = self.textToImageProf(ticker + '(' + base + ')', current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
|
||||
|
||||
|
||||
try:
|
||||
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'crypto')
|
||||
|
||||
logo = Image.open(os.path.join(logos_path, ticker + '.png'))
|
||||
|
||||
w,h = logo.size
|
||||
logo=logo.resize((int(w/2), int(h/2)))
|
||||
stitchedStock = self.stitchImage([logo,midFrame])
|
||||
except:
|
||||
|
||||
stitchedStock = midFrame
|
||||
|
||||
|
||||
image_list.append(stitchedStock)
|
||||
|
||||
image_list.append(self.blank)
|
||||
|
||||
|
||||
|
||||
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
self.blank = Image.new('RGB', (10, 32))
|
||||
return finalDisplayImage
|
||||
|
||||
def getForexImage(self):
|
||||
title_img = self.openImage('feature_titles/forex.png')
|
||||
@ -733,7 +813,53 @@ class StockTicker():
|
||||
|
||||
return finalDisplayImage
|
||||
|
||||
|
||||
def getStockProfessional(self):
|
||||
image_list = []
|
||||
|
||||
self.readStocksCSV()
|
||||
|
||||
self.blank = Image.new('RGB', (5, 16))
|
||||
for i, symbol in enumerate(self.symbols):
|
||||
|
||||
|
||||
info = self.stock_info[symbol]
|
||||
|
||||
change = float(info[0])-float(info[1]) #TEXT
|
||||
ticker = symbol #TEXT
|
||||
current = '%.2f' % float(info[0]) #TEXT
|
||||
|
||||
arrow, change = self.getArrow(change, professional=True)
|
||||
change = '%.2f' % change
|
||||
midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
|
||||
|
||||
|
||||
try:
|
||||
logos_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos')
|
||||
|
||||
logo = Image.open(os.path.join(logos_path, ticker + '.png'))
|
||||
|
||||
# half the size of the logo
|
||||
width, height = logo.size
|
||||
|
||||
logo = logo.resize((int(width/2), int(height/2)))
|
||||
stitchedStock = self.stitchImage([logo,midFrame])
|
||||
except Exception as e:
|
||||
|
||||
stitchedStock = midFrame
|
||||
|
||||
image_list.append(stitchedStock)
|
||||
|
||||
|
||||
image_list.append(self.blank)
|
||||
|
||||
|
||||
finalDisplayImage = self.stitchImage(image_list)
|
||||
|
||||
|
||||
self.blank = Image.new('RGB', (10, 32))
|
||||
return finalDisplayImage
|
||||
|
||||
|
||||
def getNewsImage(self):
|
||||
|
||||
title_img = self.openImage('feature_titles/news.png')
|
||||
@ -806,7 +932,7 @@ class StockTicker():
|
||||
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")
|
||||
@ -866,7 +992,7 @@ class StockTicker():
|
||||
|
||||
hc_timage = self.textImage(sports_info[home_team]['code'], med_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
|
||||
ac_timage = self.textImage(sports_info[away_team]['code'], med_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
|
||||
vs_timage = self.textImage('vs', med_font, r = 255, g = 255, b = 255)
|
||||
vs_timage = self.textImage('vs', med_font, r = 255, g = 255, b = 255, h_buff = 5)
|
||||
|
||||
img.paste(hc_timage, (x_offset, 9))
|
||||
img.paste(vs_timage, (x_offset + hc_timage.size[0], 9))
|
||||
@ -1541,7 +1667,8 @@ class StockTicker():
|
||||
def process_msg(self, msg):
|
||||
|
||||
if msg == 'S': # stocks
|
||||
img = self.getStockImage()
|
||||
#img = self.getStockImage()
|
||||
img = self.getStockProfessional()
|
||||
|
||||
|
||||
img.save('display_images/stocks.ppm')
|
||||
@ -1579,7 +1706,7 @@ class StockTicker():
|
||||
|
||||
elif msg == 'I': # image
|
||||
|
||||
image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_image'))
|
||||
image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/user_image.ppm'))
|
||||
|
||||
#self.setImage( image)
|
||||
while True:
|
||||
@ -1589,7 +1716,7 @@ class StockTicker():
|
||||
break
|
||||
|
||||
elif msg == 'G': # gif
|
||||
gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_gif.ppm'))
|
||||
gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/user_gif.ppm'))
|
||||
#self.displayGIF(gif)
|
||||
while True:
|
||||
kill = self.scrollGIF(gif, offset_x = 128)
|
||||
@ -1640,7 +1767,7 @@ class StockTicker():
|
||||
'league_games': self.getLeagueImage, 'news':self.getNewsImage, 'text': self.getUserText, 'display_image': self.getUserImage, 'display_gif':self.getUserGIF} #put this somewhere else
|
||||
|
||||
userSettings = ['display_gif', 'text', 'display_image', '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 = ['crypto', 'stocks'] # these wil be read from csv, just for demo
|
||||
#userSettings = [ 'display_image', 'news'] # these wil be read from csv, just for demo
|
||||
|
||||
self.scrollFunctionsAnimated(userSettings, animation = 'down')
|
||||
@ -1654,6 +1781,16 @@ if __name__ == '__main__':
|
||||
try:
|
||||
stock_ticker = StockTicker()
|
||||
|
||||
img = stock_ticker.getStockProfessional()
|
||||
img.paste(stock_ticker.getCryptoProfessional(), (0, 16))
|
||||
|
||||
|
||||
while True:
|
||||
kill = stock_ticker.scrollImage(img, offset_x = 128)
|
||||
|
||||
if kill:
|
||||
break
|
||||
|
||||
#stock_ticker.process_msg(P')
|
||||
#stock_ticker.process_msg('G')
|
||||
#stock_ticker.process_msg('f')
|
||||
|
BIN
user_image.ppm
Normal file
BIN
user_image.ppm
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in New Issue
Block a user