From 2fce8ee8809fc1d0cdb1a427b36bd4d20d2e1427 Mon Sep 17 00:00:00 2001 From: kexue Date: Sun, 18 Feb 2024 11:35:39 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_heweather/config.py | 12 +++++++----- nonebot_plugin_heweather/weather_data.py | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/nonebot_plugin_heweather/config.py b/nonebot_plugin_heweather/config.py index 32aa2b2..ec4229d 100644 --- a/nonebot_plugin_heweather/config.py +++ b/nonebot_plugin_heweather/config.py @@ -1,3 +1,5 @@ +from typing import Optional + from nonebot import get_plugin_config from pydantic import BaseModel, Field @@ -5,11 +7,11 @@ class Config(BaseModel): - qweather_apikey: str = Field(default=None) - qweather_apitype: str = Field(default=None) - qweather_hourlytype: HourlyType = Field(default=HourlyType.current_12h) - qweather_forecase_days: int = Field(default=3) - debug: bool = Field(default=False) + qweather_apikey: Optional[str] = Field(default=None) + qweather_apitype: Optional[str] = Field(default=None) + qweather_hourlytype: Optional[HourlyType] = Field(default=HourlyType.current_12h) + qweather_forecase_days: Optional[int] = Field(default=3) + debug: Optional[bool] = Field(default=False) plugin_config: Config = get_plugin_config(Config) diff --git a/nonebot_plugin_heweather/weather_data.py b/nonebot_plugin_heweather/weather_data.py index 37bc495..2253cd3 100644 --- a/nonebot_plugin_heweather/weather_data.py +++ b/nonebot_plugin_heweather/weather_data.py @@ -46,8 +46,9 @@ def __url__(self): def _forecast_days(self): self.forecast_days = QWEATHER_FORECASE_DAYS - if self.api_type == 0 and not (3 <= self.forecast_days <= 7): - raise ConfigError("api_type = 0 免费订阅 预报天数必须 3<= x <=7") + if self.forecast_days: + if self.api_type == 0 and not (3 <= self.forecast_days <= 7): + raise ConfigError("api_type = 0 免费订阅 预报天数必须 3<= x <=7") def __init__(self, city_name: str, api_key: str, api_type: Union[int, str] = 0): self.city_name = city_name