Alfred workflow:百度天气,修改更新图标显示:
下载:https://github.com/BobSte/weather-workflow
原始代码是php脚本,为其增加了一个取图片的函数以及一些图片。增加到weather.php
function getWeatherIcon($weather) { if ($weather == ‘icon‘) { return ‘cloudy2.png‘; } elseif ($weather == ‘unknown‘) { return ‘unknown.png‘; } $map = array(‘晴‘ => ‘sunny.png‘, ‘晴见多云‘ => ‘cloudy1.png‘, ‘晴转多云‘ => ‘cloudy3.png‘, ‘多云转晴‘ => ‘cloudy4.png‘, ‘阴转晴‘ => ‘cloudy4.png‘, ‘多云‘ => ‘cloudy5.png‘, ‘阴‘ => ‘overcast.png‘, ‘雨‘ => ‘light_rain.png‘, ‘阵雨‘ => ‘shower1.png‘, ‘小雨‘ => ‘shower1.png‘, ‘中雨‘ => ‘shower2.png‘, ‘大雨‘ => ‘shower3.png‘, ‘暴雨‘ => ‘shower3.png‘, ‘雷阵雨‘ => ‘tstorm1.png‘, ‘雷阵雨转中雨‘ => ‘tstorm2.png‘, ‘雷阵雨转大雨‘ => ‘tstorm3.png‘, ‘雷阵雨转暴雨‘ => ‘tstorm3.png‘, ‘雨夹雪‘ => ‘sleet.png‘, ‘冰雹‘ => ‘hail.png‘, ‘阵雪‘ => ‘snow1.png‘, ‘小雪‘ => ‘snow1.png‘, ‘中雪‘ => ‘snow2.png‘, ‘大雪‘ => ‘snow3.png‘, ‘暴雪‘ => ‘snow4.png‘, ‘大暴雪‘ => ‘snow5.png‘, ‘雾‘ => ‘mist.png‘, ‘大雾‘ => ‘fog.png‘, ‘霾‘ => ‘haze.png‘, ‘雾霾‘ => ‘haze.png‘, ); foreach ($map as $key => $value) { if ($weather == $key) { return $value; } } foreach (array_reverse($map) as $key => $value) { if (strstr($weather, $key)) { return $value; } } return ‘unknown.png‘; }
时间: 2024-10-27 18:25:14