two screensavers added
This commit is contained in:
252
server.py
252
server.py
@@ -21,7 +21,9 @@ import numpy as np
|
||||
#stock_ticker = StockTicker()
|
||||
#print('API CALLER NOT STARTED')
|
||||
api_caller = pexpect.spawn("sudo -E python3 api_caller.py")
|
||||
|
||||
displaying_screensaver = False
|
||||
screensaver_p = None
|
||||
professional = False
|
||||
|
||||
command = 300
|
||||
tickerList = 0
|
||||
@@ -99,212 +101,21 @@ def index():
|
||||
}
|
||||
return render_template('index.html', **templateData)
|
||||
|
||||
@app.route("/Runtime", methods=['POST'])
|
||||
def Runtime():
|
||||
|
||||
command = request.form['text']
|
||||
|
||||
|
||||
LastCommand = 'Change runtime'
|
||||
return index()
|
||||
|
||||
@app.route("/Delay", methods=['POST'])
|
||||
def Delay():
|
||||
global DelayTime
|
||||
DelayTime = request.form['text']
|
||||
|
||||
global LastCommand
|
||||
LastCommand = 'Change Delay'
|
||||
return index()
|
||||
|
||||
@app.route("/Speed", methods=['POST'])
|
||||
def Speed():
|
||||
global speed
|
||||
speed = request.form['text']
|
||||
|
||||
ticker.sendline(speed)
|
||||
|
||||
f = open('csv/settings.csv', 'r')
|
||||
CSV = csv.reader(f)
|
||||
next(CSV)
|
||||
for line in CSV:
|
||||
_, brightness = line
|
||||
f.close()
|
||||
|
||||
f = open('csv/settings.csv', 'w+')
|
||||
f.write('speed,brightness\n')
|
||||
f.write(str(speed) + ',' + brightness)
|
||||
f.close()
|
||||
global LastCommand
|
||||
LastCommand = 'Change Speed'
|
||||
return index()
|
||||
|
||||
@app.route("/brightness", methods=['PUT','POST'])
|
||||
def brightness():
|
||||
global brightness
|
||||
|
||||
data= request.data.decode('utf-8')
|
||||
settings = json.loads(data)
|
||||
print(settings)
|
||||
brightness =settings['brightness']
|
||||
print(str(int(brightness) - 1))
|
||||
ticker.sendline(str(int(brightness) - 1))
|
||||
|
||||
f = open('csv/settings.csv', 'r')
|
||||
CSV = csv.reader(f)
|
||||
next(CSV)
|
||||
for line in CSV:
|
||||
speed, _ = line
|
||||
f.close()
|
||||
|
||||
f = open('csv/settings.csv', 'w+')
|
||||
f.write('speed,brightness\n')
|
||||
f.write(str(speed) + ',' + str(brightness))
|
||||
f.close()
|
||||
|
||||
global LastCommand
|
||||
LastCommand = 'Change Brightness'
|
||||
return index()
|
||||
|
||||
@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 index()
|
||||
|
||||
@app.route("/SetNews", methods=['POST'])
|
||||
def SetNews():
|
||||
text = request.form['text']
|
||||
|
||||
#args = ['q', 'sources', 'category', 'country']
|
||||
args = ['q', 'category', 'country']
|
||||
arg_dict = {}
|
||||
lst = text.split(',')
|
||||
|
||||
|
||||
try:
|
||||
for i, arg in enumerate(args):
|
||||
if len(lst[i])>0:
|
||||
arg_dict[arg] = lst[i]
|
||||
|
||||
|
||||
|
||||
json.dump( arg_dict, open( "csv/news_settings.json", 'w+' ))
|
||||
|
||||
except Exception as e:
|
||||
#reset settings
|
||||
|
||||
f = open( "csv/news_settings.json", 'w+' )
|
||||
f.close()
|
||||
|
||||
api_caller.sendline('R')
|
||||
|
||||
return index()
|
||||
|
||||
@app.route("/SetWeather", methods=['POST'])
|
||||
def SetWeather():
|
||||
text = request.form['text']
|
||||
|
||||
#args = ['q', 'sources', 'category', 'country']
|
||||
|
||||
f = open( "csv/weather_location.txt", 'w+' )
|
||||
f.write(text)
|
||||
f.close()
|
||||
api_caller.sendline('R')
|
||||
|
||||
return index()
|
||||
|
||||
@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:
|
||||
|
||||
filename = 'user_gif.gif'
|
||||
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)),os.path.join('display_images', filename)))
|
||||
global LastCommand
|
||||
LastCommand = 'Add a new logo file'
|
||||
ticker.sendline('K')
|
||||
ticker.sendline('G')
|
||||
return hello()
|
||||
return index()
|
||||
|
||||
@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:
|
||||
|
||||
filename = 'user_image.ppm'
|
||||
fle.save(os.path.join(os.path.dirname(os.path.abspath(__file__)),os.path.join('display_images', filename)))
|
||||
global LastCommand
|
||||
LastCommand = 'Add a new logo file'
|
||||
ticker.sendline('K')
|
||||
ticker.sendline('I')
|
||||
return hello()
|
||||
return index()
|
||||
|
||||
|
||||
@app.route("/Ticker", methods=['POST'])
|
||||
def Ticker():
|
||||
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 = 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'
|
||||
return hello()
|
||||
return index()
|
||||
|
||||
@app.route("/AddLogo", methods=['POST'])
|
||||
def AddLogo():
|
||||
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 = secure_filename(fle.filename)
|
||||
fle.save(os.path.join(LOGO_FOLDER, filename))
|
||||
global LastCommand
|
||||
LastCommand = 'Add a new logo file'
|
||||
return hello()
|
||||
return index()
|
||||
|
||||
professional = False
|
||||
|
||||
|
||||
@app.route("/start", methods = ['PUT', 'POST'])
|
||||
def start():
|
||||
global displaying_screensaver
|
||||
global ticker
|
||||
global api_caller
|
||||
if displaying_screensaver:
|
||||
screensaver_p.close()
|
||||
api_caller = pexpect.spawn("sudo -E python3 api_caller.py")
|
||||
ticker = pexpect.spawn("sudo -E taskset -c 3 python3 stockTicker.py")
|
||||
displaying_screensaver = False
|
||||
|
||||
|
||||
print(professional)
|
||||
data = str(request.data)
|
||||
|
||||
@@ -396,8 +207,37 @@ def upload():
|
||||
|
||||
|
||||
return index()
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route("/screensaver", methods = ['PUT', 'POST'])
|
||||
def screensaver():
|
||||
global displaying_screensaver
|
||||
global ticker
|
||||
global api_caller
|
||||
global screensaver_p
|
||||
api_caller.close()
|
||||
ticker.close()
|
||||
data = str(request.data)
|
||||
|
||||
|
||||
if "Pulsating Colors" in data:
|
||||
screensaver_p = pexpect.spawn("sudo -E python3 ./rpi-rgb-led-matrix/bindings/python/samples/pulsing-colors.py")
|
||||
|
||||
elif "Rotating Square" in data:
|
||||
screensaver_p = pexpect.spawn("sudo -E python3 ./rpi-rgb-led-matrix/bindings/python/samples/rotating-block-generator.py")
|
||||
|
||||
elif "Pulsating brightness" in data:
|
||||
screensaver_p = pexpect.spawn("sudo -E python3 ./rpi-rgb-led-matrix/bindings/python/samples/pulsing-brightness.py")
|
||||
|
||||
elif "Game of Life" in data:
|
||||
screensaver_p = pexpect.spawn("sudo -E python3 game_of_life.py")
|
||||
|
||||
displaying_screensaver = True
|
||||
return index()
|
||||
|
||||
|
||||
|
||||
|
||||
def combine_dict(current_settings, input_symbols, current_key):
|
||||
# removes keys not in input from current_settings[current_key] and adds keys not in current from input
|
||||
@@ -532,6 +372,12 @@ def save_message_settings(input_settings):
|
||||
def stop():
|
||||
print('stop')
|
||||
ticker.sendline('K')
|
||||
global displaying_screensaver
|
||||
if displaying_screensaver:
|
||||
screensaver.close()
|
||||
api_caller = pexpect.spawn("sudo -E python3 api_caller.py")
|
||||
ticker = pexpect.spawn("sudo -E taskset -c 3 python3 stockTicker.py")
|
||||
displaying_screensaver = False
|
||||
return index()
|
||||
|
||||
@app.route("/shutdown")
|
||||
|
Reference in New Issue
Block a user