<?php use Cmfcmf\OpenWeatherMap; use Cmfcmf\OpenWeatherMap\Exception as OWMException; $app->get('/', function () use($app) { $view = []; // NEWS SLIDE Feed::$cacheExpire = "30 minutes"; Feed::$cacheDir = "/tmp"; $rss_npr = Feed::loadRss("http://www.npr.org/rss/rss.php?id=1001"); $rss_techmeme = Feed::loadRss("http://www.techmeme.com/feed.xml"); $view['news_npr'] = $rss_npr->item; $view['news_techmeme'] = $rss_techmeme->item; // WEATHER SLIDE $lang = 'en'; $units = 'imperial'; $owm = new OpenWeatherMap(null, new WeatherCache(), 60); try { $weather = $owm->getWeather('Milpitas', $units, $lang, "06b7f9678c0512b3b8ca9e94758a9601"); $rawForecast = $owm->getWeatherForecast("Milpitas", $units, $lang, "06b7f9678c0512b3b8ca9e94758a9601", 3); $forecast = []; while ($rawForecast->valid()) { $chunk = $rawForecast->current(); $forecast[] = ['start' => $chunk->time->from->getTimestamp() - 3600 * 8, 'low' => $chunk->temperature->min->getValue(), 'avg' => $chunk->temperature->now->getValue(), 'max' => $chunk->temperature->max->getValue(), 'pressure' => $chunk->pressure->getValue(), 'precipitation' => $chunk->precipitation->getValue(), 'humidity' => $chunk->humidity->getValue(), 'clouds' => $chunk->clouds->getValue()]; $rawForecast->next(); } $forecastAvg = []; $forecastLow = []; $forecastHigh = []; $forecastPrecip = []; $fp = 0.5;
$url = ''; // URL RSS feed $update = json_decode(file_get_contents('php://input')); //your app try { if ($update->message->text == '/email') { $response = $client->sendChatAction(['chat_id' => $update->message->chat->id, 'action' => 'typing']); $response = $client->sendMessage(['chat_id' => $update->message->chat->id, 'text' => "You can send email to : Kasra@madadipouya.com"]); } else { if ($update->message->text == '/help') { $response = $client->sendChatAction(['chat_id' => $update->message->chat->id, 'action' => 'typing']); $response = $client->sendMessage(['chat_id' => $update->message->chat->id, 'text' => "List of commands :\n /email -> Get email address of the owner \n /latest -> Get latest posts of the blog \n \t\t/help -> Shows list of available commands"]); } else { if ($update->message->text == '/latest') { Feed::$cacheDir = __DIR__ . '/cache'; Feed::$cacheExpire = '5 hours'; $rss = Feed::loadRss($url); $items = $rss->item; $lastitem = $items[0]; $lastlink = $lastitem->link; $lasttitle = $lastitem->title; $message = $lasttitle . " \n " . $lastlink; $response = $client->sendChatAction(['chat_id' => $update->message->chat->id, 'action' => 'typing']); $response = $client->sendMessage(['chat_id' => $update->message->chat->id, 'text' => $message]); } else { $response = $client->sendChatAction(['chat_id' => $update->message->chat->id, 'action' => 'typing']); $response = $client->sendMessage(['chat_id' => $update->message->chat->id, 'text' => "Invalid command, please use /help to get list of available commands"]); } } } } catch (\Zelenin\Telegram\Bot\NotOkException $e) {