Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('forecast.io.php');
- $api_key = '_FORECAST_API_KEY_';
- $latitude = '43.6701';
- $longitude = '-79.3866';
- $forecast = new ForecastIO($api_key);
- $condition = $forecast->getCurrentConditions($latitude, $longitude);
- $currentWeather = 'Temp ' . round($condition->getTemperature()) . '/Feels ' . round($condition->getApparentTemperature()) . '*C';
- $response = sendPostData('lcd3', $currentWeather);
- if (strpos($response, '"return_value": 1') === false) echo $response . "\n";
- else echo $currentWeather . "\n";
- $nextHours = $condition->getNextHoursSummary();
- $response = sendPostData('lcd4', $nextHours);
- if (strpos($response, '"return_value": 1') === false) echo $response . "\n";
- else echo $nextHours . "\n";
- echo str_repeat('#', 20) . "\n";
- function sendPostData($function, $post) {
- $ch = curl_init('https://api.spark.io/v1/devices/_DEVICE_ID_/' . $function);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, 'access_token=_ACCESS_TOKEN_&args='.$post);
- $return = curl_exec($ch);
- echo curl_error($ch);
- curl_close($ch);
- return $return;
- }
- //############################################//
- //And this lines in forecast.io.php
- //Replaced - @class ForecastIO:
- function getCurrentConditions($latitude, $longitude) {
- $data = $this->requestData($latitude, $longitude);
- if ($data !== false) {
- $tmpData = $data->currently;
- $tmpData->nextHoursSummary = $data->hourly->summary;
- return new ForecastIOConditions($tmpData);
- } else {
- return false;
- }
- }
- //Added - @class ForecastIOConditions:
- function getApparentTemperature() {
- return $this->raw_data->apparentTemperature;
- }
- function getNextHoursSummary() {
- return $this->raw_data->nextHoursSummary;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement