Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
从网页端控制 feeluown 示例
"""
使用方法
- 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
You can’t perform that action at this time.