示例#1
0
function environment($city, $openweathermap = false)
{
    if (preg_match('/shi$/', $py = pinyin::encode($city))) {
        $py = substr($py, 0, strlen($py) - 3);
    }
    if ($openweathermap) {
        $citys = json_decode(file_get_contents('citys.json'), true);
        $weather = json_decode(file_get_contents('http://api.openweathermap.org/data/2.5/weather?id=' . $citys[$py] . '&units=metric&lang=zh_cn&APPID=' . APPID), true);
        $AQI = aqi($city);
        $weather['AQI'] = $AQI;
        return $weather;
    } else {
        return aqi($city);
    }
}
示例#2
0
                if ($aqi_data[1] == '日期' || preg_match('/^全/', $aqi_data[1])) {
                    continue;
                }
                if ($debug) {
                    print "{$city} - @" . $aqi_data[1] . "\n";
                }
                $entity['city'] = $city;
                $entity['date'] = $aqi_data[1];
                preg_match('/([0-9]+)<\\/td>$/', $rows[4], $aqi_data);
                if ($debug) {
                    print "AQI指数 " . $aqi_data[1] . " ";
                }
                $entity['AQI'] = $aqi_data[1];
                preg_match('/>(.*?)<\\/td>$/', $rows[5], $aqi_data);
                if ($debug) {
                    print $aqi_data[1] . " ";
                }
                $entity['quality'] = $aqi_data[1];
                preg_match('/>(.*?)<\\/td>$/', $rows[6], $aqi_data);
                if ($debug) {
                    print $aqi_data[1] . "\n\n";
                }
                $entity['pollutants'] = $aqi_data[1];
                array_push($result, $entity);
            }
        }
    }
    return $result;
}
echo json_encode(aqi('北京市', '2016-01-01', '2016-01-05'));