# 【审核】Webparserw: 天气皮肤变换 - Rainmeter官方文档 - 雨滴社区 - Powered by Discuz!
 找回密码
 点击注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 4070|回复: 1

【审核】Webparserw: 天气皮肤变换

[复制链接]

签到天数: 189 天

[LV.7]常住居民III

发表于 2014-3-13 22:49:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?点击注册

x
代码小白300问之一:我应该怎样转换天气文本,才能将网站上的天气信息提取出来并写到皮肤里去?
你弱爆了!首先找到你的measure或者相关的一堆measure(一般一个天气皮肤有3-5measure),它们都是用来天气转换的文本。它们可能会是这样的:
  1. [MeasureCurrentWeatherConditions]
  2. Measure=Plugin
  3. Plugin=WebParser
  4. Url=[MeasureYahooWeather]
  5. StringIndex=34
复制代码
请注意,天气皮肤通常配合一个主要measure进行工作,这个measure会将天气网站的RSS中的信息全部提取出来。然后再由后面单个的measure将具体的信息从前面提出来的信息中挑出来。因此你常会看到这种写法:
  1. Measure=Plugin
  2. Plugin=WebParser
  3. UpdateRate=600
  4. URL=http://weather.yahooapis.com/forecastrss?p=#Location#&u=#Unit#
  5. RegExp="(?siU)<title>.*- (.*)</title>.*<link>(.*)/\*(.*)</link>.*<description>(.*)</description>.*<language>(.*)</language>.*<lastBuildDate>(.*)</lastBuildDate>.*<yweather:location city="(.*)".*region="(.*)".*country="(.*)".*<yweather:units temperature="(.*)".*distance="(.*)".* pressure="(.*)".*speed="(.*)".*<yweather:wind chill="(.*)".*direction="(.*)".*speed="(.*)".*<yweather:atmosphere humidity="(.*)".* visibility="(.*)".*pressure="(.*)".* rising="(.*)".*<yweather:astronomy sunrise="(.*)".*sunset="(.*)".*<title>(.*)</title>.*<width>(.*)</width>.*<height>(.*)</height>.*<link>(.*)</link>.*<url>(.*)</url>.*<title>(.*)</title>.*<geo:lat>(.*)</geo:lat>.*<geo:long>(.*)</geo:long>.*<link>(.*)/\*(.*)</link>.*<pubDate>(.*)</pubDate>.*<yweather:condition text="(.*)".*code="(.*)".*temp="(.*)".*date="(.*)".*<img src="(.*)".*Current Conditions:</b><br />(.*)<BR />.*Forecast:</b><BR />(.*)<br />.*(.*)<br />.*<a href="(.*)/\*(.*)">.*provided by <a href="(.*)" >(.*)</a>.*<yweather:forecast day="(.*)".*date="(.*)".*low="(.*)".*high="(.*)".*text="(.*)".*code="(.*)".*<yweather:forecast day="(.*)".*date="(.*)".*low="(.*)".*high="(.*)".*text="(.*)".*code="(.*)".*"
复制代码
然后后面紧跟这么一些皮肤代码:
  1. [MeasureCurrentWeatherConditions]
  2. Measure=Plugin
  3. Plugin=WebParser
  4. Url=[MeasureYahooWeather]
  5. StringIndex=34
复制代码
如你所见,[MeasureCurrentWeatherConditions]这个measure用来得到[MeasureYahooWeather](这是我们的主RSSmeasure)这个节点中“URL=”的结果,然后具体要求为StringIndex=34,这个数组中的索引会返回一个值,这个值就是当前天气状况
Weather.com返回这个值之后,你需要将它们转换成自然语言。为了达到这个目的,你需要在"StringIndex=34"的后面增加一行(在我们的例子里):
  1. Substitute="Cloudy":"Bew&#246;lkt","Partly Cloudy":"Teilweise Bew&#246;lkt"
复制代码
一般格式如下:
Substitute="替代品":"被替代品","替代品":"被替代品"
这里的标点非常重要。"替代品""被替代品"都要用引号括起来。每组之间用逗号隔开。




好了完成了。在上面的例子中,当文字在一个节点中显示时,“Cloudy”将代替"Bew&#246;lkt"
代码小白300问之二——“当前天气文本的代码会从weather.com/ Yahoo Weather得到些什么,好让我用来转换?
下面是转换的数字和文字的对应:
  1. 0 – 雷暴
  2. 1 – 风雨交加
  3. 2 – 风雨交加
  4. 3 – 雷暴
  5. 4 – 雷暴
  6. 5 - 雨雪
  7. 6 – 雨夹雪??
  8. 7 – 冰雪
  9. 8 – 冻毛毛雨???
  10. 9 – 毛毛雨
  11. 10 – 冻雨
  12. 11 – 雷阵雨
  13. 11 – 阵雨
  14. 11 – 小雨
  15. 12 – 大雨
  16. 13 – 阵雪
  17. 14 – 小雪
  18. 15 – 中雪
  19. 16 – 大雪
  20. 17 – 暴雪
  21. 18 – 冰雹
  22. 19 – 浮尘
  23. 20 – 雾
  24. 21 – 薄雾
  25. 22 – 烟尘
  26. 23 – 风
  27. 24 – 风
  28. 25 – 严寒
  29. 26 – 多云
  30. 27 – 多云的夜间 (此处有不懂:the "Night" will not be included)
  31. 28 – 多云
  32. 29 – 部分云的夜间 (什么玩意儿??the "Night" will not be included)
  33. 30 – 中等量的云????
  34. 31 – 晴夜 (the "Night" will not be included)
  35. 32 – 阳光
  36. 33 – 晴
  37. 33 – 晴朗的晚上 (the "Night" will not be included)
  38. 34 – 晴
  39. 34 – 阳光
  40. 35 – 雷暴
  41. 36 – 炎热
  42. 37 – 少雷???
  43. 38 – 零散雷暴
  44. 39 – 零散下雨
  45. 40 – 大雨
  46. 41 – 零散下雪
  47. 42 – 大雪
  48. 43 – 风雪
  49. 44 – 部分晴朗的白天
  50. 45 – 零星阵雨的晚上 (the "Night" will not be included)
  51. 46 – 下雪的晚上
  52. 47 – 零星雷暴的晚上 (the "Night" will not be included)
复制代码
翻译者的提问:能不能把这些换成中国天气网的数字和对应?反正我们又不用外国的天气网。。。

回复

使用道具 举报

签到天数: 267 天

[LV.8]以坛为家I

发表于 2014-3-26 10:09:10 | 显示全部楼层
好东西...........
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点击注册

本版积分规则

快速回复 返回顶部 返回列表