Merge pull request #3 from fin-tic/dev

Dev
This commit is contained in:
Neythen Treloar 2022-02-21 19:45:58 +00:00 committed by GitHub
commit a4f2ee1cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 33 deletions

2
csv/system_info.json Normal file → Executable file
View File

@ -1 +1 @@
{"update_available": false, "first_boot": true} {"update_available": false, "first_boot": false}

View File

@ -65,7 +65,8 @@ def updateStocks(api_key):
url += '&apiKey=' + api_key url += '&apiKey=' + api_key
response = requests.get(url) response = requests.get(url)
data = response.json() data = response.json()
print(response)
print(data)
stock_info = {} stock_info = {}
@ -120,9 +121,13 @@ def updateCrypto(api_key):
print(data) print(data)
coin_info = {}
for i,d in enumerate(data): #TODO get base from the server for i,d in enumerate(data): #TODO get base from the server
coin_info[symbol_base[i]] = {'current': d['price'], '24hr_change': d['percent_over_24hr']}
symbol = d['symbol']
base = d['currency']
coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['percent_over_24hr']}
all_crypto_settings['symbols'] = coin_info all_crypto_settings['symbols'] = coin_info
@ -532,6 +537,7 @@ def updateAll(api_key, weather_key):
updateForex(api_key) updateForex(api_key)
updateNews(api_key) updateNews(api_key)
updateSports(api_key) updateSports(api_key)
if weather_key:
updateWeather(weather_key) updateWeather(weather_key)
@ -544,7 +550,7 @@ if __name__ == '__main__':
update_frequencies = {'stocks':1, 'crypto':5, 'forex':60, 'news':120, 'weather': 120, 'sports': 120} #minutes update_frequencies = {'stocks':1, 'crypto':5, 'forex':60, 'news':120, 'weather': 120, 'sports': 1440} #minutes
NY_zone = pytz.timezone('America/New_York') NY_zone = pytz.timezone('America/New_York')
CET_zone = pytz.timezone('Europe/Berlin') CET_zone = pytz.timezone('Europe/Berlin')
@ -569,7 +575,7 @@ if __name__ == '__main__':
try: try:
weather_key = api_keys[1].strip() weather_key = api_keys[1].strip()
except Exception as e: except Exception as e:
weather_key = False
exc_type, exc_obj, exc_tb = sys.exc_info() exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
logf.write(str(e)) logf.write(str(e))

View File

@ -33,6 +33,7 @@ api_caller.sendline('A')
displaying_screensaver = False displaying_screensaver = False
uploading = False uploading = False
screensaver_p = None screensaver_p = None
ticker_stopped = False
professional = json.load(open('csv/display_settings.json', 'r'))[0] == "Professional" professional = json.load(open('csv/display_settings.json', 'r'))[0] == "Professional"
command = 300 command = 300
@ -174,11 +175,18 @@ def start():
global ticker global ticker
global api_caller global api_caller
global professional global professional
global ticker_stopped
if displaying_screensaver: if displaying_screensaver:
screensaver_p.close() screensaver_p.close()
ticker = pexpect.spawn("sudo -E python3 stockTicker.py") ticker = pexpect.spawn("sudo -E python3 stockTicker.py")
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py") #api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py")
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 database_caller.py")
displaying_screensaver = False displaying_screensaver = False
if ticker_stopped:
ticker = pexpect.spawn("sudo -E python3 stockTicker.py")
ticker_stopped = False
api_caller.sendline('A') api_caller.sendline('A')
ticker.sendline('K') ticker.sendline('K')
@ -193,17 +201,30 @@ def stop():
global ticker global ticker
global api_caller global api_caller
global professional global professional
if not displaying_screensaver: global ticker_stopped
ticker.sendline('K') ticker.sendline('K')
if not displaying_screensaver:
time.sleep(1) # give time for leds to turn off
ticker.close()
else: else:
screensaver_p.close() screensaver_p.close()
if not ticker_stopped:
time.sleep(1) # give time for leds to turn off
ticker.close()
ticker_stopped = True
if displaying_screensaver: if displaying_screensaver:
screensaver_p.close() screensaver_p.close()
ticker = pexpect.spawn("sudo -E python3 stockTicker.py") ticker = pexpect.spawn("sudo -E python3 stockTicker.py")
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py") #api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py")
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 database_caller.py")
displaying_screensaver = False displaying_screensaver = False
return index() return index()
@app.route("/update", methods=['PUT','POST']) @app.route("/update", methods=['PUT','POST'])

File diff suppressed because one or more lines are too long

View File

@ -57,7 +57,7 @@ class StockTicker():
options.chain_length = 2 options.chain_length = 2
options.parallel = 1 options.parallel = 1
options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat' options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat'
options.gpio_slowdown = 1 options.gpio_slowdown = 4
options.brightness = self.brightness options.brightness = self.brightness
self.matrix = RGBMatrix(options = options) self.matrix = RGBMatrix(options = options)
print(dir(self.matrix)) print(dir(self.matrix))
@ -931,9 +931,6 @@ class StockTicker():
current = float(coin_info[cb]["current"]) current = float(coin_info[cb]["current"])
change = float(coin_info[cb]["24hr_change"]) change = float(coin_info[cb]["24hr_change"])
percent_change = '%.2f' % abs(change) +'%' percent_change = '%.2f' % abs(change) +'%'
@ -1074,10 +1071,10 @@ class StockTicker():
current = float(forex_settings[sb]['current']) current = float(forex_settings[sb]['current'])
change = float(forex_settings[sb]['24hr_change']) change = float(forex_settings[sb]['24hr_change'])
percent_change = '%.2f' % abs(change) +'%' percent_change = str(abs(change)) +'%'
point_change = '%.2f' % abs(change/100 * current) point_change = str(abs(change/100 * current))
if not all_forex_settings['percent']: if not all_forex_settings['percent']:
percent_change = False percent_change = False
@ -1167,10 +1164,10 @@ class StockTicker():
# convert percent to points # convert percent to points
change = change/current * 100 change = change/current * 100
change = '%.2f' % change + '%' change = str(change) + '%'
else: else:
change = '%.6f' % change change = str(change)
current = '%.3f' % current current = str(current)
midFrame = self.textToImageProf(symbol + '(' + base + ')', current, change, arrow, font = ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT midFrame = self.textToImageProf(symbol + '(' + base + ')', current, change, arrow, font = ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
if all_forex_settings['logos']: if all_forex_settings['logos']:
@ -1240,13 +1237,13 @@ class StockTicker():
change = float(info['current'])-float(info['opening']) #TEXT change = float(info['current'])-float(info['opening']) #TEXT
ticker = symbol #TEXT ticker = symbol #TEXT
percent_change = '%.2f' % abs(float(change)/float(info['current'])*100) + '%' percent_change = str(abs(float(change)/float(info['current'])*100)) + '%'
point_change = '%.2f' % abs(change) point_change = str(abs(change))
arrow, change = self.getArrow(change) arrow, change = self.getArrow(change)
print(percent_change, point_change) print(percent_change, point_change)
current = '%.2f' % float(info['current']) #TEXT current = str(float(info['current'])) #TEXT
@ -1327,10 +1324,10 @@ class StockTicker():
# convert percent to points # convert percent to points
change = change/float(info['current'])* 100 change = change/float(info['current'])* 100
change = '%.2f' % change + '%' change = str(change) + '%'
else: else:
change = '%.2f' % change change = str(change)
current = '%.2f' % float(info['current']) #TEXT current = str(float(info['current'])) #TEXT
midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
if all_stocks_settings['logos']: if all_stocks_settings['logos']: