/** * Gets the weather from Yahoo!, which is more reliable. */ public function getYahooWeatherInfo() { echo "<pre>\n"; $manualSearch = new Collection(); foreach (Structure::get() as $structure) { if (strlen($structure->postal_code) > 0 && strlen($structure->country_code) > 0) { // find City in database? /** @var City $city */ $city = City::firstOrCreate(['postal_code' => $structure->postal_code, 'country_code' => $structure->country_code]); } else { // Fall back to Utrecht, the netherlands (central station area): $city = City::firstOrCreate(['postal_code' => '3511CE', 'country_code' => 'NL']); } $manualSearch->push($city); } $manualSearch = $manualSearch->unique(); // Yahoo weather is always per city. /** @var City $manualEntry */ foreach ($manualSearch as $city) { // function wont do stuff when its already filled. $this->_helper->getGeoFromYahoo($city); $weatherObject = $this->_helper->getYahooWeatherForCity($city); echo 'Now searching for city #' . $city->id . ', [postal code: ' . $city->postal_code . ', country code: ' . $city->country_code . ']' . "\n"; echo 'City has timezone ' . $city->time_zone . ' and woe-id ' . $city->woeid . "\n"; // try to get as many results from this as possible if (isset($weatherObject->query->results)) { $channel = $weatherObject->query->results->channel; // create report entry first: $report = new Report(); $report->city()->associate($city); $report->time = new Carbon(); $report->save(); // start saving data: // sunrise: $sysSunrise = new Carbon($channel->astronomy->sunrise, $city->time_zone); $sysSunrise->setTimezone('UTC'); $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'sys.sunrise'; $entry->value = $sysSunrise->format('U'); $entry->save(); // sunset: $sysSunset = new Carbon($channel->astronomy->sunset, $city->time_zone); $sysSunset->setTimezone('UTC'); $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'sys.sunset'; $entry->value = $sysSunset->format('U'); $entry->save(); // current temperature: $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.temp'; $entry->value = floatval($channel->item->condition->temp); $entry->save(); // current humidity: $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.humidity'; $entry->value = floatval($channel->atmosphere->humidity); $entry->save(); // current pressure: $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.pressure'; $entry->value = floatval($channel->atmosphere->pressure); $entry->save(); // max predicted for today. $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.temp_max'; $entry->value = floatval($channel->item->forecast[0]->high); $entry->save(); // min predicted for today. $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'main.temp_min'; $entry->value = floatval($channel->item->forecast[0]->low); $entry->save(); // wind speed $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'wind.speed'; $entry->value = floatval($channel->wind->speed); $entry->save(); // wind degrees $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'wind.deg'; $entry->value = floatval($channel->wind->direction); $entry->save(); // rain 1h? SKIPPED // weather.main $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'weather.main'; $entry->value = trim($channel->item->condition->text); $entry->save(); // weather.description $entry = new ReportValue(); $entry->report()->associate($report); $entry->name = 'weather.description'; $entry->value = trim($channel->item->description); $entry->save(); echo 'Saved ' . $report->reportValues()->count() . ' weather reports for city #' . $city->id . "\n\n"; } else { echo 'No results for city [' . $city->postal_code . ', ' . $city->country_code . ']' . "\n\n"; } } }
public function testLoad_setUnmodifiedWithDots() { $structure = new Structure(); $structure->merge(array('param' => array('subparam' => 'value')), false); $this->assertEquals('value', $structure->get('param.subparam')); $this->assertFalse($structure->isModified('param.subparam')); }