Example #1
0
<?php

//including app settings
require_once 'settings.php';
//including weather app
require_once 'weather2.php';
////constant and variable declaration
define('SYSTEM', 'test');
$settings = get_settings(SYSTEM);
$vars = array("stations" => array($settings['station']), "api_key" => $settings['token']);
$options = array('http' => array('method' => 'POST', 'content' => json_encode($vars), 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n"));
$context = stream_context_create($options);
$result = file_get_contents($settings['url'], false, $context);
$response = get_current_temp($result);
$bctemp = json_encode($response);
header('Content-Type: application/json; charset=UTF-8');
echo $bctemp;
Example #2
0
<?php

date_default_timezone_set('America/New_York');
# Set your timezonr here.
$details = json_decode(file_get_contents("http://ipinfo.io/"));
$ipinfoZip = $details->postal;
if ($_GET["temp"] == 'Y') {
    # CALL WITH http://[IPADDRESS]:84/weather-set-1.php?temp=Y
    $current_temp = get_current_temp($ipinfoZip);
    echo $current_temp . "<br>";
    $formatted_current_temp = str_ireplace("&deg;", "", $current_temp);
    $formatted_current_temp = "T" . str_pad($formatted_current_temp, 4, "0", STR_PAD_LEFT) . "ZZ";
    echo $formatted_current_temp;
    $pass_current_temp = file_get_contents('http://127.0.0.1:83/' . $formatted_current_temp);
    echo $pass_current_temp;
} else {
    # CALL WITH http://[IPADDRESS]:84/weather-set-1.php
    $raw_weather_code = get_weather_code($ipinfoZip);
    $clean_weather_code = "W" . str_pad($raw_weather_code, 3, "0", STR_PAD_LEFT) . "WW";
    echo $clean_weather_code . "<br/>";
    $pass_weather_code = file_get_contents('http://127.0.0.1:83/' . $clean_weather_code);
    echo $pass_weather_code;
}
#Start Functions
function get_contents()
{
    file_get_contents("http://" . $_SERVER['SERVER_ADDR'] . ":83/H");
    $output = var_dump($http_response_header);
    return $output;
}
function get_weather_code($zipcode)