scrolling news headlines added
This commit is contained in:
parent
7486ac1125
commit
b0f106c64f
Binary file not shown.
@ -8,6 +8,8 @@ import datetime as dt
|
|||||||
import sys, os, base64, hashlib, hmac
|
import sys, os, base64, hashlib, hmac
|
||||||
import requests
|
import requests
|
||||||
from pycoingecko import CoinGeckoAPI
|
from pycoingecko import CoinGeckoAPI
|
||||||
|
from newsapi import NewsApiClient
|
||||||
|
|
||||||
|
|
||||||
def readCSV(file_path, max_stocks):
|
def readCSV(file_path, max_stocks):
|
||||||
|
|
||||||
@ -144,8 +146,25 @@ def updateCrypto(coins):
|
|||||||
|
|
||||||
CSV.write(coin+ ',' + str(response[coin]['usd']) + ',' + str(response[coin]['usd_24h_change']) + '\n')
|
CSV.write(coin+ ',' + str(response[coin]['usd']) + ',' + str(response[coin]['usd_24h_change']) + '\n')
|
||||||
CSV.close()
|
CSV.close()
|
||||||
|
|
||||||
|
|
||||||
|
def updateNews():
|
||||||
|
top_headlines = newsapi.get_top_headlines()
|
||||||
|
headline_titles = [top_headline['title'] for top_headline in top_headlines['articles']]
|
||||||
|
CSV = open('csv/news.csv', 'w+')
|
||||||
|
CSV.write('headline\n')
|
||||||
|
|
||||||
|
for title in headline_titles:
|
||||||
|
CSV.write(title + '\n')
|
||||||
|
|
||||||
|
CSV.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
|
||||||
|
|
||||||
|
|
||||||
finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub
|
finnhubAPIkey = "c24qddqad3ickpckgg80" #Finnhub
|
||||||
finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub
|
finnhubsandboxAPIkey = "sandbox_c24qddqad3ickpckgg8g" #Finnhub
|
||||||
sleeptime = 2 #minutes
|
sleeptime = 2 #minutes
|
||||||
@ -173,12 +192,13 @@ if __name__ == '__main__':
|
|||||||
NY_time = datetime.now(NY_zone)
|
NY_time = datetime.now(NY_zone)
|
||||||
|
|
||||||
print(NY_time)
|
print(NY_time)
|
||||||
coins, coin_info = readCSV('csv/crypto.csv', max_stocks)
|
|
||||||
print(coins, coin_info)
|
|
||||||
updateCrypto(coins)
|
|
||||||
|
|
||||||
sys.exit()
|
|
||||||
while True:
|
while True:
|
||||||
|
coins, coin_info = readCSV('csv/crypto.csv', max_stocks)
|
||||||
|
updateCrypto(coins)
|
||||||
|
|
||||||
|
#updateNews()
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone)
|
NY_time = datetime.now(NY_zone)
|
||||||
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name,current,24hr change
|
name,current,24hr change
|
||||||
bitcoin,40905,1.9630605505752174
|
bitcoin,41158,-3.112342608605254
|
||||||
ethereum,2756.88,2.711695798229129
|
ethereum,2691.26,-8.560574933024819
|
||||||
|
|
@ -1 +1 @@
|
|||||||
14/05/2021 06:29:45
|
21/05/2021 09:21:44
|
||||||
|
|
21
csv/news.csv
Normal file
21
csv/news.csv
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
headline, ' doesnt display, sort out comma
|
||||||
|
Total of 43 Changi Airport workers test positive for Covid-19; source likely worker who helped infected family from South Asia - The Straits Times
|
||||||
|
Covid-19 (May 21) - 6493 new cases, nationwide uptrend; 50 deaths - Malaysiakini
|
||||||
|
Lady Gaga says rape as teenager left her pregnant and caused psychotic break - The Guardian
|
||||||
|
Coronavirus: Spain to lift restrictions for UK and Japanese travellers - BBC News
|
||||||
|
Walsh wonderful as Warriors win thriller over Tigers - NRL.COM
|
||||||
|
Diana interview: Whistleblower wants apology from BBC bosses - BBC News
|
||||||
|
Latest Gombak death-in-custody due to heart attack, says S'gor CPO - Malaysiakini
|
||||||
|
Prince Harry tells Oprah that Diana's death led him to drink and drugs, accuses royals of 'total neglect' - NBC News
|
||||||
|
Manchester United passed on signing Man City star Ruben Dias - Manchester Evening News
|
||||||
|
Prince Harry: pain of Diana's death pushed me to drink and drugs - The Star Online
|
||||||
|
Kim Kardashian Accused Kourtney Kardashian Of Constantly "Degrading" Her Staff After A Brutal Confrontation With Her Nanny - BuzzFeed News
|
||||||
|
Overwatch 2 PvP is 5v5, Bastion reworked "from the ground up" - Eurogamer.net
|
||||||
|
Hospital staff 'should have checked for blood clots', say SA family - 9News
|
||||||
|
Cloudy skies to continue in Southern Luzon, Visayas and Mindanao due to ITCZ - INQUIRER.net
|
||||||
|
16-year-old Pune boy merges 50,000 images of Moon to create detailed picture - The Tribune
|
||||||
|
UK to offer Australia tariff-free trade deal despite farmers' fears - BBC News
|
||||||
|
Disha Patani does backflip to new BTS song Butter and Tiger Shroff is impressed, watch - Hindustan Times
|
||||||
|
Mop-up operations begin in Cape Town after flooding caused by heavy rain - News24
|
||||||
|
New type of coronavirus originating in dogs found — study - The Edge Markets MY
|
||||||
|
House panel OKs bill for creation of PH virology institute, CDC - ABS-CBN News
|
Can't render this file because it contains an unexpected character in line 12 and column 58.
|
@ -1,2 +1,2 @@
|
|||||||
speed,brightness
|
speed,brightness
|
||||||
m,5
|
f,5
|
|
@ -1,22 +1,22 @@
|
|||||||
name,current,opening
|
name,current,opening
|
||||||
MSFT,243.03,241.8
|
MSFT,246.48,243.96
|
||||||
NFLX,486.66,489.13
|
NFLX,501.67,489.55
|
||||||
GOOG,2261.97,2261.09
|
GOOG,2356.09,2328.04
|
||||||
TSLA,571.69,601.545
|
TSLA,586.78,575
|
||||||
AAPL,124.97,124.58
|
AAPL,127.31,125.23
|
||||||
INTC,54.01,54.04
|
INTC,55.95,55.57
|
||||||
TXN,178.99,179.99
|
TXN,185.3,182.28
|
||||||
HPQ,32.39,32
|
HPQ,32.04,31.98
|
||||||
HOG,46.25,45.35
|
HOG,48.28,48.99
|
||||||
LUV,59.93,58.97
|
LUV,59.92,60.92
|
||||||
WMT,138.24,136.23
|
WMT,142.42,141.5
|
||||||
BJ,45.99,45.63
|
BJ,46.16,48.26
|
||||||
ETSY,156.59,163.3368
|
ETSY,172.36,166.28
|
||||||
G,44.51,43.84
|
G,44.26,43.83
|
||||||
GDDY,79.29,80.92
|
GDDY,81.4,81.18
|
||||||
GNRC,293.36,294.17
|
GNRC,308.53,304.56
|
||||||
PEP,146.37,144.24
|
PEP,147.23,145.25
|
||||||
STM,34.81,35.28
|
STM,36.18,35.79
|
||||||
YELP,38.14,37.39
|
YELP,38.38,37.84
|
||||||
XRAY,66.61,65.83
|
XRAY,67.95,67.72
|
||||||
ZTS,170.85,168.37
|
ZTS,175.8,171.52
|
||||||
|
|
BIN
display_gif
BIN
display_gif
Binary file not shown.
Before Width: | Height: | Size: 747 B After Width: | Height: | Size: 821 B |
BIN
display_image
BIN
display_image
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.3 KiB |
BIN
scroll_text.ppm
BIN
scroll_text.ppm
Binary file not shown.
21
server.py
21
server.py
@ -229,8 +229,8 @@ def AddLogo():
|
|||||||
|
|
||||||
@app.route("/matrix", methods=['POST'])
|
@app.route("/matrix", methods=['POST'])
|
||||||
def matrix():
|
def matrix():
|
||||||
global LastCommand
|
global LastCommand
|
||||||
if "Run Display" in request.form:
|
if "Run Stocks" in request.form:
|
||||||
pass
|
pass
|
||||||
print('run display')
|
print('run display')
|
||||||
#stock_ticker.runStockTicker(command, DelayTime, speedTime)
|
#stock_ticker.runStockTicker(command, DelayTime, speedTime)
|
||||||
@ -240,13 +240,24 @@ def matrix():
|
|||||||
#child.sendline('sent from server')
|
#child.sendline('sent from server')
|
||||||
|
|
||||||
#process = Popen(["sudo", "-E", "python3", "stockTicker.py"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
#process = Popen(["sudo", "-E", "python3", "stockTicker.py"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||||
|
ticker.sendline('K')
|
||||||
ticker.sendline('S')
|
ticker.sendline('S')
|
||||||
|
|
||||||
print('back in flask')
|
print('back in flask')
|
||||||
|
|
||||||
|
|
||||||
LastCommand = 'Run display'
|
LastCommand = 'Run display'
|
||||||
elif "Stop Display (at next refresh)" in request.form:
|
if "Run News" in request.form:
|
||||||
|
pass
|
||||||
|
print('run display')
|
||||||
|
ticker.sendline('K')
|
||||||
|
ticker.sendline('N')
|
||||||
|
|
||||||
|
print('back in flask')
|
||||||
|
|
||||||
|
|
||||||
|
LastCommand = 'Run display'
|
||||||
|
elif "Stop Display (at next refresh)" in request.form:
|
||||||
pass
|
pass
|
||||||
print('run display')
|
print('run display')
|
||||||
#ticker.kill()
|
#ticker.kill()
|
||||||
@ -256,14 +267,14 @@ def matrix():
|
|||||||
ticker.sendline('K')
|
ticker.sendline('K')
|
||||||
except:
|
except:
|
||||||
print("none running")
|
print("none running")
|
||||||
elif "Shutdown the pi" in request.form:
|
elif "Shutdown the pi" in request.form:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
LastCommand = 'shutdown'
|
LastCommand = 'shutdown'
|
||||||
os.system("sudo shutdown now")
|
os.system("sudo shutdown now")
|
||||||
except:
|
except:
|
||||||
print("couldn't shutdown")
|
print("couldn't shutdown")
|
||||||
return hello()
|
return hello()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host='0.0.0.0', port=1024, debug=False) # the debuggger causes flickering
|
app.run(host='0.0.0.0', port=1024, debug=False) # the debuggger causes flickering
|
||||||
|
134
stockTicker.py
134
stockTicker.py
@ -97,7 +97,21 @@ class StockTicker():
|
|||||||
offset_x -= 1
|
offset_x -= 1
|
||||||
|
|
||||||
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
|
||||||
time.sleep(delay)
|
|
||||||
|
try:
|
||||||
|
msg = getInput()
|
||||||
|
if msg == 'K':
|
||||||
|
self.resetMatrix()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
self.process_msg(msg)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
sys.stdout.flush()
|
||||||
|
pass
|
||||||
|
|
||||||
|
time.sleep(self.delay)
|
||||||
|
return False
|
||||||
|
|
||||||
def scrollImageTransition(self, image_files, offset_x = 0, offset_y = 0, stocks = True):
|
def scrollImageTransition(self, image_files, offset_x = 0, offset_y = 0, stocks = True):
|
||||||
# use two image files and switch between them with a seemless transition
|
# use two image files and switch between them with a seemless transition
|
||||||
@ -138,9 +152,12 @@ class StockTicker():
|
|||||||
time.sleep(self.delay)
|
time.sleep(self.delay)
|
||||||
try:
|
try:
|
||||||
msg = getInput()
|
msg = getInput()
|
||||||
|
|
||||||
if msg == 'K':
|
if msg == 'K':
|
||||||
self.resetMatrix()
|
self.resetMatrix()
|
||||||
kill = True
|
kill = True
|
||||||
|
image1.close()
|
||||||
|
image2.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
self.process_msg(msg)
|
self.process_msg(msg)
|
||||||
@ -148,7 +165,9 @@ class StockTicker():
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
image1.close()
|
||||||
|
image2.close()
|
||||||
|
|
||||||
if kill: break
|
if kill: break
|
||||||
|
|
||||||
if stocks:
|
if stocks:
|
||||||
@ -159,7 +178,9 @@ class StockTicker():
|
|||||||
current_img = 1
|
current_img = 1
|
||||||
offset_x = 0
|
offset_x = 0
|
||||||
|
|
||||||
def displayText(self):
|
def displayTextRepeating(self):
|
||||||
|
|
||||||
|
|
||||||
f = open('csv/scroll_text.csv', 'r')
|
f = open('csv/scroll_text.csv', 'r')
|
||||||
|
|
||||||
CSV = csv.reader(f)
|
CSV = csv.reader(f)
|
||||||
@ -181,37 +202,80 @@ class StockTicker():
|
|||||||
img.save('scroll_text.ppm')
|
img.save('scroll_text.ppm')
|
||||||
self.scrollImageTransition(['scroll_text.ppm', 'scroll_text.ppm'], offset_x = 128, offset_y = 0, stocks = False)
|
self.scrollImageTransition(['scroll_text.ppm', 'scroll_text.ppm'], offset_x = 128, offset_y = 0, stocks = False)
|
||||||
|
|
||||||
|
def displayText(self, text, font):
|
||||||
|
|
||||||
def displayGIF(self, gif_file):
|
|
||||||
|
|
||||||
im = Image.open(gif_file)
|
|
||||||
|
width, height = self.get_text_dimensions(text, font)
|
||||||
|
print(text)
|
||||||
|
print('dims:', width, height)
|
||||||
|
img = Image.new('RGB', (width + 50, 32))
|
||||||
|
d = ImageDraw.Draw(img)
|
||||||
|
|
||||||
# To iterate through the entire gif
|
d.text((4, 0), text, fill=(255, 255, 255), font=font)
|
||||||
|
|
||||||
i = 0
|
|
||||||
while 1:
|
|
||||||
print(im.tell())
|
|
||||||
try:
|
|
||||||
im.seek(i)
|
|
||||||
except EOFError:
|
|
||||||
print('finished')
|
|
||||||
i = 0
|
|
||||||
im.seek(i)
|
|
||||||
# do something to im
|
|
||||||
self.setImage(im.convert('RGB'))
|
|
||||||
time.sleep(0.5)
|
|
||||||
i += 1
|
|
||||||
try:
|
|
||||||
msg = getInput()
|
|
||||||
if msg == 'K':
|
|
||||||
self.resetMatrix()
|
|
||||||
break
|
|
||||||
|
|
||||||
self.process_msg(msg)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
sys.stdout.flush()
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
img.save('scroll_text.ppm')
|
||||||
|
return self.scrollImage('scroll_text.ppm', offset_x = 128, offset_y = 0)
|
||||||
|
|
||||||
|
def displayNews(self):
|
||||||
|
font = ImageFont.load("./fonts/8x13.pil")
|
||||||
|
while True:
|
||||||
|
headlines = []
|
||||||
|
f = open('csv/news.csv', 'r')
|
||||||
|
CSV = csv.reader(f)
|
||||||
|
next(CSV)
|
||||||
|
for row in CSV:
|
||||||
|
headlines.append(','.join(row))
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
for headline in headlines:
|
||||||
|
killed = self.displayText(headline, font)
|
||||||
|
|
||||||
|
if killed:
|
||||||
|
kill = True
|
||||||
|
if kill: break
|
||||||
|
if kill: break
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def displayGIF(self, gif_file):
|
||||||
|
with open('log.txt', "w") as log:
|
||||||
|
|
||||||
|
try:
|
||||||
|
im = Image.open(gif_file)
|
||||||
|
|
||||||
|
# To iterate through the entire gif
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while 1:
|
||||||
|
print(im.tell())
|
||||||
|
try:
|
||||||
|
im.seek(i)
|
||||||
|
except EOFError:
|
||||||
|
print('finished')
|
||||||
|
i = 0
|
||||||
|
im.seek(i)
|
||||||
|
# do something to im
|
||||||
|
self.setImage(im.convert('RGB'))
|
||||||
|
time.sleep(0.5)
|
||||||
|
i += 1
|
||||||
|
try:
|
||||||
|
msg = getInput()
|
||||||
|
|
||||||
|
if msg == 'K':
|
||||||
|
im.close()
|
||||||
|
self.resetMatrix()
|
||||||
|
break
|
||||||
|
|
||||||
|
self.process_msg(msg)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
sys.stdout.flush()
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
log.write(str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Using change between min and day price give appropriate arrow
|
#Using change between min and day price give appropriate arrow
|
||||||
@ -361,6 +425,8 @@ class StockTicker():
|
|||||||
#os.system("sudo ./demo -D1 final.ppm -t " + str(displayTime) +" -m "+ str(speedDisplay) +" --led-gpio-mapping=adafruit-hat --led-rows=32 --led-cols=256")
|
#os.system("sudo ./demo -D1 final.ppm -t " + str(displayTime) +" -m "+ str(speedDisplay) +" --led-gpio-mapping=adafruit-hat --led-rows=32 --led-cols=256")
|
||||||
#os.system("sudo ./demo -D1 final.ppm -t " + str(self.displayTime) +" -m "+ str(self.speedDisplay) +" --led-gpio-mapping=adafruit-hat --led-rows=64 --led-cols=64 --led-slowdown-gpio=4 ")
|
#os.system("sudo ./demo -D1 final.ppm -t " + str(self.displayTime) +" -m "+ str(self.speedDisplay) +" --led-gpio-mapping=adafruit-hat --led-rows=64 --led-cols=64 --led-slowdown-gpio=4 ")
|
||||||
self.scrollImageTransition(['final.ppm', 'final.ppm'], offset_x = 0, offset_y = 0)
|
self.scrollImageTransition(['final.ppm', 'final.ppm'], offset_x = 0, offset_y = 0)
|
||||||
|
|
||||||
|
|
||||||
#Retrieve symbols and stock info from the csv file
|
#Retrieve symbols and stock info from the csv file
|
||||||
def readCSV(self):
|
def readCSV(self):
|
||||||
|
|
||||||
@ -441,6 +507,8 @@ class StockTicker():
|
|||||||
self.getFullStockImage(1)
|
self.getFullStockImage(1)
|
||||||
self.displayStocks()
|
self.displayStocks()
|
||||||
|
|
||||||
|
elif msg == 'N': #news
|
||||||
|
self.displayNews()
|
||||||
# speed settings
|
# speed settings
|
||||||
elif msg == 's':
|
elif msg == 's':
|
||||||
self.delay = 0.03
|
self.delay = 0.03
|
||||||
@ -459,7 +527,7 @@ class StockTicker():
|
|||||||
|
|
||||||
elif msg == 'T':# text
|
elif msg == 'T':# text
|
||||||
|
|
||||||
self.displayText()
|
self.displayTextRepeating()
|
||||||
|
|
||||||
elif msg == 'I': # image
|
elif msg == 'I': # image
|
||||||
|
|
||||||
@ -471,6 +539,7 @@ class StockTicker():
|
|||||||
self.displayGIF(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_gif'))
|
self.displayGIF(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_gif'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
elif msg == 'K': # kill
|
elif msg == 'K': # kill
|
||||||
self.resetMatrix()
|
self.resetMatrix()
|
||||||
|
|
||||||
@ -478,7 +547,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
#print(sys.stdin.readlines())
|
#print(sys.stdin.readlines())
|
||||||
stock_ticker = StockTicker()
|
stock_ticker = StockTicker()
|
||||||
|
#stock_ticker.process_msg('f')
|
||||||
|
#stock_ticker.displayNews()
|
||||||
#stock_ticker.displayGIF('/home/pi/Desktop/stock_ticker/gifs/open.gif')
|
#stock_ticker.displayGIF('/home/pi/Desktop/stock_ticker/gifs/open.gif')
|
||||||
|
|
||||||
#stock_ticker.displayGIF('/home/pi/Desktop/stock_ticker/gifs/close.gif')
|
#stock_ticker.displayGIF('/home/pi/Desktop/stock_ticker/gifs/close.gif')
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
<form action="/matrix" method="POST">
|
<form action="/matrix" method="POST">
|
||||||
<input type="submit" name="Run Display" value="Run Display" style="height:50px" >
|
<input type="submit" name="Run Stocks" value="Run Stocks" style="height:50px" >
|
||||||
|
<input type="submit" name="Run News" value="Run News" style="height:50px" >
|
||||||
<input type="submit" name="Stop Display (at next refresh)" value="Stop 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">
|
<input type="submit" name="Shutdown the pi" value="Shutdown the pi"style="height:50px">
|
||||||
</form>
|
</form>
|
||||||
|
6
test.py
6
test.py
@ -14,11 +14,7 @@ import pexpect
|
|||||||
from pycoingecko import CoinGeckoAPI
|
from pycoingecko import CoinGeckoAPI
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
cg = CoinGeckoAPI()
|
|
||||||
|
|
||||||
print(cg.get_price(ids='bitcoin, ethereum', vs_currencies = 'usd', include_24hr_change=True))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user