market opening time check added
This commit is contained in:
parent
fa91bc4a9b
commit
aaeb9e4de2
Binary file not shown.
@ -1,12 +1,26 @@
|
||||
import finnhub
|
||||
import time
|
||||
import csv
|
||||
import pytz
|
||||
from datetime import datetime
|
||||
|
||||
APIkey = "c24qddqad3ickpckgg80"
|
||||
sandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g"
|
||||
finnhubClient = finnhub.Client(api_key=APIkey)
|
||||
|
||||
NY_zone = pytz.timezone('America/New_York')
|
||||
NY_time = datetime.now(NY_zone)
|
||||
|
||||
opening = NY_time.replace(hour=9, minute=30, second=0, microsecond=0)
|
||||
closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def getStockPrices():
|
||||
|
||||
if opening < NY_time < closing:
|
||||
apiCalledError = False
|
||||
stock_info = []
|
||||
|
||||
@ -35,7 +49,7 @@ def getStockPrices():
|
||||
print("Could not fetch data - API CALLS REACHED? - Will display old image")
|
||||
print(e)
|
||||
apiCalledError = True
|
||||
return stock_info, apiCalledError
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,20 +1,20 @@
|
||||
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
|
||||
MSFT,246.695,249.06
|
||||
NFLX,499.625,504.99
|
||||
GOOG,2362.47,2368.42
|
||||
TSLA,670.29,681.06
|
||||
AAPL,128.6,129.2
|
||||
INTC,56.775,56.96
|
||||
TXN,181.845,181.01
|
||||
HPQ,34.565,34.24
|
||||
HOG,49.65,48.33
|
||||
LUV,61.36,60.77
|
||||
WMT,140.85,140.71
|
||||
BJ,45.465,45.17
|
||||
ETSY,182.205,190.99
|
||||
G,47.15,47.25
|
||||
GDDY,82.125,83.24
|
||||
GNRC,319.07,318.9
|
||||
PEP,144.35,143.715
|
||||
STMYELP,0,0
|
||||
XRAY,67.68,68.92
|
||||
ZTS,172.4995,174.2
|
||||
XRAY,67.73,68.92
|
||||
ZTS,173,174.2
|
||||
|
|
@ -153,15 +153,6 @@ class StockTicker():
|
||||
current_img = 1
|
||||
offset_x = 0
|
||||
|
||||
#Get the logo from file that is the same as ticker name
|
||||
def getLogo(self, Ticker):
|
||||
logos_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos')
|
||||
try:
|
||||
Logo = Image.open(os.path.join(logos_path, Ticker + '.png'))
|
||||
except:
|
||||
print('Could not find logo for: ' + Ticker + ' using default')
|
||||
Logo = Image.open(os.path.join(logos_path, 'default.png'))
|
||||
return Logo
|
||||
|
||||
#Using change between min and day price give appropriate arrow
|
||||
#and set the overall change colour
|
||||
@ -250,12 +241,24 @@ class StockTicker():
|
||||
ticker = symbol #TEXT
|
||||
current = '%.2f' % float(info[0]) #TEXT
|
||||
|
||||
logo = self.getLogo(symbol)
|
||||
|
||||
|
||||
arrow, change = self.getArrow(change)
|
||||
change = '%.2f' % change
|
||||
midFrame = self.textToImage(ticker, current, change, arrow) #IMAGE THE TEXT
|
||||
|
||||
|
||||
try:
|
||||
logos_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos')
|
||||
print(os.path.join(logos_path, ticker + '.png'))
|
||||
logo = Image.open(os.path.join(logos_path, ticker + '.png'))
|
||||
stitchedStock = self.stitchImage([logo,midFrame])
|
||||
except:
|
||||
print('no logo for ' + ticker)
|
||||
stitchedStock = midFrame
|
||||
|
||||
|
||||
|
||||
image_list.append(self.blank)
|
||||
image_list.append(stitchedStock)
|
||||
|
||||
@ -361,13 +364,13 @@ if __name__ == '__main__':
|
||||
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)
|
||||
#stock_ticker.getFullStockImage()
|
||||
#stock_ticker.displayMatrix()
|
||||
stock_ticker.getFullStockImage()
|
||||
stock_ticker.displayMatrix()
|
||||
|
||||
|
||||
while True:
|
||||
|
Loading…
Reference in New Issue
Block a user