-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
32 lines (25 loc) · 1.15 KB
/
app.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
from flask import Flask, render_template, request
import subprocess
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
# 处理表单提交
subscription_text = request.form['subscription_text']
# 将输入框的内容替换到 rss.py 文件中的网页 RSS 订阅地址
with open('rss.py', 'r', encoding='utf-8') as file:
lines = file.readlines()
with open('rss.py', 'w', encoding='utf-8') as file:
for line in lines:
if 'rss_url =' in line:
file.write(f'rss_url = "{subscription_text}"\n')
else:
file.write(line)
# 运行 rss.py 文件,并获取输出内容
output = subprocess.check_output(['python3', 'rss.py']).decode('utf-8')
# 在网页上显示输出内容
return render_template('index.html', output=output)
# 渲染包含输入框和确定按钮的模板
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=12589)