api and transition updates
This commit is contained in:
parent
a23b0f849c
commit
afe4f583bf
@ -100,6 +100,7 @@ def updateUpdate(NY_time):
|
||||
f.close()
|
||||
|
||||
def updateStockPrices():
|
||||
max_stocks = 200
|
||||
finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub
|
||||
finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub
|
||||
finnhubClient = finnhub.Client(api_key=finnhubAPIkey)
|
||||
@ -141,7 +142,10 @@ def updateStockPricesIEX():
|
||||
max_stocks = 200
|
||||
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
||||
try:
|
||||
'''
|
||||
symbols_str = ','.join(symbols)
|
||||
print(symbols)
|
||||
print(symbols_str)
|
||||
method = 'GET'
|
||||
host = 'https://cloud.iexapis.com/stable'
|
||||
lastEndpoint = '/tops/last'
|
||||
@ -153,20 +157,23 @@ def updateStockPricesIEX():
|
||||
print('\nBEGIN REQUEST++++++++++++++++++++++++++++++++++++')
|
||||
print('Request URL = ' + last_request_url)
|
||||
last_response = requests.get(last_request_url)
|
||||
|
||||
print('done')
|
||||
if last_response.status_code == 200:
|
||||
print('last success')
|
||||
|
||||
current_prices = []
|
||||
|
||||
for stock in last_response.json():
|
||||
current_prices.append(stock['price'])
|
||||
|
||||
'''
|
||||
|
||||
|
||||
current_prices = []
|
||||
opening_prices = []
|
||||
for symbol in symbols:
|
||||
symbol = 'MSFT'
|
||||
print(symbol)
|
||||
method = 'GET'
|
||||
host = 'https://cloud.iexapis.com/stable'
|
||||
lastEndpoint = '/tops/last'
|
||||
|
||||
intradayEndpoint = '/stock/'+ symbol+ '/intraday-prices'
|
||||
querystring = '?chartIEXOnly=true&token='+iexAPIkey
|
||||
|
||||
@ -177,23 +184,32 @@ def updateStockPricesIEX():
|
||||
intraday_response = requests.get(intraday_request_url)
|
||||
|
||||
print('\nRESPONSE++++++++++++++++++++++++++++++++++++')
|
||||
print('Response code: %d\n' % intraday_response.status_code)
|
||||
print('Response code: \n',intraday_response)
|
||||
|
||||
|
||||
print(intraday_response.text)
|
||||
|
||||
opn = intraday_response.json()[0]['open']
|
||||
current = intraday_response.json()[-1]['close']
|
||||
|
||||
opening_prices.append(opn)
|
||||
current_prices.append(current)
|
||||
|
||||
'''
|
||||
for time_point in intraday_response.json():
|
||||
print(time_point['date'])
|
||||
print(time_point['open'])
|
||||
|
||||
'''
|
||||
|
||||
|
||||
CSV = open('csv/tickers.csv', 'w+')
|
||||
CSV.write('name,current,opening\n')
|
||||
for i, symbol in enumerate(symbols):
|
||||
|
||||
CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n')
|
||||
CSV.close()
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
@ -202,7 +218,8 @@ def updateStockPricesIEX():
|
||||
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||
logf.write('. type: ' + str(exc_type))
|
||||
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||
print(e)
|
||||
raise e
|
||||
sys.exit()
|
||||
|
||||
|
||||
def updateCrypto():
|
||||
@ -360,10 +377,6 @@ def updateForex():
|
||||
|
||||
c_dict = {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for curr in currencies:
|
||||
|
||||
current = all_data['rates'][str_tod][curr]
|
||||
@ -558,7 +571,16 @@ def checkStocks(last_update, update_frequency):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
updateWeather()
|
||||
logf = open("log.txt", "w")
|
||||
|
||||
t = time.time()
|
||||
|
||||
updateStockPrices()
|
||||
print('finnhub:',time.time() -t)
|
||||
t = time.time()
|
||||
updateStockPricesIEX()
|
||||
print('iex:', time.time() -t)
|
||||
sys.exit()
|
||||
max_stocks = 200
|
||||
max_crypto = 100
|
||||
|
||||
@ -587,7 +609,7 @@ if __name__ == '__main__':
|
||||
|
||||
t = time.time()
|
||||
|
||||
logf = open("log.txt", "w")
|
||||
|
||||
|
||||
try:
|
||||
while True:
|
||||
|
@ -1,4 +1,4 @@
|
||||
name,current,opening
|
||||
MSFT,267.88,266.185
|
||||
NFLX,532.71,528.12
|
||||
GOOG,2532,2540
|
||||
MSFT,271.2101,268.865
|
||||
NFLX,533.325,533.55
|
||||
GOOG,2518.59,2535.45
|
||||
|
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 821 B |
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 9.9 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -202,7 +202,7 @@ def DisplayImage():
|
||||
print('No file selected')
|
||||
return hello()
|
||||
if fle and allowed_file(fle.filename):
|
||||
filename = 'display_image'
|
||||
filename = 'display_image.ppm'
|
||||
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), filename))
|
||||
global LastCommand
|
||||
LastCommand = 'Add a new logo file'
|
||||
@ -224,7 +224,7 @@ def DisplayGIF():
|
||||
return hello()
|
||||
if fle:
|
||||
print('in')
|
||||
filename = 'display_gif'
|
||||
filename = 'display_gif.ppm'
|
||||
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), filename))
|
||||
global LastCommand
|
||||
LastCommand = 'Add a new logo file'
|
||||
|
145
stockTicker.py
145
stockTicker.py
@ -61,7 +61,7 @@ class StockTicker():
|
||||
# Make image fit our screen.
|
||||
#image.thumbnail((self.matrix.width, self.matrix.height), Image.ANTIALIAS)
|
||||
|
||||
image = image.convert('RGB')
|
||||
#image = image.convert('RGB')
|
||||
return image
|
||||
|
||||
def degreesToCompass(self, deg):
|
||||
@ -198,10 +198,10 @@ class StockTicker():
|
||||
def updateMultiple(self, options):
|
||||
|
||||
for option in options:
|
||||
print(option)
|
||||
img = self.functions[option]()
|
||||
img.save('display_images/' + option + '.ppm')
|
||||
|
||||
if option not in ['display_image', 'display_gif']:
|
||||
img = self.functions[option]()
|
||||
img.save('display_images/' + option + '.ppm')
|
||||
|
||||
def checkKilled(self):
|
||||
|
||||
kill = False
|
||||
@ -232,63 +232,149 @@ class StockTicker():
|
||||
print('display_images/' + options[i % len(options)] +'.ppm')
|
||||
|
||||
image = self.openImage('display_images/' + options[i % len(options)] +'.ppm')
|
||||
|
||||
if animation == 'continuous':
|
||||
image2 = self.openImage('display_images/' + options[(i + 1) % len(options)] +'.ppm')
|
||||
|
||||
img_width, img_height = image.size
|
||||
offset_x = 0
|
||||
if animation == 'traditional':
|
||||
if animation in ['traditional', 'continuous']:
|
||||
offset_x = 128
|
||||
elif animation in ['up', 'down']:
|
||||
offset_x = max(0, 128-img_width)
|
||||
|
||||
|
||||
offset_y = 0
|
||||
#first scroll image in from bottom
|
||||
|
||||
frames = 10 #controls how fast gifs run
|
||||
frame = 0
|
||||
|
||||
|
||||
pause_frames = int(1/self.delay)
|
||||
if animation == 'up':
|
||||
offset_y = 33
|
||||
|
||||
|
||||
while offset_y > 0:
|
||||
|
||||
# for animation in gifs
|
||||
if offset_y%frames == 0:
|
||||
print(frame)
|
||||
try:
|
||||
|
||||
image.seek(frame)
|
||||
|
||||
except EOFError:
|
||||
print('finished')
|
||||
frame = 0
|
||||
image.seek(frame)
|
||||
frame +=1
|
||||
|
||||
|
||||
offset_y -= 1
|
||||
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||
self.setImage(image.convert('RGB'), offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
time.sleep(self.delay)
|
||||
kill = self.checkKilled()
|
||||
if kill: break
|
||||
time.sleep(1)
|
||||
|
||||
while pause_frames > 0:
|
||||
if pause_frames%frames == 0:
|
||||
print(frame)
|
||||
try:
|
||||
|
||||
image.seek(frame)
|
||||
|
||||
except EOFError:
|
||||
print('finished')
|
||||
frame = 0
|
||||
image.seek(frame)
|
||||
frame +=1
|
||||
|
||||
pause_frames -=1
|
||||
self.setImage(image.convert('RGB'), offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
time.sleep(self.delay)
|
||||
kill = self.checkKilled()
|
||||
if kill: break
|
||||
|
||||
elif animation == 'down':
|
||||
|
||||
offset_y = -33
|
||||
while offset_y < 0:
|
||||
|
||||
# for animation in gifs
|
||||
if offset_y%frames == 0:
|
||||
print(frame)
|
||||
try:
|
||||
|
||||
image.seek(frame)
|
||||
|
||||
except EOFError:
|
||||
print('finished')
|
||||
frame = 0
|
||||
image.seek(frame)
|
||||
frame +=1
|
||||
|
||||
offset_y += 1
|
||||
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||
self.setImage(image.convert('RGB'), offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
time.sleep(self.delay)
|
||||
kill = self.checkKilled()
|
||||
if kill: break
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
while pause_frames > 0:
|
||||
if pause_frames%frames == 0:
|
||||
print(frame)
|
||||
try:
|
||||
|
||||
image.seek(frame)
|
||||
|
||||
except EOFError:
|
||||
print('finished')
|
||||
frame = 0
|
||||
image.seek(frame)
|
||||
frame +=1
|
||||
|
||||
|
||||
pause_frames -=1
|
||||
self.setImage(image.convert('RGB'), offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
|
||||
time.sleep(self.delay)
|
||||
kill = self.checkKilled()
|
||||
if kill: break
|
||||
|
||||
|
||||
while offset_x > -img_width:
|
||||
|
||||
# for animation in gifs
|
||||
if offset_x%frames == 0:
|
||||
print(frame)
|
||||
try:
|
||||
|
||||
image.seek(frame)
|
||||
|
||||
except EOFError:
|
||||
print('finished')
|
||||
frame = 0
|
||||
image.seek(frame)
|
||||
frame +=1
|
||||
|
||||
#image = image.convert('RGB')
|
||||
offset_x -= 1
|
||||
|
||||
|
||||
# remove the ppixels behind the image, to stop trailing
|
||||
for x in range(0,offset_x ):
|
||||
for y in range(self.matrix.height):
|
||||
|
||||
|
||||
self.matrix.SetPixel(x , y , 0,0,0)
|
||||
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||
self.setImage(image.convert('RGB'), offset_x = offset_x, offset_y = offset_y)
|
||||
|
||||
if animation == 'continuous':
|
||||
if offset_x + img_width < self.matrix.width: # if the image is ending
|
||||
self.setImage(image2, offset_x = offset_x + img_width, offset_y = offset_y)
|
||||
|
||||
buff = 0
|
||||
if offset_x + img_width + buff< self.matrix.width and animation == 'continuous': # if the image is ending
|
||||
self.setImage(image2, offset_x = offset_x + img_width + buff, offset_y = offset_y)
|
||||
else:
|
||||
# remove the ppixels behind the image, to stop trailing
|
||||
for x in range(offset_x + img_width, 128):
|
||||
@ -339,7 +425,7 @@ class StockTicker():
|
||||
|
||||
font = ImageFont.load("./fonts/texgyre-27.pil")
|
||||
|
||||
img = self.textImage(text, font, int(r), int(g), int(b), True, buff = 50)
|
||||
img = self.textImage(text, font, int(r), int(g), int(b), True, w_buff = 50)
|
||||
return img
|
||||
|
||||
def displayGIF(self, gif):
|
||||
@ -1431,6 +1517,14 @@ class StockTicker():
|
||||
|
||||
time.sleep(self.delay*1.1)
|
||||
|
||||
def getUserImage(self):
|
||||
image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_image.ppm'))
|
||||
return image
|
||||
|
||||
def getUserGIF(self):
|
||||
gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_gif.ppm'))
|
||||
return gif
|
||||
|
||||
def displayStocks(self):
|
||||
|
||||
self.scrollImageTransition(['final.ppm', 'final.ppm'], offset_x = 0, offset_y = 0)
|
||||
@ -1486,7 +1580,7 @@ class StockTicker():
|
||||
break
|
||||
|
||||
elif msg == 'G': # gif
|
||||
gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_gif'))
|
||||
gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_gif.ppm'))
|
||||
#self.displayGIF(gif)
|
||||
while True:
|
||||
kill = self.scrollGIF(gif, offset_x = 128)
|
||||
@ -1534,9 +1628,9 @@ class StockTicker():
|
||||
|
||||
self.functions = {'stocks': self.getStockImage, 'crypto': self.getCryptoImage, 'forex': self.getForexImage,
|
||||
'daily_weather':self.getDailyWeatherImage, 'today_weather': self.getDailyWeatherImage, 'league_table': self.getLeagueTableImage,
|
||||
'league_games': self.getLeagueImage, 'news':self.getNewsImage} #put this somewhere else
|
||||
'league_games': self.getLeagueImage, 'news':self.getNewsImage, 'text': self.getUserText, 'display_image': self.getUserImage, 'display_gif':self.getUserGIF} #put this somewhere else
|
||||
|
||||
userSettings = ['stocks', 'crypto', 'forex', 'today_weather', 'daily_weather', 'league_table', 'league_games', 'news'] # these wil be read from csv, just for demo
|
||||
userSettings = ['display_gif', 'text', 'display_image', 'stocks', 'crypto', 'forex', 'today_weather', 'daily_weather', 'league_table', 'league_games', 'news'] # these wil be read from csv, just for demo
|
||||
#userSettings = ['stocks', 'crypto'] # these wil be read from csv, just for demo
|
||||
#userSettings = [ 'forex', 'weather'] # these wil be read from csv, just for demo
|
||||
|
||||
@ -1551,8 +1645,9 @@ if __name__ == '__main__':
|
||||
try:
|
||||
stock_ticker = StockTicker()
|
||||
|
||||
#stock_ticker.process_msg('P')
|
||||
stock_ticker.process_msg('W')
|
||||
#stock_ticker.process_msg(P')
|
||||
#stock_ticker.process_msg('G')
|
||||
stock_ticker.process_msg('A')
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user