// Set your access token $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"]); } } }
<?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;
<?php use Nette\Application\Routers\Route; // Load libraries require __DIR__ . '/app/libs/nette.min.php'; require __DIR__ . '/app/libs/feed.class.php'; require __DIR__ . '/app/libs/twitter.class.php'; require __DIR__ . '/app/libs/texy.min.php'; $configurator = new Nette\Config\Configurator(); // Enable Nette Debugger for error visualisation & logging $configurator->enableDebugger(__DIR__ . '/app/log'); // Configure libraries Twitter::$cacheDir = Feed::$cacheDir = __DIR__ . '/app/temp/cache'; $configurator->setTempDirectory(__DIR__ . '/app/temp'); // Create Dependency Injection container from config.neon file $configurator->addConfig(__DIR__ . '/app/config.neon'); $container = $configurator->createContainer(); // Setup routes // http://davidgrudl.com/[cs|en] $container->router[] = new Route('[<lang (?-i)cs|en>]', function ($presenter, $lang) use($container) { if (!$lang) { $lang = $container->httpRequest->detectLanguage(array('en', 'cs')) ?: 'cs'; return $presenter->redirectUrl($lang); } // create template $template = $presenter->createTemplate()->setFile(__DIR__ . '/app/' . $lang . '.latte'); // register template helpers like {$foo|date} $template->registerHelper('date', function ($date) use($lang) { if ($lang === 'en') { return date('F j, Y', (int) $date); } else {