image and gif upload and display working

This commit is contained in:
Neythen 2021-05-21 11:20:39 +01:00
parent b511b4f69e
commit 29784eed4f
15 changed files with 127 additions and 21 deletions

View File

@ -1,3 +1,3 @@
name,current,24hr change
bitcoin,50378,0.18956930030648758
ethereum,4007.97,4.564560454952176
bitcoin,40905,1.9630605505752174
ethereum,2756.88,2.711695798229129

1 name current 24hr change
2 bitcoin 50378 40905 0.18956930030648758 1.9630605505752174
3 ethereum 4007.97 2756.88 4.564560454952176 2.711695798229129

View File

@ -1 +1 @@
hello world!,255,255,0
ARUSHI IS CUTE,0,0,255
1 hello world! ARUSHI IS CUTE 0 255 0 255

View File

@ -1,2 +1,2 @@
speed,brightness
s,5
m,5
1 speed brightness
2 s m 5

BIN
display_gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

BIN
display_image Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
final.ppm

Binary file not shown.

Binary file not shown.

BIN
gifs/close.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

BIN
gifs/open.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.

View File

@ -137,15 +137,58 @@ def Brightness():
LastCommand = 'Change Brightness'
return hello()
@app.route("/Display_text", methods=['POST'])
def Display_text():
@app.route("/DisplayText", methods=['POST'])
def DisplayText():
text = request.form['text']
f = open('csv/scroll_text.csv', 'w+')
f.write(text)
f.close()
ticker.sendline('K')
ticker.sendline('T')
return hello()
@app.route("/DisplayImage", methods=['POST'])
def DisplayImage():
if request.method == 'POST':
if 'file' not in request.files:
print('No file attached in request')
return hello()
fle = request.files['file']
if fle.filename == '':
print('No file selected')
return hello()
if fle and allowed_file(fle.filename):
filename = 'display_image'
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), filename))
global LastCommand
LastCommand = 'Add a new logo file'
ticker.sendline('K')
ticker.sendline('I')
return hello()
return hello()
@app.route("/DisplayGIF", methods=['POST'])
def DisplayGIF():
if request.method == 'POST':
if 'file' not in request.files:
print('No file attached in request')
return hello()
fle = request.files['file']
if fle.filename == '':
print('No file selected')
return hello()
if fle:
print('in')
filename = 'display_gif'
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), filename))
global LastCommand
LastCommand = 'Add a new logo file'
ticker.sendline('K')
ticker.sendline('G')
return hello()
return hello()
@app.route("/Ticker", methods=['POST'])
def Ticker():
@ -153,13 +196,13 @@ def Ticker():
if 'file' not in request.files:
print('No file attached in request')
return hello()
file = request.files['file']
if file.filename == '':
fle = request.files['file']
if fle.filename == '':
print('No file selected')
return hello()
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(CSV_FOLDER, filename))
if fle and allowed_file(fle.filename):
filename = secure_filename(fle.filename)
fle.save(os.path.join(CSV_FOLDER, filename))
process_file(os.path.join(CSV_FOLDER, filename), filename)
global LastCommand
LastCommand = 'Change CSV file'
@ -172,13 +215,13 @@ def AddLogo():
if 'file' not in request.files:
print('No file attached in request')
return hello()
file = request.files['file']
if file.filename == '':
fle = request.files['file']
if fle.filename == '':
print('No file selected')
return hello()
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(LOGO_FOLDER, filename))
if fle and allowed_file(fle.filename):
filename = secure_filename(fle.filename)
fle.save(os.path.join(LOGO_FOLDER, filename))
global LastCommand
LastCommand = 'Add a new logo file'
return hello()

View File

@ -180,6 +180,37 @@ class StockTicker():
img.save('scroll_text.ppm')
self.scrollImageTransition(['scroll_text.ppm', 'scroll_text.ppm'], offset_x = 128, offset_y = 0, stocks = False)
def displayGIF(self, gif_file):
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':
self.resetMatrix()
break
self.process_msg(msg)
except KeyboardInterrupt:
sys.stdout.flush()
pass
@ -406,11 +437,11 @@ class StockTicker():
def process_msg(self, msg):
if msg == 'S':
if msg == 'S': # stocks
self.getFullStockImage(1)
self.displayStocks()
# speed settings
elif msg == 's':
self.delay = 0.03
@ -420,16 +451,36 @@ class StockTicker():
elif msg == 'f':
self.delay = 0.005
elif msg in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
elif msg in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']: # birghtness ettings
self.brightness = min(1.0, float(msg)/10 + 0.1)
elif msg == 'T':
elif msg == 'T':# text
self.displayText()
elif msg == 'I': # image
image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_image'))
self.setImage( image)
elif msg == 'G': # gif
self.displayGIF(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_gif'))
elif msg == 'K': # kill
self.resetMatrix()
if __name__ == '__main__':
#print(sys.stdin.readlines())
stock_ticker = StockTicker()
#stock_ticker.displayGIF('/home/pi/Desktop/stock_ticker/gifs/open.gif')
#stock_ticker.displayGIF('/home/pi/Desktop/stock_ticker/gifs/close.gif')
#stock_ticker.process_msg(brightness)
#stock_ticker.process_msg(speed)

Binary file not shown.

View File

@ -30,11 +30,23 @@
</form>
<p>Display scrolling text. Enter the message followed by the rgb values seperated by commas. e.g. hello world!,255,255,0</p>
<form action="/Display_text" method="POST">
<form action="/DisplayText" method="POST">
<input name="text" placeholder="hello world!,255,255,0"style="height:24px">
<input type="submit" value="Display"style="height:30px">
</form>
<p>Display an image</p>
<form action="/DisplayImage" method="POST" enctype=multipart/form-data>
<p><input type=file name=file style="height:30px">
<input type=submit value=Upload style="height:30px">
</form>
<p>Display a gif</p>
<form action="/DisplayGIF" method="POST" enctype=multipart/form-data>
<p><input type=file name=file style="height:30px">
<input type=submit value=Upload style="height:30px">
</form>
<br><br>
<h3>Tickers to display</h3>
<p>To change the tickers displayed please upload a CSV (comma separated value) file with 11 tickers on each row e.g</p>