index.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require __DIR__ . '/vendor/autoload.php';
  3. $url = 'https://www.yr.no/place/Norway/Troms/Tromsø/Tromsø/forecast_hour_by_hour.xml';
  4. $forecast = new App\Yr\Forecast($url);
  5. $range = $forecast->getTabular()->getBetween(
  6. $forecast->getSunset(), $forecast->getSunrise()->add(new \DateInterval('P1D'))
  7. );
  8. echo '<pre>';
  9. echo sprintf("Forecast from %s until %s, updated %s:\n",
  10. $range->getFrom()->format('d.m H:i'),
  11. $range->getUntil()->format('d.m H:i'),
  12. $forecast->getLastUpdate()->format('H:i')
  13. );
  14. foreach ($range->getVariations()->getData() as $data) {
  15. echo $data['time']->getFrom()->format("H:i");
  16. }
  17. //echo sprintf("%s: %s\n", $data['time']->getFrom()->format("H:i"), join(", ", $data['entities']));
  18. $f = current(iterator_to_array($range->getIterator()));
  19. echo $f->getWindSpeed()->convertTo('ft/s');
  20. echo "\n";
  21. $stat = $range->getStatistics();
  22. echo "\n";
  23. echo $stat->getAverageTemperature();
  24. echo "\n";
  25. echo $stat->getAverageWindSpeed();
  26. echo "\n";
  27. var_dump($stat->getAverageSymbols());
  28. var_dump($stat->getMostCommonSymbol());
  29. echo "\n";
  30. foreach ($forecast->getCredit() as $c)
  31. echo $c . "\n";
  32. ?>