include 'lib/forecast.io.php';
$api_key = '<your_api_key>';
$latitude = '52.4308';
$longitude = '13.2588';
$units = 'auto';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
$forecast = new ForecastIO($api_key, $units, $lang);
// all default will be
// $forecast = new ForecastIO($api_key);
/*
 * GET CURRENT CONDITIONS
 */
$condition = $forecast->getCurrentConditions($latitude, $longitude);
echo 'Current temperature: ' . $condition->getTemperature() . "\n";
/*
 * GET HOURLY CONDITIONS FOR TODAY
 */
$conditions_today = $forecast->getForecastToday($latitude, $longitude);
echo "\n\nTodays temperature:\n";
foreach ($conditions_today as $cond) {
    echo $cond->getTime('H:i:s') . ': ' . $cond->getTemperature() . "\n";
}
/*
 * GET DAILY CONDITIONS FOR NEXT 7 DAYS
 */
$conditions_week = $forecast->getForecastWeek($latitude, $longitude);
echo "\n\nConditions this week:\n";
foreach ($conditions_week as $conditions) {
Example #2
0
$apiKeyParam = $_GET["apiKey"];
$latParam = $_GET["lat"];
$lonParam = $_GET["lon"];
$unitsParam = $_GET["units"];
$langParam = $_GET["lang"];
$units = 'us';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
if ($unitsParam != "") {
    $units = $unitsParam;
}
if ($langParam != "") {
    $lang = $langParam;
}
//error_log(date(DATE_RFC822)." -- api=".$apiKeyParam.",lat=".$latParam.",lon=".$lonParam.",units=".$units.",lang=".$lang."\n", 3, '/home/weather.log');
$forecast = new ForecastIO($apiKeyParam, $units, $lang);
$condition = $forecast->getCurrentConditions($latParam, $lonParam);
echo "CURRENT_TEMP=" . round($condition->getTemperature()) . "\n";
echo "CURRENT_HUMIDITY=" . $condition->getHumidity() * 100 . "\n";
echo "CURRENT_ICON=" . $condition->getIcon() . "\n";
echo "CURRENT_SUMMARY=" . $condition->getSummary() . "\n";
$conditions_week = $forecast->getForecastWeek($latParam, $lonParam);
echo "MAX_TEMP_TODAY=" . round($conditions_week[0]->getMaxTemperature()) . "\n";
echo "MIN_TEMP_TODAY=" . round($conditions_week[0]->getMinTemperature()) . "\n";
echo "ICON_TODAY=" . $conditions_week[0]->getIcon() . "\n";
echo "SUMMARY_TODAY=" . $conditions_week[0]->getSummary() . "\n";
echo "MAX_TEMP_TOMORROW=" . round($conditions_week[1]->getMaxTemperature()) . "\n";
echo "ICON_TOMORROW=" . $conditions_week[1]->getIcon() . "\n";
echo "MIN_TEMP_TOMORROW=" . round($conditions_week[1]->getMinTemperature()) . "\n";
echo "SUMMARY_TODAY=" . $conditions_week[1]->getSummary() . "\n";
            $userIP = $_SERVER['REMOTE_ADDR'];
        }
        $IPInfoLoc = json_decode(file_get_contents('http://ipinfo.io/{$userIP}/loc'));
        $IPInfoArray = explode(",", $IPInfoLoc);
        $userLat = $IPInfoArray[0];
        $userLong = $IPInfoArray[1];
    } else {
        $userLat = $_GET['latitude'];
        $userLong = $_GET['longitude'];
    }
}
$forecast = new ForecastIO($apikey);
if ($userLat != null && $userLong != null) {
    $units = 'si';
    $_COOKIE['tempPref'] == 'F' ? $units = 'us' : pass;
    $condition = $forecast->getCurrentConditions($userLat, $userLong, $units);
    $weatherCondition = $condition->getIcon();
    // $weatherCondition = 'clear';
    $backgroundImageURL = './weather-backgrounds/' . $weatherCondition . '.jpg';
    $conditionLaterToday = $forecast->getForecastToday($userLat, $userLong, $units);
    $weatherConditionLater = $conditionLaterToday[7]->getIcon();
    if (in_array($weatherConditionLater, ['rain', 'snow', 'sleet'])) {
    }
    if (in_array($weatherCondition, ['clear-night', 'partly-cloudy-night'])) {
        $isNight = True;
    }
}
?>

    <div id="prefs_modal" class="modal fade">
        <div class="modal-dialog">
<?php

