_binary From 4b5e93f27523e53cc3b4ef1dd72abd57eaac7e36 Mon Sep 17 00:00:00 2001
From: Harika Nukala <harika.nukala@sap.com>
Date: Mon, 12 Dec 2016 19:28:40 -0800
Subject: [PATCH] added weather bot in examples/bot_examples

---
 src/examples/bot_examples/weather/index.php | 91 +++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)
 create mode 100644 src/examples/bot_examples/weather/index.php

diff --git a/src/examples/bot_examples/weather/index.php b/src/examples/bot_examples/weather/index.php
new file mode 100644
index 0000000..14a7afb
--- /dev/null
+++ b/src/examples/bot_examples/weather/index.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2014  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see .
+ *
+ *  END LICENSE
+ *
+ * @author Chris Pollett chris@pollett.org
+ * @package seek_quarry
+ * @subpackage executables
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2014
+ * @filesource
+ */
+/**
+ * User: Harika Nukala
+ * Date: 11/15/16
+ * Time: 1:05 PM
+ */
+/**
+ * Bot work instruction:
+ * The current folder has to be moved to root path
+ * Create a bot with CALLBACK_URL as http://HOSTNAME/weather/index.php
+ * Add the bot to the group you wanted to converse
+ * Talk to your bot in yioop Groups by calling bot as @bot_name in comment
+ */
+/**
+ * This file contains an example bot called weather bot
+ * to get weather updates whenever you ask
+ */
+
+class WeatherBot
+{
+    function setKey($access_token)
+    {
+        $this->access_token = $access_token;
+    }
+    /**
+     * Get weather information
+     *
+     * @param string $location the location to get weather updates for
+     * @return string weather information
+     */
+    function getWeather($location)
+    {
+        $BASE_URL = "http://query.yahooapis.com/v1/public/yql";
+        $yql_query = "select * from weather.forecast where woeid in 
+                      (select woeid from geo.places(1) where text='".$location."')";
+        $Url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $Url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        $data = curl_exec($ch);
+        curl_close($ch);
+        $result = json_decode($data);
+        $temp = $result->query->results->channel->item->condition->temp;
+        $text = $result->query->results->channel->item->condition->text;
+        return "The weather is " . $temp . " and " . $text . " in " . $location;
+    }
+}
+
+$access_token ="bot_token";
+$bot = new WeatherBot();
+$bot->setKey($access_token);
+$location = "";
+$result = "";
+if(!empty($_POST['post'])){
+    $location = explode(" ", $_POST['post']);
+}
+if(!empty($location[4])) {
+    $result = $bot->getWeather($location[4]);
+}
+echo $result;
-- 
2.9.3 (Apple Git-75)

