_binary From a834d62038c36fb6a722e328329e71ec4cc5c91e Mon Sep 17 00:00:00 2001
From: Harika Nukala <harika.nukala@sap.com>
Date: Sun, 4 Dec 2016 03:06:13 -0800
Subject: [PATCH] added weather bot in examples

---
 src/examples/bot_examples/weather/index.php | 56 +++++++++++++++++++++++++++++
 1 file changed, 56 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..5ae9324
--- /dev/null
+++ b/src/examples/bot_examples/weather/index.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * 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 index
+{
+    function setKey($access_token)
+    {
+        $this->access_token = $access_token;
+    }
+    /**
+     * Get weather information
+     *
+     * @param string $location  the location to get weather updates for
+     * @return 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 index;
+$bot->setKey($access_token);
+$location = explode(" ", $_POST['post']);
+$result = $bot->getWeather($location[4]);
+print_r($result);
-- 
2.8.4 (Apple Git-73)