include 'lib/forecast.io.php';
#Slack slash command to return the weather given a zipcode
# Uses forecast.io PHP API by https://github.com/tobias-redmann
$api_key = '0743673bd6f1c055452ab6ee2731dcfd';
//forecast.io API key
$units = 'us';
//units of measurement
$lang = 'en';
//language
#$command = $_POST['command'];   //Slack command name
$text = $_POST['text'];
//given zipcode
$forecast = new ForecastIO($api_key, $units, $lang);
#Convert zipcode to lat/long
$zip = $forecast->getLatLong($text);
$latitude = $zip['lat'];
$longitude = $zip['lng'];
#Int conversion on lat/long
$lat = (int) $latitude;
$long = (int) $longitude;
$geocode = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . $text . '&sensor=true');
$output = json_decode($geocode);
$location = $output->results[0]->formatted_address;
$condition = $forecast->getCurrentConditions($lat, $long);
echo $location . '|' . $condition->getTemperature() . '|' . $condition->getCloudCover();
//print info to slack
Example #5
0
//forecast api need those
$api_key = '538a11475afb9fdd4f9891efb0b697db';
$units = 'auto';
// Can be set to 'us', 'si', 'ca', 'uk' or 'auto' (see forecast.io API); default is auto
$lang = 'en';
// Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en'
$forecast = new ForecastIO($api_key, $units, $lang);
if (!empty($_GET['ID'])) {
    for ($i = 0; $i < $searchRange; $i++) {
        if ($_GET['ID'] == $i) {
            $found = true;
            break;
        } else {
            $found = false;
        }
    }
    if ($found) {
        $_SESSION['user'] = $toolPdo->getUser($_GET['ID']);
        $condition = $forecast->getCurrentConditions($_SESSION['user']['CoordLat'], $_SESSION['user']['CoordLong']);
        include "../v/v_weather.php";
    } else {
        echo "<div='error'><h1>We've met some 404 error, sorry for that...</h1></div>\n\t\t\t<p>Consider trying another ID number in the URL</p>";
    }
} else {
    if (!empty($_GET['Phaser'])) {
        include "../v/v_phaser.php";
    } else {
        echo "<div='error'><h1>We've met some 404 error, sorry for that...</h1></div>\n\t\t\t<p>Consider trying another ID number in the URL</p>";
        echo "<div=''><a href='action.php?ID=2'>Existing Profile : Nagato Yuki</a></div>";
    }
}
function getweather($api_key, $latitude, $longitude, $units = "auto", $lang = "en")
{
    $forecast = new ForecastIO($api_key, $units, $lang);
    //This is array holding CURRENT weather data i.e. weather right now
    $now = array();
    $yesterday = array();
    //This holds today's, tomorrow's and the day after's weather data
    $twoday = array();
    //create a timestamp of yestday, so we can retrieve its weather
    $today = new DateTime("now");
    $yesterdaytime = $today->sub(new DateInterval('P1D'))->getTimeStamp();
    //echo $yesterday;
    //Get current conditions and give to array too
    $condition = $forecast->getCurrentConditions($latitude, $longitude);
    echo "current: " . $condition->getTemperature() . "\n";
    echo "percent rain: " . $condition->getPrecipitationProbability() . "\n";
    echo "humidity: " . $condition->getHumidity() . "\n";
    echo "rain fall: " . $condition->getPrecipitationIntensity();
    $now['temp'] = $condition->getTemperature();
    $now['chancerain'] = $condition->getPrecipitationProbability();
    $now['humidity'] = $condition->getHumidity();
    $now['summary'] = $condition->getSummary();
    $now['rainfall'] = $condition->getPrecipitationIntensity();
    //If precip probability > 0 then get precip type too
    if ($now['chancerain'] > 0) {
        echo "Precip type: " . $current->PrecipitationType() . "\n";
        $now['preciptype'] = $current->PrecipitationType();
    }
    //Get weekly forecast (next 2 days is fine)
    $conditions_week = $forecast->getForecastWeek($latitude, $longitude);
    //print_r($conditions_week);
    echo "\nConditions this week:\n";
    $i = 0;
    foreach ($conditions_week as $conditions) {
        $cheese = new DateTime("now");
        $step = new DateInterval('P2D');
        //If day is less then or equal to 2 days from now then we want that info
        if ($cheese->add($step)->format('Y-m-d') >= $conditions->getTime('Y-m-d')) {
            echo $conditions->getTime('Y-m-d') . ": " . $conditions->getMaxTemperature() . "\n";
            $twoday[$i]['maxtemp'] = $conditions->getMaxTemperature();
            $twoday[$i]['chancerain'] = $conditions->getPrecipitationProbability();
            $twoday[$i]['rainfall'] = $conditions->getPrecipitationIntensity();
            $twoday[$i]['rainfallmax'] = $conditions->getPrecipitationIntensityMax();
            if ($twoday[$i]['rainfallmax'] > 0) {
                $twoday[$i]['rainfallmaxtime'] = $conditions->getPrecipitationIntensityMaxTime();
            }
            if ($twoday[$i]['chancerain'] > 0) {
                echo "Precip type: " . $conditions->getPrecipitationType() . "\n";
                $twoday[$i]['preciptype'] = $conditions->getPrecipitationType();
            }
            $twoday[$i]['humidity'] = $conditions->getHumidity();
            $twoday[$i]['summary'] = $conditions->getSummary();
        }
        $i++;
    }
    //Get Yesterdays forecast
    echo "\n Yesterdays conditions: \n";
    $yesterdays = $forecast->getHistoricalConditions($latitude, $longitude, $yesterdaytime);
    echo "Yesterday: " . $yesterdays->getMaxTemperature() . "\n";
    echo "percent rain: " . $yesterdays->getPrecipitationProbability() . "\n";
    echo "humidity: " . $yesterdays->getHumidity() . "\n";
    echo "rain fall: " . $yesterdays->getPrecipitationIntensity();
    $yesterday['temp'] = $yesterdays->getMaxTemperature();
    $yesterday['chancerain'] = $yesterdays->getPrecipitationProbability();
    $yesterday['humidity'] = $yesterdays->getHumidity();
    $yesterday['summary'] = $yesterdays->getSummary();
    $yesterday['rainfall'] = $yesterdays->getPrecipitationIntensity();
    //If precip probability > 0 then get precip type too
    if ($yesterday['chancerain'] > 0) {
        echo "Precip type: " . $yesterdays->PrecipitationType() . "\n";
        $yesterdays['preciptype'] = $yesterdays->PrecipitationType();
    }
    //print_r($yesterdays);
    //return array with current, today, tomorrow, and day after temp/conditions
    return [$now, $twoday];
}