Created
April 21, 2012 19:13
-
-
Save ajitam/2439161 to your computer and use it in GitHub Desktop.
Get weather from ARSO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('Europe/Belgrade'); | |
function align($string, $width) { | |
$spaces = 0; | |
$spaces = $width - strlen($string); | |
for($i = 0; $i < $spaces; $i++) { | |
$result .= " "; | |
} | |
$result .= $string; | |
return $result; | |
} | |
// Get curen temp and humidity | |
echo "@current --\n"; | |
$places = array( | |
'Ilirska Bistrica' => 'http://meteo.arso.gov.si/uploads/probase/www/observ/surface/text/sl/observationAms_ILIRS-BIS_latest.xml' | |
,'Postojna' => 'http://meteo.arso.gov.si/uploads/probase/www/observ/surface/text/sl/observationAms_POSTOJNA_latest.xml' | |
,'Ljubljana' => 'http://meteo.arso.gov.si/uploads/probase/www/observ/surface/text/sl/observationAms_LJUBL-ANA_BEZIGRAD_latest.xml' | |
); | |
foreach($places as $key => $place) { | |
$www_data = file_get_contents($place); | |
$elements = new SimpleXMLElement($www_data); | |
foreach ($elements->metData as $key => $element) { | |
echo $element->domain_longTitle . align($element->t, 7) . " " . $element->rhavg . "%\n"; | |
} | |
} | |
echo "\n"; | |
//print_r($elements); | |
// Forecast | |
/* | |
url: http://meteo.arso.gov.si/uploads/meteo/help/sl/xml_service.pdf | |
clear 000 | |
mostClear .0. | |
slightCloudy -0- | |
partCloudy -o- | |
modCloudy +o+ | |
prevCloudy #o# | |
overcast ### | |
FG --- | |
*/ | |
$weather_icon_array = array( | |
'clear' => '000' | |
,'mostClear' => '.0.' | |
,'slightCloudy' => '-0-' | |
,'partCloudy' => '-o-' | |
,'modCloudy' => '+o+' | |
,'prevCloudy' => '#o#' | |
,'overcast' => '###' | |
,'FG' => '---' | |
); | |
/* | |
FG megla - -- --- | |
DZ rosenje ' '' ''' | |
FZDZ rosenje, ki zmrzuje __' _'_ _'' | |
RA dež / // /// | |
FZRA dež, ki zmrzuje _/ _/_ _// | |
RASN dež s snegom * / /* * // | |
SN sneg * ** *** | |
SHRA ploha dežja /' '/' /'/ | |
SHRASN ploha dežja s snegom /*' /*' /*' | |
SHSN snežna ploha * ** *** | |
SHGR ploha sodre .' .'. ..' | |
TS nevihta | || ||| | |
TSRA nevihta z dežjem |/ |// ↓// | |
TSRASN nevihta z dežjem in snegom |/* |/* ↓/* | |
TSSN nevihta s sneženjem *| **| **↓ | |
TSGR nevihta s točo .| ..| ..↓ | |
*/ | |
$weather_extra_array = array( | |
'FG' => array( | |
'light' => " -" | |
,'mod' => " --" | |
,'heavy' => "---" | |
) | |
,'DZ' => array( | |
'light' => " '" | |
,'mod' => " ''" | |
,'heavy' => "'''" | |
) | |
,'FZDZ' => array( | |
'light' => " _'" | |
,'mod' => "__'" | |
,'heavy' => "_''" | |
) | |
,'RA' => array( | |
'light' => " /" | |
,'mod' => " //" | |
,'heavy' => "///" | |
) | |
,'FZRA' => array( | |
'light' => " _/" | |
,'mod' => "__/" | |
,'heavy' => "_//" | |
) | |
,'RASN' => array( | |
'light' => " */" | |
,'mod' => " /*" | |
,'heavy' => "*//" | |
) | |
,'SN' => array( | |
'light' => " *" | |
,'mod' => " **" | |
,'heavy' => "***" | |
) | |
,'SHRA' => array( | |
'light' => " /'" | |
,'mod' => "'/'" | |
,'heavy' => "//'" | |
) | |
,'SHRASN'=> array( | |
'light' => "/*" | |
,'mod' => "/*'" | |
,'heavy' => "/*'" | |
) | |
,'SHSN' => array( | |
'light' => " *" | |
,'mod' => " **" | |
,'heavy' => "***" | |
) | |
,'SHGR' => array( | |
'light' => " ." | |
,'mod' => " .." | |
,'heavy' => "..." | |
) | |
,'TS' => array( | |
'light' => " |" | |
,'mod' => " ||" | |
,'heavy' => "|||" | |
) | |
,'TSRA' => array( | |
'light' => " |/" | |
,'mod' => "|//" | |
,'heavy' => "↓//" | |
) | |
,'TSRASN'=> array( | |
'light' => "|/*" | |
,'mod' => "|/*" | |
,'heavy' => "↓/*" | |
) | |
,'TSSN' => array( | |
'light' => " *|" | |
,'mod' => "**|" | |
,'heavy' => "**↓" | |
) | |
,'TSGR' => array( | |
'light' => " .|" | |
,'mod' => "..|" | |
,'heavy' => "..↓" | |
) | |
); | |
$urls = array( | |
'@ljubljana #' => 'http://meteo.arso.gov.si/uploads/probase/www/fproduct/text/sl/forecast_SI_OSREDNJESLOVENSKA_latest.xml' | |
,'@ljubljana 0' => 'http://meteo.arso.gov.si/uploads/probase/www/fproduct/text/sl/fcast_SLOVENIA_MIDDLE_latest.xml' | |
,'@podgrad #' => 'http://meteo.arso.gov.si/uploads/probase/www/fproduct/text/sl/forecast_SI_NOTRANJSKO-KRASKA_latest.xml' | |
,'@podgrad 0' => 'http://meteo.arso.gov.si/uploads/probase/www/fproduct/text/sl/fcast_SLOVENIA_SOUTH-WEST_latest.xml' | |
); | |
foreach($urls as $type => $url) { | |
echo $type." --\n"; | |
$www_data = file_get_contents($url); | |
$elements = new SimpleXMLElement($www_data); | |
$day = 0; | |
foreach ($elements->metData as $key => $element) { | |
$icon = (string)$element->nn_icon; | |
$weather_icon = $weather_icon_array[$icon]; | |
if ($element->wwsyn_icon != '') { | |
$icon = (string)$element->wwsyn_icon; | |
$level = (string)$element->rr_decodeText; | |
$weather_extra = $weather_extra_array[$icon][$level]; | |
} else { $weather_extra = ' '; } | |
// Get first letter of the day | |
$day_code = (string)$element->valid; | |
$day_name = strtolower(date('D', strtotime($day_code))); | |
$min_temp = "/"; | |
if ($element->tnsyn_degreesC) { | |
$min_temp = $element->tnsyn_degreesC; | |
} else { | |
$min_temp = $element->tn_degreesC; | |
} | |
$max_temp = "/"; | |
if ($element->txsyn_degreesC) { | |
$max_temp = $element->txsyn_degreesC; | |
} else { | |
$max_temp = $element->tx_degreesC; | |
} | |
echo "+ " . $day . " (" . $day_name . ") ☛ ↓ " . align($min_temp, 2) . " | ↑ " . align($max_temp, 2) . " | " . align($weather_icon, 3) . " | " . align($weather_extra, 3) ." |\n"; | |
$day++; | |
} | |
echo "\n"; | |
} | |
//print_r($elements); | |
//print_r($elements->metData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment