diff --git a/__pycache__/stockTicker.cpython-37.pyc b/__pycache__/stockTicker.cpython-37.pyc index 982ce17..e2520d1 100644 Binary files a/__pycache__/stockTicker.cpython-37.pyc and b/__pycache__/stockTicker.cpython-37.pyc differ diff --git a/api_caller.py b/api_caller.py new file mode 100644 index 0000000..07f8d8b --- /dev/null +++ b/api_caller.py @@ -0,0 +1,45 @@ +import finnhub +import time +import csv + +APIkey = "c24qddqad3ickpckgg80" +sandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" +finnhubClient = finnhub.Client(api_key=APIkey) + +def getStockPrices(): + apiCalledError = False + stock_info = [] + + symbols = [] + f = open('csv/tickers.csv', 'r') + CSV = csv.reader(f) + + for row in CSV: + symbol = row[0] + symbols.append(symbol) + f.close() + try: + quotes = [finnhubClient.quote(symbol) for symbol in symbols] + current_prices = [quote['c'] for quote in quotes] + opening_prices = [quote['o'] for quote in quotes] + + CSV = open('csv/tickers.csv', 'w+') + for i, symbol in enumerate(symbols): + symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n' + CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n') + CSV.close() + print('API called successfully') + + + except Exception as e: + print("Could not fetch data - API CALLS REACHED? - Will display old image") + print(e) + apiCalledError = True + return stock_info, apiCalledError + + +if __name__ == '__main__': + sleeptime = 2 #minutes + while True: + getStockPrices() + time.sleep(sleeptime*60) diff --git a/csv/settings.csv b/csv/settings.csv new file mode 100644 index 0000000..170284b --- /dev/null +++ b/csv/settings.csv @@ -0,0 +1 @@ +f,9 \ No newline at end of file diff --git a/csv/tickers.csv b/csv/tickers.csv index 5cb9893..72c26a9 100644 --- a/csv/tickers.csv +++ b/csv/tickers.csv @@ -1,20 +1,20 @@ -MSFT,248.515,249.06 -NFLX,503.82,504.99 -GOOG,2370,2368.42 -TSLA,679.15,681.06 -AAPL,129.681,129.2 -INTC,56.995,56.96 -TXN,182.05,181.01 -HPQ,34.155,34.24 -HOG,48.61,48.33 -LUV,61.255,60.77 -WMT,140.61,140.71 -BJ,44.9502,45.17 -ETSY,187.4508,190.99 -G,46.86,47.25 -GDDY,82.7339,83.24 -GNRC,316.745,318.9 -PEP,143.83,143.715 +MSFT,248.15,249.06 +NFLX,502.34,504.99 +GOOG,2366.54,2368.42 +TSLA,676.818,681.06 +AAPL,129.675,129.2 +INTC,56.94,56.96 +TXN,182.07,181.01 +HPQ,34.315,34.24 +HOG,49.62,48.33 +LUV,61.46,60.77 +WMT,140.6,140.71 +BJ,45.18,45.17 +ETSY,187.8,190.99 +G,47.02,47.25 +GDDY,82.985,83.24 +GNRC,320.425,318.9 +PEP,143.65,143.715 STMYELP,0,0 -XRAY,67.405,68.92 -ZTS,173.086,174.2 +XRAY,67.68,68.92 +ZTS,172.4995,174.2 diff --git a/final.ppm b/final.ppm index a5bc108..df47240 100755 Binary files a/final.ppm and b/final.ppm differ diff --git a/server.py b/server.py index 876dbde..fbdf429 100644 --- a/server.py +++ b/server.py @@ -46,13 +46,15 @@ def process_file(path, filename): for row in new_csv: default_csv.writerow(row) - + app = Flask(__name__) @app.route("/", methods=['GET', 'POST']) def hello(): global command + + now = datetime.datetime.now() timeString = now.strftime("%Y-%m-%d %H:%M") LogoList = os.listdir('logos') @@ -88,10 +90,20 @@ def Delay(): @app.route("/Speed", methods=['POST']) def Speed(): - global speedTime - speedTime = request.form['text'] - print(speedTime) - ticker.sendline(speedTime) + global speed + speed = request.form['text'] + print(speed) + ticker.sendline(speed) + + f = open('csv/settings.csv', 'r') + CSV = csv.reader(f) + for line in CSV: + _, brightness = line + f.close() + + f = open('csv/settings.csv', 'w+') + f.write(str(speed) + ',' + brightness) + f.close() global LastCommand LastCommand = 'Change Speed' return hello() @@ -102,6 +114,17 @@ def Brightness(): brightness = int(request.form['text'])-1 print(brightness) ticker.sendline(str(brightness)) + + f = open('csv/settings.csv', 'r') + CSV = csv.reader(f) + for line in CSV: + speed, _ = line + f.close() + + f = open('csv/settings.csv', 'w+') + f.write(str(speed) + ',' + str(brightness)) + f.close() + global LastCommand LastCommand = 'Change Brightness' return hello() diff --git a/stockTicker.py b/stockTicker.py index 56ed695..7d0485c 100644 --- a/stockTicker.py +++ b/stockTicker.py @@ -136,14 +136,7 @@ class StockTicker(): kill = True break - elif msg == 's': - stock_ticker.delay = 0.03 - elif msg == 'm': - stock_ticker.delay = 0.01 - elif msg == 'f': - stock_ticker.delay = 0.005 - elif msg in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']: - self.brightness = min(1.0, float(msg)/10 + 0.1) + self.process_msg(msg) except KeyboardInterrupt: @@ -326,16 +319,50 @@ class StockTicker(): #Change running to false stopping refresh at next checkpoint def stopStockTicker(self): + self.keySwapper = 0 self.running = False print('MATRIX DISPLAY STOP CALLED') + def process_msg(self, msg): + + if msg == 'S': + self.getFullStockImage() + self.displayMatrix() + + + elif msg == 's': + self.delay = 0.03 + + elif msg == 'm': + self.delay = 0.01 + + elif msg == 'f': + self.delay = 0.005 + + elif msg in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']: + + self.brightness = min(1.0, float(msg)/10 + 0.1) if __name__ == '__main__': #print(sys.stdin.readlines()) stock_ticker = StockTicker() + + f = open('csv/settings.csv') + + CSV = csv.reader(f) + + for row in CSV: + speed, brightness = row + + print(speed, brightness) + stock_ticker.process_msg(brightness) + stock_ticker.process_msg(speed) + + print(stock_ticker.delay, stock_ticker.brightness) + #t = time.time() #api_caller = pexpect.spawn("sudo -E python3 api_caller.py") #print('time to call api', time.time()-t) @@ -345,19 +372,7 @@ if __name__ == '__main__': while True: msg = getInput() - if msg == 'S': - stock_ticker.getFullStockImage() - stock_ticker.displayMatrix() - - - elif msg == 's': - stock_ticker.delay = 0.03 - elif msg == 'm': - stock_ticker.delay = 0.01 - elif msg == 'f': - stock_ticker.delay = 0.005 - elif msg in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']: - stock_ticker.brightness = min(1.0, float(msg)/10 + 0.1) + stock_ticker.process_msg(msg) diff --git a/templates/index.html b/templates/index.html index ae8b6f4..5cd6731 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,23 +7,17 @@
Last command sent: {{ lastcommand }}
-Set the amount of time each image is displayed before a refresh in seconds
- -Set the amount of time before next image refresh that the stocks are updated
- -Set the speed the image scrolls across the screen (s, m of f for slow, medium or fast)
+Set the speed the image scrolls across the screen (s, m of f for slow, medium or fast)
- +To change the tickers displayed please upload a CSV (comma separated value) file with 11 tickers on each row e.g
@@ -44,7 +38,7 @@
-
+
Upload logo images (e.g "TICKER.png") or change the default images here
@@ -57,18 +51,6 @@ - -Logos currently in file:
-{{ logofiles }}