Ejemplo n.º 1
0
 /**
  * @param $args
  */
 public function index($args)
 {
     if (empty($args)) {
         return false;
     }
     setcookie("name", $args['name'], time() + 50000, '/');
     $forecast = new \models\ForecastModel(\models\DbClass::getInstance());
     $api = new \models\ApiModel();
     $city = $api->getCity($args['name']);
     $curWeather = $api->getCurrentWeather($args['name']);
     $this->smarty->assign('current_weather', $curWeather);
     $weather = $forecast->forecast($args['name']);
     $archive = $forecast->archive($args['name']);
     $this->smarty->assign('weather', $weather);
     $this->smarty->assign('archive', $archive);
     $this->smarty->assign('city', $city['title']);
     $this->smarty->display('forecast.tpl');
 }
Ejemplo n.º 2
0
 public function add_forecast()
 {
     $api = new \models\ApiModel();
     $towns = $api->getCities();
     $config = \config\Config::getInstance();
     $db = new \Mongo("mongodb://" . $config['db_host'] . ":" . $config['db_port'] . "/" . $config['db_database']);
     $collection = $db->selectCollection('ngs', 'forecasts');
     foreach ($towns as $town) {
         $decoded = $api->getForecast($town['name']);
         foreach ($decoded['forecasts'] as $forecasts) {
             foreach ($forecasts['hours'] as $hours) {
                 if ($hours['hour'] == '12') {
                     $mas = array('temperature' => $hours['temperature']['avg'], 'pressure' => $hours['pressure']['avg'], 'humidity' => $hours['humidity']['avg'], 'wind' => array('speed' => $hours['wind']['speed']['avg'], 'direction' => $hours['wind']['direction']['title']), 'cloud' => $hours['cloud']['title'], 'precipitation' => $hours['precipitation']['title']);
                 }
             }
             $document = array('date' => new \MongoDate(strtotime($forecasts['date'])), 'city' => $town['name'], 'forecast' => $mas);
             $collection->update(array('city' => $document['city'], 'date' => $document['date']), array('$set' => $document), array('upsert' => true));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param $args
  */
 public function change($args)
 {
     if (empty($args)) {
         return false;
     }
     $api = new \models\ApiModel();
     $city = new \models\CityModel(\models\DbClass::getInstance());
     $city->addCity($api->getCity($args['name']));
     $city->delCity($args['current']);
     $this->index();
 }