diff --git a/.gitignore b/.gitignore index d8bc4873..025ac507 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .venv/ .idea/ +.vscode/ .cache/ node_modules/ data/ diff --git a/src/nonebot_plugins/liteyuki_weather/qw_api.py b/src/nonebot_plugins/liteyuki_weather/qw_api.py index 8f28cd91..ab47fad6 100644 --- a/src/nonebot_plugins/liteyuki_weather/qw_api.py +++ b/src/nonebot_plugins/liteyuki_weather/qw_api.py @@ -169,3 +169,20 @@ async def get_airquality( async with httpx.AsyncClient() as client: resp = await client.get(url, params=params) return resp.json() + +async def get_astronomy( + key: str, + location: str, + date: str, + dev: bool = get_memory_data("is_dev", True), +) -> dict: + url_path = f"v7/astronomy/sun?" + url = dev_url + url_path if dev else com_url + url_path + params = { + "key" : key, + "location" : location, + "date" : date, + } + async with httpx.AsyncClient() as client: + resp = await client.get(url, params=params) + return resp.json() \ No newline at end of file diff --git a/src/nonebot_plugins/liteyuki_weather/qweather.py b/src/nonebot_plugins/liteyuki_weather/qweather.py index 72d3aaee..0afaf931 100644 --- a/src/nonebot_plugins/liteyuki_weather/qweather.py +++ b/src/nonebot_plugins/liteyuki_weather/qweather.py @@ -1,3 +1,5 @@ +import datetime + from nonebot import require, on_endswith from nonebot.adapters import satori from nonebot.adapters.onebot.v11 import MessageSegment @@ -50,6 +52,9 @@ async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword: qw_lang = get_qw_lang(ulang.lang_code) key = get_config("weather_key") is_dev = get_memory_data("weather.is_dev", True) + extra_info = get_config("weather_extra_info") + attr = get_config("weather_attr") + user: User = user_db.where_one(User(), "user_id = ?", event_utils.get_user_id(event), default=User()) # params unit = user.profile.get("unit", "m") @@ -80,6 +85,7 @@ async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword: weather_daily = await get_weather_daily(key, location_data.id, lang=qw_lang, unit=unit, dev=is_dev) weather_hourly = await get_weather_hourly(key, location_data.id, lang=qw_lang, unit=unit, dev=is_dev) aqi = await get_airquality(key, location_data.id, lang=qw_lang, dev=is_dev) + weather_astronomy = await get_astronomy(key, location_data.id, date=datetime.datetime.now().strftime('%Y%m%d'), dev=is_dev) image = await template2image( template=get_path("templates/weather_now.html", abs_path=True), @@ -89,13 +95,17 @@ async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword: "unit": unit, "lang": ulang.lang_code, }, - "weatherNow" : weather_now, - "weatherDaily" : weather_daily, - "weatherHourly": weather_hourly, - "aqi" : aqi, - "location" : location_data.dump(), - "localization" : get_local_data(ulang.lang_code), - "is_dev": 1 if is_dev else 0 + "weatherNow" : weather_now, + "weatherDaily" : weather_daily, + "weatherHourly" : weather_hourly, + "aqi" : aqi, + "location" : location_data.dump(), + "localization" : get_local_data(ulang.lang_code), + "weatherAstronomy" : weather_astronomy, + "is_dev" : 1 if is_dev else 0, + "extra_info" : extra_info, + "attr" : attr + } }, ) diff --git a/src/resources/liteyuki_weather/templates/css/weather_now.css b/src/resources/liteyuki_weather/templates/css/weather_now.css index f25f4ddf..608c93bb 100644 --- a/src/resources/liteyuki_weather/templates/css/weather_now.css +++ b/src/resources/liteyuki_weather/templates/css/weather_now.css @@ -14,7 +14,7 @@ } .icon { -/* icon 类img阴影*/ + /* icon 类img阴影*/ filter: drop-shadow(1px 1px 10px #00000044); } @@ -118,7 +118,7 @@ padding: 20px 10px; } -.hourly-icon{ +.hourly-icon { width: 80%; margin-bottom: 20px; } @@ -167,18 +167,74 @@ height: 80px; } -.daily-weather{ +.daily-weather { position: absolute; left: 30%; } -.daily-temperature{ +.daily-temperature { position: absolute; left: 83%; } -.daily-day, .daily-weather, .daily-temperature { +.daily-day, +.daily-weather, +.daily-temperature { text-align: center; color: var(--main-text-color); font-size: 30px; +} + +.ad-box { + margin-bottom: 20px; + + img { + border-radius: 60px; + } +} + +.sub-info { + display: grid; + grid-template-columns: repeat(2, 1fr); + gap: 10px; + color: var(--main-text-color); + font-size: 40px; + align-items: center; +} + +.sub-info>div { + display: flex; + align-items: center; + gap: 5px; + overflow: hidden; + padding-left: 20px; + + /*要问就问html调svg为什么那么不友好*/ + img { + transform: translateY(-80px); + /*自定义颜色*/ + filter: drop-shadow(var(--main-text-color) 0 80px); + /*自定义透明度*/ + opacity: 1; + padding-right: 10px; + } +} + +.attribution-box { + margin: 0; + position: relative; + display: flex; + justify-content: center; + + #attribution-info { + backdrop-filter: blur(10px); + padding: 0 5px 0; + background-color: rgba(0, 0, 0, 0.5); + font-size: 25px; + justify-content: space-between; + display: inline-flex; + word-wrap: break-word; + color: var(--sub-text-color); + text-align: center; + } } \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/ad_default/ad_default.png b/src/resources/liteyuki_weather/templates/img/ad_default/ad_default.png new file mode 100644 index 00000000..120df813 Binary files /dev/null and b/src/resources/liteyuki_weather/templates/img/ad_default/ad_default.png differ diff --git a/src/resources/liteyuki_weather/templates/img/svg/cloud.svg b/src/resources/liteyuki_weather/templates/img/svg/cloud.svg new file mode 100644 index 00000000..1d48c549 --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/cloud.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/feelsLike.svg b/src/resources/liteyuki_weather/templates/img/svg/feelsLike.svg new file mode 100644 index 00000000..fb18cb13 --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/feelsLike.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/humidity.svg b/src/resources/liteyuki_weather/templates/img/svg/humidity.svg new file mode 100644 index 00000000..e0343850 --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/humidity.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/precip.svg b/src/resources/liteyuki_weather/templates/img/svg/precip.svg new file mode 100644 index 00000000..f0e1d167 --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/precip.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/pressure.svg b/src/resources/liteyuki_weather/templates/img/svg/pressure.svg new file mode 100644 index 00000000..d06fe8ef --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/pressure.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/sunrise.svg b/src/resources/liteyuki_weather/templates/img/svg/sunrise.svg new file mode 100644 index 00000000..ae6ef2f6 --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/sunrise.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/sunset.svg b/src/resources/liteyuki_weather/templates/img/svg/sunset.svg new file mode 100644 index 00000000..b8c096fd --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/sunset.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/vis.svg b/src/resources/liteyuki_weather/templates/img/svg/vis.svg new file mode 100644 index 00000000..c67c0dd6 --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/vis.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/windDirect.svg b/src/resources/liteyuki_weather/templates/img/svg/windDirect.svg new file mode 100644 index 00000000..f3ab84f5 --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/windDirect.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/img/svg/windVelocity.svg b/src/resources/liteyuki_weather/templates/img/svg/windVelocity.svg new file mode 100644 index 00000000..03019797 --- /dev/null +++ b/src/resources/liteyuki_weather/templates/img/svg/windVelocity.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/resources/liteyuki_weather/templates/js/weather_now.js b/src/resources/liteyuki_weather/templates/js/weather_now.js index 78c1c039..b8af944f 100644 --- a/src/resources/liteyuki_weather/templates/js/weather_now.js +++ b/src/resources/liteyuki_weather/templates/js/weather_now.js @@ -23,7 +23,10 @@ let weatherNow = data["weatherNow"] let weatherDaily = data["weatherDaily"] let weatherHourly = data["weatherHourly"] let aqi = data["aqi"] +let weatherAstronomy = data["weatherAstronomy"] let is_dev = data["is_dev"] +let attr = data["attr"] + let locationData = data["location"] @@ -35,10 +38,10 @@ if ("aqi" in aqi) { if (item["defaultLocalAqi"]) { document.getElementById("aqi-data").innerText = "AQI " + item["valueDisplay"] + " " + item["category"] // 将(255,255,255)这种格式的颜色设置给css - if(is_dev == 1){ + if (is_dev) { //开发版 document.getElementById("aqi-dot").style.backgroundColor = "rgb(" + item["color"]['red'] + "," + item["color"]['green'] + "," + item["color"]['blue'] + "," + item["color"]['alpha'] + ")" - }else{ + } else { //正式版 document.getElementById("aqi-dot").style.backgroundColor = "rgb(" + item["color"] + ")" } @@ -65,6 +68,33 @@ for (let id in templates) { document.getElementById(id).innerText = templates[id] } + +subtemplates = { + "now-windDirect": weatherNow["now"]["windDir"] + " " + weatherNow["now"]["wind360"] + "°", + "now-windVelocity": "风矢 " + weatherNow["now"]["windScale"] + "级 " + weatherNow["now"]["windSpeed"] + "km/h", + "now-humidity": "湿度 " + weatherNow["now"]["humidity"] + "%", + "now-feelsLike": "体感 " + weatherNow["now"]["feelsLike"] + "°C", + "now-precip": "降水 " + weatherNow["now"]["precip"] + "mm", + "now-pressure": "气压 " + weatherNow["now"]["pressure"] + "hPa", + "vis": "能见 " + weatherNow["now"]["vis"] + "km", + "cloud ": "云量 " + (weatherNow["now"]["cloud"] == "" ? "无数据" : (weatherNow["now"]["cloud"] + "%")), + "astronomy-sunrise": "日出 " + get_time_hour(weatherAstronomy["sunrise"]), + "astronomy-sunset": "日落 " + get_time_hour(weatherAstronomy["sunset"]) +} + +let subItemDivTemplate = document.importNode(document.getElementById("sub-info-template").content, true); + +let subItemDiv = subItemDivTemplate.querySelector(".sub-info"); + +for (let id in subtemplates) { + let element = subItemDiv.querySelector(`#${id}`); + if (element) { + element.innerText = subtemplates[id]; + } +} + +document.getElementById('sub-info').appendChild(subItemDiv); + let maxHourlyItem = 8 let percentWidth = 1 / (maxHourlyItem * 1.5) * 100 let hourlyStep = 2 // n小时一个数据 @@ -126,7 +156,12 @@ weatherDaily['daily'].forEach( ) function get_time_hour(fxTime) { -// fxTime 2024-05-03T02:00+/-08:00' + // fxTime 2024-05-03T02:00+/-08:00' fxTime = fxTime.replace("-", "+") return fxTime.split("T")[1].split("+")[0] } + +let attrinfo = document.getElementById('attribution-info'); +if (!is_dev & !attr) attrinfo.parentElement.style.display = "none" + +attrinfo.innerText = is_dev ? "Weather Service Drived by QWeather" : (attr ? attr : "Weather Service Drived by QWeather") diff --git a/src/resources/liteyuki_weather/templates/weather_now.html b/src/resources/liteyuki_weather/templates/weather_now.html index ec360876..8a65bffc 100644 --- a/src/resources/liteyuki_weather/templates/weather_now.html +++ b/src/resources/liteyuki_weather/templates/weather_now.html @@ -1,76 +1,151 @@ + Liteyuki Status + + - + - - - -
{{ data | tojson }}
-
-
-
2045-01-12 22:22:22
-
枫丹 白露 白露区
-
白露区
-
-
-
- WeatherIcon -
-
-
-
- 90° -
-
- 10°~90° -
+ + + + +
{{ data | tojson }}
+
+
+
2045-01-12 22:22:22
+
枫丹 白露 白露区
+
白露区
+
+
+
+ WeatherIcon +
+
+
+
+ 90° +
+
+ 10°~90° +
+
+
+ 示例天气 +
+
+
+
+
+
AQI 114 优
+
+
+
+
+
+ + + + + +
+
+
+ + - - \ No newline at end of file