Skip to content

Commit

Permalink
close #4: added levels and dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacky Liang committed Feb 19, 2015
1 parent 26124eb commit 5f69feb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 50 deletions.
67 changes: 23 additions & 44 deletions PollenBuddy.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class PollenBuddy {
// Number of characters to strip before getting to the data
const CITY_HTML = 20;
const POLLEN_TYPE_HTML = 13;
const LEVELS = 3;
const DATES = 6;

/**
* Get the content of the Wunderground pollen site page based on the
Expand Down Expand Up @@ -85,71 +83,52 @@ public function getPollenType() {
}

/**
* TODO: $this->levels is incomplete
* Get the four day forecast data
* @return mixed
*/
public function getFourDayForecast() {
$this->fourDayForecast = array_merge(
$this->dates,
$this->levels
);
}

/**
* Get the four forecasted dates
* TODO: Set this as private and remove return once development is completed
* @return array Four forecasted dates
*/
public function getFourDates() {

// Iterate through the four dates [Wunderground only has four day
// pollen prediction]
for($i = 0; $i < 4; $i++) {

// Get the raw date
$rawDate = $this->html
->find("td.levels", $i)
->find("td.levels p", $i)
->plaintext;

// Clean the raw date
$date = substr(
$rawDate,
PollenBuddy::DATES
);
// Get the raw level
$rawLevel = $this->html
->find("td.even-four div", $i)
->plaintext;

// Push each date to the dates array
array_push($this->dates, $date);
array_push($this->dates, $rawDate);
// Push each date to the levels array
array_push($this->levels, $rawLevel);
}

$this->fourDayForecast = array_combine(
$this->levels,
$this->dates
);

return $this->fourDayForecast;
}

/**
* Get the four forecasted dates
* @return array Four forecasted dates
*/
public function getFourDates() {
return $this->dates;
}

/**
* TODO: clean the levels data
* TODO: Set this as private and remove return once development is completed
* Get four forecasted levels
* @return array
* @return array Four forecasted levels of each day's pollen levels.
*/
public function getFourLevels() {
// Iterate through the four pollen levels [Wunderground only has four day
// pollen prediction]
for($i = 0; $i < 4; $i++) {

// Get the raw level
$rawLevel = $this->html
->find("td.even-four", $i)
->plaintext;

// Clean the raw level
$level = substr(
$rawLevel,
PollenBuddy::LEVELS
);

// Push each date to the levels array
array_push($this->levels, $level);
}

return $this->levels;
}
}
12 changes: 6 additions & 6 deletions TestPollenBuddy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
require_once("PollenBuddy.php");

$data = new PollenBuddy(19104);
echo $data->getSiteHTML();
echo $data->getCity();
echo $data->getZipCode();
echo $data->getPollenType();
var_dump($data->getFourDates());
var_dump($data->getFourLevels());
//echo $data->getSiteHTML();
//echo $data->getCity();
//echo $data->getZipCode();
//echo $data->getPollenType();
//var_dump($data->getFourDates());
//var_dump($data->getFourLevels());
var_dump($data->getFourDayForecast());

0 comments on commit 5f69feb

Please sign in to comment.