更新新的请求方式,避免Dot APP过滤参数
This commit is contained in:
parent
4a3eaf87e8
commit
7e5b34d122
1 changed files with 34 additions and 7 deletions
41
app.py
41
app.py
|
|
@ -36,19 +36,26 @@ def create_app(config_name='default'):
|
|||
for handler_name in available_handlers:
|
||||
if handler_name == 'crypto':
|
||||
docs += f"""
|
||||
<li><a href="/rss/{handler_name}?pair=ETH-USDT">/rss/{handler_name}?pair=ETH-USDT</a> - ETH价格</li>
|
||||
<li><a href="/rss/{handler_name}?pair=BTC-USDT">/rss/{handler_name}?pair=BTC-USDT</a> - BTC价格</li>
|
||||
<li><a href="/rss/{handler_name}">/rss/{handler_name}</a> - 默认加密货币价格</li>
|
||||
<li><a href="/rss/{handler_name}/eth/usdt">/rss/{handler_name}/eth/usdt</a> - ETH/USDT价格</li>
|
||||
<li><a href="/rss/{handler_name}/btc/usdt">/rss/{handler_name}/btc/usdt</a> - BTC/USDT价格</li>
|
||||
<li><a href="/rss/{handler_name}/ETH/USDC">/rss/{handler_name}/ETH/USDC</a> - ETH/USDC价格(大写)</li>
|
||||
"""
|
||||
|
||||
docs += """
|
||||
</ul>
|
||||
<h2>使用说明:</h2>
|
||||
<p>将RSS链接粘贴到您的墨水屏RSS阅读器中即可。</p>
|
||||
<p>URL格式:/rss/crypto/[base_currency]/[quote_currency]</p>
|
||||
<p>例如:/rss/crypto/eth/usdc 或 /rss/crypto/ETH/USDC 都表示 ETH-USDC 交易对</p>
|
||||
<p>支持大小写混合格式</p>
|
||||
"""
|
||||
return docs
|
||||
|
||||
@app.route('/rss/<handler_name>')
|
||||
def rss_feed(handler_name):
|
||||
@app.route('/rss/<handler_name>/<path:base_currency>')
|
||||
@app.route('/rss/<handler_name>/<path:base_currency>/<path:quote_currency>')
|
||||
def rss_feed(handler_name, base_currency=None, quote_currency=None):
|
||||
"""RSS订阅源端点"""
|
||||
handler = handler_registry.get_handler(handler_name)
|
||||
|
||||
|
|
@ -56,8 +63,26 @@ def create_app(config_name='default'):
|
|||
return Response("Handler not found", status=404)
|
||||
|
||||
try:
|
||||
# 获取查询参数
|
||||
request_params = request.args.to_dict()
|
||||
# 构建请求参数
|
||||
request_params = {}
|
||||
|
||||
# 处理crypto handler的特殊逻辑
|
||||
if handler_name == 'crypto':
|
||||
if base_currency and quote_currency:
|
||||
# 将路径参数转换为pair格式
|
||||
pair = f"{base_currency.upper()}-{quote_currency.upper()}"
|
||||
request_params['pair'] = pair
|
||||
elif base_currency and not quote_currency:
|
||||
# 只有base_currency,使用默认quote_currency (通常是USDC)
|
||||
default_quote = 'USDC' # 你可以在config中配置这个默认值
|
||||
pair = f"{base_currency.upper()}-{default_quote}"
|
||||
request_params['pair'] = pair
|
||||
else:
|
||||
# 使用默认pair
|
||||
request_params['pair'] = app.config.get('DEFAULT_CRYPTO_PAIR', 'BTC-USDT')
|
||||
|
||||
# 合并其他查询参数(如果有的话)
|
||||
request_params.update(request.args.to_dict())
|
||||
|
||||
# 让处理器处理请求
|
||||
items = handler.handle(**request_params)
|
||||
|
|
@ -66,7 +91,7 @@ def create_app(config_name='default'):
|
|||
return Response("No data available", status=204)
|
||||
|
||||
if handler_name == 'crypto':
|
||||
motdTitle = request_params.get('pair', app.config['DEFAULT_CRYPTO_PAIR'])
|
||||
motdTitle = request_params.get('pair', app.config.get('DEFAULT_CRYPTO_PAIR', 'BTC-USDT'))
|
||||
motdTitle = motdTitle.replace('-', '/').upper()
|
||||
rss_xml = rss_generator.generate_rss(items, motdTitle=motdTitle)
|
||||
else:
|
||||
|
|
@ -92,6 +117,8 @@ def create_app(config_name='default'):
|
|||
|
||||
return app
|
||||
|
||||
app = create_app('production') # 生产环境使用production配置
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = create_app('development')
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
||||
Loading…
Add table
Add a link
Reference in a new issue