public function wunderground() { global $LAT, $LON, $APPID_WG; $xml = NULL; $kurikaeshi = 10; $sleeptime = 30; for ($count = 0; $count < $kurikaeshi; $count++) { $req2 = "http://api.wunderground.com/api/" . $APPID_WG . "/conditions/lang:JP/q/" . $LAT . "," . $LON . ".xml"; $xml = @simplexml_load_file($req2); if ($xml) { // var_dump($xml); $wg = array(); $wg["city"] = $xml->current_observation->display_location->city; echo "Wunderground City = " . $wg["city"] . "\n"; $wg["temp_now2"] = round((double) (5 / 9) * ($xml->current_observation->temp_f - 32), 1); $wg["temp_now_f"] = $xml->current_observation->temp_f; $wg["humidity_now2"] = str_replace("%", "%", $xml->current_observation->relative_humidity); $wg["windspeed_now2"] = round(0.44704 * (double) $xml->current_observation->wind_mph, 1); $wg["pressure_now2"] = round((double) $xml->current_observation->pressure_in * 33.8639, 1); $wg["kazamuki2"] = $this->ryusWehatherWindDigree($xml->current_observation->wind_degrees); $wg["kazamuki_degrees"] = $xml->current_observation->wind_degrees; $wg["feelslike"] = round((double) (5 / 9) * ($xml->current_observation->feelslike_f - 32), 1); $wg["fukai"] = round((double) (0.8100000000000001 * $wg["temp_now2"] + 0.01 * $wg["humidity_now2"] * (0.99 * $wg["temp_now2"] - 14.3) + 46.3), 1); $wg["weather"] = $this->trans_condition($xml->current_observation->weather); if ($wg["weather"] == "") { $owm = $this->openweathermap(); $wg["weather"] = $owm["description"]; } $wg["icon_url"] = $xml->current_observation->icon_url; $wg["humidity_now2_X"] = $xml->current_observation->relative_humidity; $wg["windspeed_now2_X"] = $xml->current_observation->wind_mph; $wg["pressure_now2_X"] = $xml->current_observation->pressure_in; $wg["feelslike_X"] = $xml->current_observation->feelslike_f; if (strlen($wg["humidity_now2_X"]) == 0) { $wg["humidity_now2"] = "?"; $wg["fukai"] = "?"; } if (strlen($wg["windspeed_now2_X"]) == 0) { $wg["windspeed_now2"] = "?"; } if (strlen($wg["pressure_now2_X"]) == 0) { $wg["pressure_now2"] = "?"; } if (strlen($wg["feelslike_X"]) == 0) { $wg["feelslike"] = "?"; } if (strlen($wg["temp_now_f"]) == 0) { $wg["temp_now2"] = "?"; $wg["fukai"] = "?"; } if (strlen($wg["kazamuki2"]) == 0) { $wg["kazamuki2"] = "?"; } if (strlen($wg["weather"]) == 0) { $wg["weather"] = "?"; } $filename = strrchr($wg["icon_url"], "/"); $filename = substr($filename, 1); $wg_icon = str_replace('nt_', '', $filename); if ($wg_icon == ".gif") { $wg["icon_url"] = "http://linuxparadise.moe.hm/wp-content/uploads/2016/10/question_blue.jpg"; $wg["icon_url"] = NULL; return $wg; } $SunMoon = new Moon_Class(); $Sun = $SunMoon->SunHatena(); if (!$Sun) { $wg_icon = "nt_" . $wg_icon; } $wg["icon_url"] = $this->trans_weather_icon_7("http://icons.wxug.com/i/c/k/" . $wg_icon); return $wg; } else { sleep($sleeptime); } } return NULL; }
$day = day_diff(date('Y-m-d'), $FM[0] . "-" . $FM[1] . "-" . $FM[2]); if ($day < 0) { $day = "--"; } $pref->appendChild($dom->createElement('Wait', $day)); $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'NewMoon'); $pref->appendChild($dom->createElement('Date', $NM[0] . "-" . $NM[1] . "-" . $NM[2])); $pref->appendChild($dom->createElement('Time', $NM[3] . ":" . $NM[4] . ":" . $NM[5])); $day = day_diff(date('Y-m-d'), $NM[0] . "-" . $NM[1] . "-" . $NM[2]); if ($day < 0) { $day = "--"; } $pref->appendChild($dom->createElement('Wait', $day)); $weekjp = array('日', '月', '火', '水', '木', '金', '土'); $weekno = date('w'); $week_X = "〔" . $weekjp[$weekno] . "〕"; $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'DATE'); $pref->appendChild($dom->createElement('time', date("Y年m月j日") . $week_X . date(" H時i分"))); $pref->appendChild($dom->createElement('time_ampm', date("Y年m月j日") . $week_X . date(" A h:i"))); $dom->formatOutput = true; $save_file = "/etc/zabbix/externalscripts/F_N_Moon.xml"; $dom->save($save_file); } //----------------------------------------------------------------------- $MM = new Moon_Class(); list($NM, $FM) = $MM->moon_phase_time(); echo "新月=" . $NM[0] . "-" . $NM[1] . "-" . $NM[2] . " " . $NM[3] . ":" . $NM[4] . ":" . $NM[5] . "," . $NM[6] . "\n"; echo "満月=" . $FM[0] . "-" . $FM[1] . "-" . $FM[2] . " " . $FM[3] . ":" . $FM[4] . ":" . $FM[5] . "," . $FM[6] . "\n"; file_write();
return 1; } elseif ($argv[3] == "CHECK") { if ($timea["M10"] == date('i') && $timea["H"] == date('H')) { echo "ツイートします。\n"; return 1; } else { echo "ツイートしません(2)。\n"; return 0; } } else { echo "ツイートしません(1)。\n"; return 0; } } //-------------------------------------------------------------------------- $MM = new Moon_Class(); $TT = new Twitter_Class(); $SunMoon = $MM->StoreSunMoon(); $Moon = $MM->StoreFullNewMoon(); if (date("H") <= 12) { $Answer = timecheck($SunMoon["sunrise_hm"]); } else { $Answer = timecheck($SunMoon["sunset_hm"]); } if (!$Answer) { exit; } $status = make_message(); //------------------------------------------------------------------------- $twitter = new tmhOauth(array("consumer_key" => $consumer_key, "consumer_secret" => $consumer_secret, "token" => $token, "secret" => $secret, "curl_ssl_verifypeer" => false)); $c = 0;
$pref->appendChild($dom->createElement('moonset_hm', sprintf("%05s", $ohakon["moonset_hm"]))); $pref->appendChild($dom->createElement('moon_age', $ohakon["moon_age"])); $pref->appendChild($dom->createElement('moon_phase', $ohakon["moon_phase"])); $pref->appendChild($dom->createElement('fullmoon_wait', $ohakon["fullmoon_wait"])); $pref->appendChild($dom->createElement('newmoon_wait', $ohakon["newmoon_wait"])); $pref->appendChild($dom->createElement('tide_name', $tide_name)); $weekjp = array('日', '月', '火', '水', '木', '金', '土'); $weekno = date('w'); $week_X = "〔" . $weekjp[$weekno] . "〕"; $pref = $prefs->appendChild($dom->createElement('pref')); $pref->setAttribute('code', 'DATE'); $pref->appendChild($dom->createElement('time', date("Y年m月j日") . $week_X . date(" H時i分"))); $pref->appendChild($dom->createElement('time_ampm', date("Y年m月j日") . $week_X . date(" A h:i"))); $dom->formatOutput = true; $save_file = "/etc/zabbix/externalscripts/" . $OUT_FILE; $dom->save($save_file); } if ($argc != 4) { $LAT = "35.6811856"; $LON = "139.7638611"; $OUT_FILE = "sunmoon_prefs.xml"; } else { $LAT = $argv[1]; $LON = $argv[2]; $OUT_FILE = $argv[3]; } echo "LAT=" . $LAT . "\nLON=" . $LON . "\nOUT_FILE=" . $OUT_FILE . "\nで出力します。\n"; $SunMoon = new Moon_Class(); $ohakon = $SunMoon->ohakon($LAT, $LON); $tide_name = $SunMoon->shiomei($ohakon["moon_age"]); file_write();