Created
August 3, 2018 06:51
-
-
Save cosven/239c0132ea3c90667ec436ae8b067890 to your computer and use it in GitHub Desktop.
从网页端控制 feeluown 示例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
使用方法 | |
- pip3 install flask # 安装依赖 | |
- python3 remote_control.py # 启动网页,在浏览器 | |
""" | |
import socket | |
from flask import Flask, request | |
app = Flask(__name__) | |
index_html = """ | |
<html> | |
<body> | |
<form method="POST" action="/exec"> | |
<input name="cmd" style="width: 400px; height: 30px;" placeholder="输入命令,比如 `play fuo://netease/songs/25704014`" /> | |
<br/> | |
<br/> | |
<input type="submit" /> | |
<p></p> | |
执行返回: | |
<blockquote><pre>{}</pre></blockquote> | |
</form> | |
</body> | |
</html> | |
""" | |
@app.route('/') | |
def index(): | |
return index_html | |
@app.route('/exec', methods=["POST"]) | |
def exec_cmd(): | |
cmd = request.form.get('cmd') or 'help' | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect(('0.0.0.0', 23333)) | |
sock.recv(1024 * 10) | |
sock.sendall(bytes(cmd, 'utf-8') + b'\n') | |
content = sock.recv(1024 * 10) | |
return index_html.format(content.decode('utf-8')) | |
app.run(host='0.0.0.0', port=9000, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment