You are here

function _weather_es_get_td_info in Weather_es 6

Same name and namespace in other branches
  1. 5 weather_es_parser.inc \_weather_es_get_td_info()

Get the td info: rain probability, tmax, tmin...

File

./weather_es_parser.inc, line 38
Gets the data from the AEMET web

Code

function _weather_es_get_td_info($captured_td, $ampm) {
  $lon = sizeof($captured_td);

  // Sky state
  if ($ampm == 'am') {
    $end = 9;
  }
  else {
    $end = 8;
  }

  // In images
  for ($i = 0; $i <= $end; $i++) {
    preg_match('/[0-9]{2}.gif/', $captured_td[$i], $data);
    $data_lon = strlen($data[0]);
    $sky_img[] = substr($data[0], 0, $data_lon - 4);
  }

  // In text
  for ($i = 0; $i <= $end; $i++) {
    preg_match('/alt=".+"/', $captured_td[$i], $data);
    $data_lon = strlen($data[0]);
    $sky_txt[] = substr($data[0], 5, $data_lon - 6);
  }

  // Begining of wind direction
  $beg = $end + 1;
  for ($i = $beg; $i <= $lon; $i++) {
    if (preg_match('/[A-Z]{1,2}.gif/', $captured_td[$i])) {
      break;
    }
  }
  $win_beg = $i;

  // Get all the data between the rain probability and the wind direction
  $end = $win_beg - 1;
  for ($i = $beg; $i <= $end; $i++) {
    preg_match('/>[0-9]{1,4}/', $captured_td[$i], $data);
    $data_lon = strlen($data[0]);
    $rain_tmin[] = substr($data[0], 1, $data_lon);
  }
  $beg = $win_beg;

  // Wind direction
  if ($ampm == 'am') {
    $end = $beg + 9;
  }
  else {
    $end = $beg + 8;
  }
  for ($i = $beg; $i <= $end; $i++) {
    preg_match('/alt=".+"/', $captured_td[$i], $data);
    $data_lon = strlen($data[0]);
    $win_dir[] = substr($data[0], 5, $data_lon - 6);
  }
  $beg = $end + 1;

  // Wind speed
  if ($ampm == 'am') {
    $end = $beg + 9;
  }
  else {
    $end = $beg + 8;
  }
  for ($i = $beg; $i <= $end; $i++) {
    preg_match('/>[0-9]{1,3}/', $captured_td[$i], $data);
    $data_lon = strlen($data[0]);
    $win_spd[] = substr($data[0], 1, $data_lon);
  }

  // Violet index
  $beg = $end + 1;
  $end = $beg + 2;
  for ($i = $beg; $i <= $end; $i++) {
    preg_match('/[0-9]{1,2}</', $captured_td[$i], $data);
    $data_lon = strlen($data[0]);
    $vi[] = substr($data[0], 0, $data_lon - 1);
  }

  // Risk level
  $beg = $beg + 7;
  $end = $beg + 2;
  for ($i = $beg; $i <= $end; $i++) {
    preg_match('/alt=".+?"/', $captured_td[$i], $data);
    $data_lon = strlen($data[0]);
    $rsk[] = substr($data[0], 5, $data_lon - 6);
  }
  return array(
    $sky_img,
    $sky_txt,
    $rain_tmin,
    $win_dir,
    $win_spd,
    $vi,
    $rsk,
  );
}