persistant settings added
This commit is contained in:
parent
ea1e2bd7fb
commit
fa91bc4a9b
Binary file not shown.
45
api_caller.py
Normal file
45
api_caller.py
Normal file
@ -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)
|
1
csv/settings.csv
Normal file
1
csv/settings.csv
Normal file
@ -0,0 +1 @@
|
||||
f,9
|
|
@ -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
|
||||
|
|
31
server.py
31
server.py
@ -53,6 +53,8 @@ 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()
|
||||
|
@ -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:
|
||||
@ -327,15 +320,49 @@ 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)
|
||||
|
||||
|
||||
|
||||
|
@ -7,22 +7,16 @@
|
||||
<body>
|
||||
<center>
|
||||
<h2>Stock Ticker Control Panel</h2>
|
||||
<h3>Time of last page reload <br> {{ time }}</h3>
|
||||
<hr width=70% size=3 noshade>
|
||||
<p>Last command sent: {{ lastcommand }}</p>
|
||||
<br>
|
||||
|
||||
<h3>Runtime: {{ runtime }}s & API call: {{ delay }}s before refresh <br> displayed at a speed of {{ speedtime }}m/s</h3>
|
||||
<p>Set the amount of time each image is displayed before a refresh in seconds</p>
|
||||
<form action="/Runtime" method="POST">
|
||||
<input name="text" placeholder="300"style="height:24px">
|
||||
<input type="submit" value="Runtime"style="height:30px">
|
||||
</form>
|
||||
<p>Set the amount of time before next image refresh that the stocks are updated</p>
|
||||
<form action="/Delay" method="POST">
|
||||
<input name="text" placeholder="20"style="height:24px">
|
||||
<input type="submit" value="Delay"style="height:30px">
|
||||
<br><br>
|
||||
<form action="/matrix" method="POST">
|
||||
<input type="submit" name="Run Display" value="Run Display" style="height:50px" >
|
||||
<input type="submit" name="Stop Display (at next refresh)" value="Stop Display"style="height:50px">
|
||||
<input type="submit" name="Shutdown the pi" value="Shutdown the pi"style="height:50px">
|
||||
</form>
|
||||
<br><br>
|
||||
<br><br>
|
||||
|
||||
<p>Set the speed the image scrolls across the screen (s, m of f for slow, medium or fast)</p>
|
||||
<form action="/Speed" method="POST">
|
||||
<input name="text" placeholder="m"style="height:24px">
|
||||
@ -57,18 +51,6 @@
|
||||
<input type=submit value=Upload style="height:30px">
|
||||
</form>
|
||||
|
||||
|
||||
<br><br>
|
||||
<form action="/matrix" method="POST">
|
||||
<input type="submit" name="Run Display" value="Run Display" style="height:50px" >
|
||||
<input type="submit" name="Stop Display (at next refresh)" value="Stop Display (at next refresh)"style="height:50px">
|
||||
<input type="submit" name="Shutdown the pi" value="Shutdown the pi"style="height:50px">
|
||||
</form>
|
||||
<br><br>
|
||||
<br><br>
|
||||
|
||||
<p>Logos currently in file:</p>
|
||||
<p>{{ logofiles }}</p>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user