最近迷上了用Rainmeter,官网https://www.rainmeter.net,

一款占用很小的桌面美化软件,了解了一下,后来百度到知乎老哥的文章

[桌面美化之 windows10 - Yoki] 传送门:https://zhuanlan.zhihu.com/p/102859469

下载到了口碑很好的 simple clean魔改版 - 无妄云烟@酷安 [点击下载,提取码:29r5]

原主题很炫酷,内容也很多,大约包含下面这些(图片来自原贴,若侵删)

包含内容

其中的天气插件已经失效,于是决定自己动手修复一下

接口分析

配置文件用webParse.dll的插件,从weather.com动态抓取对应的天气

原本的接口是在配置文件的32行

http://wxdata.weather.com/weather/local/#Location#?cc=*&unit=m&dayf=1

其中 #Location# 是存在皮肤目录的变量文件中的

但是访问这个接口,提示已经在2020年01月15日停止了…所以导致了失效

原来是更新了接口,我又试了试weacher.com现在使用的接口,原来他停止了城市代码

改用了每个城市的编码,比如我所在的西安市莲湖区,现在的访问地址是:

https://weather.com/zh-CN/weather/today/l/7e1166b88281aca3bfadc891829b5ac82206d9b7a85b0d84ae4874c0fba4cceb

看了看代码,其实就是可能被抓烦了,于是改了接口吧,查看原代码,找到对应的位置

更新规则

更新URL和对应的正则如下:

Url = http://weather.com/zh-CN/weather/today/l/xxxx 
RegExp="(?si).<span\sdata\-testid=\"TemperatureValue\".*?>(.*?)<span.*?<svg\sset=\"weather\"\sskycode=\"(.*?)\""

然后把对应的图标和文字位置标注好:

[MeasureWeatherTemp]
Measure=Plugin
Plugin=WebParser
Url=[MeasureWeather]
StringIndex=1

[MeasureWeatherIcon]
Measure=Plugin
Plugin=WebParser
Url=[MeasureWeather]
StringIndex=2

上面表示的是文字,下面的是图标,是正则对应的获取值的序号

当然,成品如下:

[Rainmeter]
Update=1000
Author=- HipHopium-
BackgroundMode=2
SolidColor=0,0,0,1


[Metadata]
Name = 简单天气
Version = 1.0.0
Author = Xafyi
License = 知识共享协议 署名-非商业性使用-以相同方式共享 4.0
Information=基于weather.com网站的天气修复版本,图标依然用eather.com的,自己用的时候,只要去weather.com搜索自己的地区,然后替换配置文件中的 URL后面的地址就可以用啦~


[Variables]
;通用文件夹中的变量
@include=#@#Variables.inc
@include2=#@#Language\#Language#.inc

;你本地的天气访问地址
weatherUrl = http://weather.com/zh-CN/weather/today/l/7e1166b88281aca3bfadc891829b5ac82206d9b7a85b0d84ae4874c0fba4cceb


;-------------------------------------------------------------
;-------------------------------------------------------------

[StyleWeather]
StringAlign=Center
FontColor=#FontColor#
FontFace=#FontFace#
AntiAlias=1

;-------------------------------------------------------------
;-------------------------------------------------------------

[MeasureWeather]
Measure=Plugin
Plugin=Plugins\WebParser.dll
;Url=http://wxdata.weather.com/weather/local/#Location#?cc=*&unit=#Unit#&dayf=1
Url=#weatherUrl#
;RegExp="(?siU).*<cc>.*<tmp>(.*)</tmp>.*<t>(.*)</t>.*<icon>(.*)</icon>"
RegExp="(?si).<span\sdata\-testid=\"TemperatureValue\".*?>(.*?)<span.*?<svg\sset=\"weather\"\sskycode=\"(.*?)\""
UpdateRate=1800

[MeasureWeatherTemp]
Measure=Plugin
Plugin=WebParser
Url=[MeasureWeather]
StringIndex=1

[MeasureWeatherIcon]
Measure=Plugin
Plugin=WebParser
Url=[MeasureWeather]
StringIndex=2

;-------------------------------------------------------------
;-------------------------------------------------------------

[WeatherIcon]
Meter=Image
MeasureName=MeasureWeatherIcon
ImagePath=#@#WeatherIcons
X=0
Y=0
W=100
H=100
AntiAlias=1
ImageTint=#FontColor#

成品下载

你如果觉得复杂,可以来这里拿,下载地址: https://github.com/afyi/rainmeter_weather

对了,有一个重要的事情,配置文件用记事本编辑,而且保存的时候要用ansi,不要用utf8,他不支持utf8…

嗯,ENJOY~