Merge pull request #1243 from xinnan-tech/py_weather_fix

Py weather fix
This commit is contained in:
hrz
2025-05-14 20:30:56 +08:00
committed by GitHub
3 changed files with 22 additions and 10 deletions
@@ -49,7 +49,7 @@
<div class="fields-container"> <div class="fields-container">
<el-table :data="form.fields" style="width: 100%;" border size="medium" :key="tableKey"> <el-table :data="form.fields" style="width: 100%;" border size="medium" :key="tableKey">
<el-table-column label="选择" align="center" width="120"> <el-table-column label="选择" align="center" width="50">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox v-model="scope.row.selected" @change="handleFieldSelectChange"></el-checkbox> <el-checkbox v-model="scope.row.selected" @change="handleFieldSelectChange"></el-checkbox>
</template> </template>
@@ -60,7 +60,7 @@
<el-input v-model="scope.row.key" placeholder="字段key"></el-input> <el-input v-model="scope.row.key" placeholder="字段key"></el-input>
</template> </template>
<template v-else> <template v-else>
{{ scope.row.key || '-' }} {{ scope.row.key }}
</template> </template>
</template> </template>
</el-table-column> </el-table-column>
@@ -70,7 +70,7 @@
<el-input v-model="scope.row.label" placeholder="字段标签"></el-input> <el-input v-model="scope.row.label" placeholder="字段标签"></el-input>
</template> </template>
<template v-else> <template v-else>
{{ scope.row.label || '-' }} {{ scope.row.label }}
</template> </template>
</template> </template>
</el-table-column> </el-table-column>
@@ -89,6 +89,16 @@
</template> </template>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="默认值">
<template slot-scope="scope">
<template v-if="scope.row.editing">
<el-input v-model="scope.row.default_value" placeholder="请输入默认值"></el-input>
</template>
<template v-else>
{{ scope.row.default_value }}
</template>
</template>
</el-table-column>
<el-table-column label="操作" width="150" align="center"> <el-table-column label="操作" width="150" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button v-if="!scope.row.editing" type="primary" size="mini" @click="startEditing(scope.row)"> <el-button v-if="!scope.row.editing" type="primary" size="mini" @click="startEditing(scope.row)">
@@ -148,7 +158,7 @@ export default {
'boolean': '布尔值', 'boolean': '布尔值',
'dict': '字典' 'dict': '字典'
}; };
return typeMap[type] || '-'; return typeMap[type];
}, },
startEditing(row) { startEditing(row) {
@@ -205,6 +215,7 @@ export default {
key: '', key: '',
label: '', label: '',
type: 'string', type: 'string',
default_value: '',
selected: false, selected: false,
editing: true editing: true
}); });
+2 -1
View File
@@ -101,7 +101,8 @@ plugins:
# 这个密钥是项目共用的key,用多了可能会被限制 # 这个密钥是项目共用的key,用多了可能会被限制
# 想稳定一点就自行申请替换,每天有1000次免费调用 # 想稳定一点就自行申请替换,每天有1000次免费调用
# 申请地址:https://console.qweather.com/#/apps/create-key/over # 申请地址:https://console.qweather.com/#/apps/create-key/over
get_weather: { "api_key": "a861d0d5e7bf4ee1a83d9a9e4f96d4da", "default_location": "广州" } # 申请后通过这个链接可以找到自己的apihosthttps://console.qweather.com/setting?lang=zh
get_weather: {"api_host":"mj7p3y7naa.re.qweatherapi.com", "api_key": "a861d0d5e7bf4ee1a83d9a9e4f96d4da", "default_location": "广州" }
# 获取新闻插件的配置,这里根据需要的新闻类型传入对应的url链接,默认支持社会、科技、财经新闻 # 获取新闻插件的配置,这里根据需要的新闻类型传入对应的url链接,默认支持社会、科技、财经新闻
# 更多类型的新闻列表查看 https://www.chinanews.com.cn/rss/ # 更多类型的新闻列表查看 https://www.chinanews.com.cn/rss/
get_news_from_chinanews: get_news_from_chinanews:
@@ -107,8 +107,8 @@ WEATHER_CODE_MAP = {
} }
def fetch_city_info(location, api_key): def fetch_city_info(location, api_key, api_host):
url = f"https://geoapi.qweather.com/v2/city/lookup?key={api_key}&location={location}&lang=zh" url = f"https://{api_host}/geo/v2/city/lookup?key={api_key}&location={location}&lang=zh"
response = requests.get(url, headers=HEADERS).json() response = requests.get(url, headers=HEADERS).json()
return response.get("location", [])[0] if response.get("location") else None return response.get("location", [])[0] if response.get("location") else None
@@ -151,7 +151,8 @@ def parse_weather_info(soup):
@register_function("get_weather", GET_WEATHER_FUNCTION_DESC, ToolType.SYSTEM_CTL) @register_function("get_weather", GET_WEATHER_FUNCTION_DESC, ToolType.SYSTEM_CTL)
def get_weather(conn, location: str = None, lang: str = "zh_CN"): def get_weather(conn, location: str = None, lang: str = "zh_CN"):
api_key = conn.config["plugins"]["get_weather"]["api_key"] api_host = conn.config["plugins"]["get_weather"].get("api_host", "mj7p3y7naa.re.qweatherapi.com")
api_key = conn.config["plugins"]["get_weather"].get("api_key", "a861d0d5e7bf4ee1a83d9a9e4f96d4da")
default_location = conn.config["plugins"]["get_weather"]["default_location"] default_location = conn.config["plugins"]["get_weather"]["default_location"]
client_ip = conn.client_ip client_ip = conn.client_ip
# 优先使用用户提供的location参数 # 优先使用用户提供的location参数
@@ -164,8 +165,7 @@ def get_weather(conn, location: str = None, lang: str = "zh_CN"):
else: else:
# 若IP解析失败或无IP,使用默认位置 # 若IP解析失败或无IP,使用默认位置
location = default_location location = default_location
city_info = fetch_city_info(location, api_key, api_host)
city_info = fetch_city_info(location, api_key)
if not city_info: if not city_info:
return ActionResponse( return ActionResponse(
Action.REQLLM, f"未找到相关的城市: {location},请确认地点是否正确", None Action.REQLLM, f"未找到相关的城市: {location},请确认地点是否正确", None