feat: 新增模块化Streamlit本地工具箱
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import streamlit as st
|
||||
from toolbox.tasks import start_task
|
||||
from .inputs import file_input
|
||||
from .task_panel import show_started, task_panel
|
||||
|
||||
|
||||
def render():
|
||||
st.title("楼宇数据查询")
|
||||
st.write("根据坐标 CSV 查询楼宇 WFS,返回后即时写入,保留未命中和失败记录。")
|
||||
source = file_input("坐标清单", "source/NRBuildingsPoint.csv", "csv", "building_csv")
|
||||
st.caption("输入列名必须包含:序号、经度、维度。输出采用 UTF-8 BOM,方便 Excel 打开。")
|
||||
with st.form("building_run"):
|
||||
c1, c2, c3 = st.columns(3)
|
||||
start = c1.number_input("起始数据行(不含表头)", 1, value=1)
|
||||
limit = c2.number_input("查询数量(0 表示剩余全部)", 0, value=1000)
|
||||
concurrency = c3.number_input("并发请求数", 1, 32, 8)
|
||||
encoding = st.selectbox("输入编码", ["gb18030", "utf-8-sig"])
|
||||
with st.expander("请求参数"):
|
||||
timeout = st.number_input("单次请求超时(秒)", 1, 300, 30)
|
||||
retries = st.number_input("失败重试次数", 0, 10, 2)
|
||||
interval = st.number_input("每协程请求间隔(秒)", 0.0, 60.0, 0.2, 0.1)
|
||||
override = st.checkbox("本次使用新的连接配置", value=False)
|
||||
st.caption("默认使用现有脚本中的本地连接配置;下方临时配置不会写入任务历史。")
|
||||
url = st.text_input("完整 WFS URL", type="password")
|
||||
cookies = st.text_input("Cookies", type="password")
|
||||
referer = st.text_input("Referer(可留空)")
|
||||
submitted = st.form_submit_button("开始查询", type="primary")
|
||||
if submitted:
|
||||
try:
|
||||
if not source:
|
||||
raise ValueError("请先导入坐标 CSV。")
|
||||
if override and (not url.startswith(("http://", "https://")) or not cookies.strip()):
|
||||
raise ValueError("请填写完整 WFS URL 和 Cookies。")
|
||||
params = {"INPUT_CSV": source, "INPUT_ENCODING": encoding, "START_ROW": start,
|
||||
"LIMIT": limit or None, "CONCURRENCY": concurrency, "TIMEOUT": timeout,
|
||||
"MAX_RETRIES": retries, "REQUEST_INTERVAL": interval}
|
||||
credentials = {"URL": url.strip(), "COOKIES": cookies.strip(), "REFERER": referer.strip()} if override else None
|
||||
show_started(start_task("buildings", params, credentials))
|
||||
except (OSError, ValueError, UnicodeError) as error:
|
||||
st.error(str(error))
|
||||
if st.session_state.get("last_task"):
|
||||
task_panel(st.session_state["last_task"])
|
||||
Reference in New Issue
Block a user