From 8753fdd45499d59e81869094a63f5a5f5b144128 Mon Sep 17 00:00:00 2001 From: Neythen Treloar Date: Tue, 22 Feb 2022 20:10:42 +0000 Subject: [PATCH] fixed decimal point issues --- database_caller.py | 9 +++++---- setup_config_files.sh | 6 +++--- stockTicker.py | 44 +++++++++++++++++++++---------------------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/database_caller.py b/database_caller.py index 921e23f..88e6f3f 100755 --- a/database_caller.py +++ b/database_caller.py @@ -71,7 +71,7 @@ def updateStocks(api_key): stock_info = {} for stock in data: - stock_info[stock['symbol']] = {'current': stock['price'], 'opening': float(stock['price']) - float(stock['change_since'])} + stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']} print(stock_info) all_stocks_settings['symbols'] = stock_info @@ -127,7 +127,7 @@ def updateCrypto(api_key): symbol = d['symbol'] base = d['currency'] - coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['percent_over_24hr']} + coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['price_over_24hr'], 'percent_change': d['percent_over_24hr']} all_crypto_settings['symbols'] = coin_info @@ -175,12 +175,12 @@ def updateForex(api_key): - + print(data) c_dict = {} for d in data: - c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr']} + c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr'], 'percent_change':d['percent_over_24hr']} @@ -572,6 +572,7 @@ if __name__ == '__main__': api_keys = f.readlines() api_key = api_keys[0].strip() + try: weather_key = api_keys[1].strip() except Exception as e: diff --git a/setup_config_files.sh b/setup_config_files.sh index 2525787..0239bf6 100755 --- a/setup_config_files.sh +++ b/setup_config_files.sh @@ -22,17 +22,17 @@ echo '{"update_available": false, "first_boot": true}' >> system_info.json echo [\"Standard\", [\"Stocks\", \"Crypto\", \"Forex\"]] >> display_settings.json echo hello world!,255,255,0 >> scroll_text.csv -echo '{"feature": "Stocks", "speed": "medium", "animation": "down", "percent": false, "point": false, "logos": true, "chart": false, "title": true, "symbols": {"ETH,USD": {"current": "2659.40", "24hr_change": "0.03"}, "BTC,USD": {"current": "38111.00", "24hr_change": "-0.54"}, "BNB,USD": {"current": "372.35", "24hr_change": "-2.73"}, "ADA,BTC": {"current": "0.0000", "24hr_change": "-1.55"}}}' >> crypto_settings.json +echo '{"feature": "Stocks", "speed": "medium", "animation": "down", "percent": false, "point": false, "logos": true, "chart": false, "title": true, "symbols": {"ETH,USD": {"current": "2629.32", "24hr_change": "-27.6432", "percent_change": "-1.04"}, "BTC,USD": {"current": "38161.00", "24hr_change": "-50.8386", "percent_change": "-0.13"}, "BNB,USD": {"current": "372.57", "24hr_change": "0.4140", "percent_change": "0.11"}, "ADA,BTC": {"current": "0.0000", "24hr_change": "-0.0000", "percent_change": "-3.74"}}}' >> crypto_settings.json echo -e "speed,brightness\nf,3" >> settings.csv echo '{"feature": "Sports (Team Stats)", "speed": "medium", "animation": "down", "title": true, "leagues": {}}' >> league_tables.json echo {\"feature\": \"Current Weather\", \"speed\": \"medium\", \"animation\": \"down\", \"temp\": \"celsius\", \"wind_speed\": \"miles/sec\", \"colour\": \"white\", \"city_colour\": \"yellow\", \"title\": true, \"locations\": {}, \"current_weather\": true} >> current_weather.json -echo '{"feature": "Stocks", "speed": "medium", "animation": "down", "percent": true, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"AAPL": {"current": "167.48", "opening": 173.07}, "MSFT": {"current": "288.00", "opening": 309.93}, "GOOG": {"current": "2610.82", "opening": 2793.9100000000003}, "NFLX": {"current": "391.32", "opening": 526.71}}}' >> stocks_settings.json +echo '{"feature": "Stocks", "speed": "medium", "animation": "down", "percent": true, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"AAPL": {"current": "164.02", "change": "-1.59", "percent_change": "-0.97"}, "MSFT": {"current": "288.29", "change": "-1.32", "percent_change": "-0.46"}, "GOOG": {"current": "2586.74", "change": "-34.01", "percent_change": "-1.31"}, "NFLX": {"current": "380.52", "change": "-7.59", "percent_change": "-1.99"}}}' >> stocks_settings.json echo {\"feature\": \"Current Weather\", \"speed\": \"medium\", \"animation\": \"down\", \"temp\": \"celsius\", \"wind_speed\": \"miles/sec\", \"colour\": \"white\", \"city_colour\": \"yellow\", \"title\": true, \"locations\": {}, \"current_weather\": true} >> daily_weather.json echo '{"feature": "Sports (Live Games)", "speed": "medium", "animation": "down", "title": true, "leagues": {}}' >> live_games.json echo '{"feature": "Custom Messages", "speed": "Medium", "animation": "down", "title": true, "messages": [{"name": "1", "text": "123", "text_colour": "White", "size": "Medium", "background_colour": "Black"}, {"name": "13", "text": "123", "text_colour": "Red", "size": "Medium", "background_colour": "Purple"}]}' >> message_settings.json echo '{"feature": "Sports (Upcoming Games)", "speed": "medium", "animation": "down", "title": true, "leagues": {"NFL": [{"date": "2021-11-22", "time": "01:20:00", "round": "11", "home_team": "Los Angeles Chargers", "home_score": "41", "away_team": "Pittsburgh Steelers", "away_score": "37"}, {"date": "2021-11-23", "time": "01:15:00", "round": "11", "home_team": "Tampa Bay Buccaneers", "home_score": "0", "away_team": "New York Giants", "away_score": "0"}, {"date": "2021-11-25", "time": "17:30:00", "round": "12", "home_team": "Detroit Lions", "home_score": null, "away_team": "Chicago Bears", "away_score": null}, {"date": "2021-11-25", "time": "21:30:00", "round": "12", "home_team": "Dallas Cowboys", "home_score": null, "away_team": "Las Vegas Raiders", "away_score": null}, {"date": "2021-11-26", "time": "01:20:00", "round": "12", "home_team": "New Orleans Saints", "home_score": null, "away_team": "Buffalo Bills", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Cincinnati Bengals", "home_score": null, "away_team": "Pittsburgh Steelers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Houston Texans", "home_score": null, "away_team": "New York Jets", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Indianapolis Colts", "home_score": null, "away_team": "Tampa Bay Buccaneers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Jacksonville Jaguars", "home_score": null, "away_team": "Atlanta Falcons", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Miami Dolphins", "home_score": null, "away_team": "Carolina Panthers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "New England Patriots", "home_score": null, "away_team": "Tennessee Titans", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "New York Giants", "home_score": null, "away_team": "Philadelphia Eagles", "away_score": null}, {"date": "2021-11-28", "time": "21:05:00", "round": "12", "home_team": "Denver Broncos", "home_score": null, "away_team": "Los Angeles Chargers", "away_score": null}, {"date": "2021-11-28", "time": "21:25:00", "round": "12", "home_team": "Green Bay Packers", "home_score": null, "away_team": "Los Angeles Rams", "away_score": null}, {"date": "2021-11-28", "time": "21:25:00", "round": "12", "home_team": "San Francisco 49ers", "home_score": null, "away_team": "Minnesota Vikings", "away_score": null}], "NBA": [{"date": "2021-11-22", "time": "01:20:00", "round": "11", "home_team": "Los Angeles Chargers", "home_score": "41", "away_team": "Pittsburgh Steelers", "away_score": "37"}, {"date": "2021-11-23", "time": "01:15:00", "round": "11", "home_team": "Tampa Bay Buccaneers", "home_score": "0", "away_team": "New York Giants", "away_score": "0"}, {"date": "2021-11-25", "time": "17:30:00", "round": "12", "home_team": "Detroit Lions", "home_score": null, "away_team": "Chicago Bears", "away_score": null}, {"date": "2021-11-25", "time": "21:30:00", "round": "12", "home_team": "Dallas Cowboys", "home_score": null, "away_team": "Las Vegas Raiders", "away_score": null}, {"date": "2021-11-26", "time": "01:20:00", "round": "12", "home_team": "New Orleans Saints", "home_score": null, "away_team": "Buffalo Bills", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Cincinnati Bengals", "home_score": null, "away_team": "Pittsburgh Steelers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Houston Texans", "home_score": null, "away_team": "New York Jets", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Indianapolis Colts", "home_score": null, "away_team": "Tampa Bay Buccaneers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Jacksonville Jaguars", "home_score": null, "away_team": "Atlanta Falcons", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "Miami Dolphins", "home_score": null, "away_team": "Carolina Panthers", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "New England Patriots", "home_score": null, "away_team": "Tennessee Titans", "away_score": null}, {"date": "2021-11-28", "time": "18:00:00", "round": "12", "home_team": "New York Giants", "home_score": null, "away_team": "Philadelphia Eagles", "away_score": null}, {"date": "2021-11-28", "time": "21:05:00", "round": "12", "home_team": "Denver Broncos", "home_score": null, "away_team": "Los Angeles Chargers", "away_score": null}, {"date": "2021-11-28", "time": "21:25:00", "round": "12", "home_team": "Green Bay Packers", "home_score": null, "away_team": "Los Angeles Rams", "away_score": null}, {"date": "2021-11-28", "time": "21:25:00", "round": "12", "home_team": "San Francisco 49ers", "home_score": null, "away_team": "Minnesota Vikings", "away_score": null}]}}' >> upcoming_games.json -echo '{"feature": "Stocks", "speed": "medium", "animation": "down", "percent": false, "point": false, "logos": true, "chart": false, "title": true, "symbols": {"EUR,USD": {"current": "1.1342", "24hr_change": "0.0000"}, "USD,JPY": {"current": "114.855", "24hr_change": "0.0000"}, "GBP,USD": {"current": "1.3610", "24hr_change": "0.0000"}, "USD,CHF": {"current": "0.9169", "24hr_change": "0.0000"}}}' >> forex_settings.json +echo '{"feature": "Stocks", "speed": "medium", "animation": "down", "percent": false, "point": false, "logos": true, "chart": false, "title": true, "symbols": {"EUR,USD": {"current": "1.1334", "24hr_change": "-0.0003", "percent_change": "0.00"}, "USD,JPY": {"current": "114.960", "24hr_change": "0.1600", "percent_change": "0.14"}, "GBP,USD": {"current": "1.3577", "24hr_change": "-0.0031", "percent_change": "-0.23"}, "USD,CHF": {"current": "0.9198", "24hr_change": "0.0029", "percent_change": "0.32"}}}' >> forex_settings.json echo '{"speed": "medium", "animation": "down", "title": true, "pause": "2", "images": []}'>> GIF_settings.json echo '{"feature": "News", "speed": "medium", "animation": "down", "country": "USA", "category": "general", "title": true, "use_sources": true, "sources": [], "headlines": []}' >> news_settings.json echo '{"speed": "slow", "animation": "down", "title": true, "pause": "/", "images": []}' >> image_settings.json diff --git a/stockTicker.py b/stockTicker.py index c2f8b39..0f0c3f2 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -929,15 +929,17 @@ class StockTicker(): try: ticker, base = cb.split(',') current = float(coin_info[cb]["current"]) - change = float(coin_info[cb]["24hr_change"]) + point_change = float(coin_info[cb]["24hr_change"]) - percent_change = '%.2f' % abs(change) +'%' + percent_change = float(coin_info[cb]["percent_change"]) - - point_change = '%.2f' % abs(change/100 * current) + + + arrow, change = self.getArrow(point_change) + + percent_change = str(abs(percent_change)) + point_change = str(abs(point_change)) - arrow, change = self.getArrow(change) - current = '%.2f' % current if not all_crypto_settings['percent']: percent_change = False if not all_crypto_settings['point']: @@ -1006,13 +1008,12 @@ class StockTicker(): change = float(coin_info[cb]["24hr_change"]) arrow, change = self.getArrow(change, professional=True) - if all_crypto_settings["point"]: + if all_crypto_settings["percent"]: # convert percent to points - change = abs(change)/100 * current - change = str(change) + change = str(abs(float(coin_info[cb]['percent_change']))) + '%' else: - change = str(change) + change = str(abs(float(change))) current = str(current) midFrame = self.textToImageProf(ticker + '(' + base + ')', current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT @@ -1071,10 +1072,10 @@ class StockTicker(): current = float(forex_settings[sb]['current']) change = float(forex_settings[sb]['24hr_change']) - percent_change = str(abs(change)) +'%' + percent_change = str(abs(forex_settings[sb]['percent_change'])) +'%' - point_change = str(abs(change/100 * current)) + point_change = str(abs(change)) if not all_forex_settings['percent']: percent_change = False @@ -1162,7 +1163,7 @@ class StockTicker(): if all_forex_settings["percent"]: # convert percent to points - change = abs(change)/current * 100 + change = abs(forex_settings[sb]['percent_change'])/current * 100 change = str(change) + '%' else: @@ -1234,13 +1235,15 @@ class StockTicker(): try: info = stock_info[symbol] - change = float(info['current'])-float(info['opening']) #TEXT + change = float(info['change']) #TEXT ticker = symbol #TEXT - percent_change = str(abs(float(change)/float(info['current'])*100)) + '%' - point_change = str(abs(change)) + arrow, change = self.getArrow(change) + percent_change = str(abs(float(info['percent_change']))) + '%' + point_change = str(abs(change)) + print(percent_change, point_change) current = str(float(info['current'])) #TEXT @@ -1313,7 +1316,7 @@ class StockTicker(): try: info = stock_info[symbol] - change = float(info['current'])-float(info['opening']) #TEXT + change = float(info['change'])#TEXT ticker = symbol #TEXT @@ -1321,12 +1324,9 @@ class StockTicker(): arrow, change = self.getArrow(change, professional=True) if all_stocks_settings["percent"]: - # convert percent to points - change = change/float(info['current'])* 100 + change = str(abs(float(info['percent_change']))) + '%' + - change = str(change) + '%' - else: - change = str(change) current = str(float(info['current'])) #TEXT midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT