forked from tschuehly/music-cards
-
Notifications
You must be signed in to change notification settings - Fork 1
/
web_add_card.py
61 lines (53 loc) · 1.72 KB
/
web_add_card.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# coding:utf-8
import re
import sys
import subprocess
from Reader import Reader
reader = Reader()
reload(sys)
sys.setdefaultencoding('utf-8')
# set flask
from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
@app.route('/')
def index():
title = "NFC Reader/Writer WEB"
# index.html をレンダリングする
return render_template('index.html', title=title)
@app.route('/read', methods=['GET', 'POST'])
def read():
res = subprocess.call('sudo systemctl stop musiccards.service', shell=True)
print (res)
title = "NFC Reader/Writer WEB"
try:
plist = reader.readCard()
except ValueError:
plist = "thin card in maybe notdata"
# read.html をレンダリングする
return render_template('read.html', plist=plist, title=title)
# /post にアクセスしたときの処理
@app.route('/post', methods=['GET', 'POST'])
def post():
title = "NFC Reader/Writer WEB"
if request.method == 'POST':
# リクエストフォームから「プレイリスト」を取得して
plist = request.form['plist']
#プレイリストを書き込み
reader.writeCard(plist)
# index.html をレンダリングする
return redirect(url_for('read'))
else:
# エラーなどでリダイレクトしたい場合はこんな感じで
return redirect(url_for('index'))
@app.route('/end', methods=['GET', 'POST'])
def end():
res = subprocess.call('sudo systemctl restart musiccards.service', shell=True)
print (res)
return redirect(url_for('index'))
#func = request.environ.get('werkzeug.server.shutdown')
#if func is None:
# raise RuntimeError('Not running with the Werkzeug Server')
#func()
#return 'Server shutting down...'
if __name__ == '__main__':
app.run(host='0.0.0.0')