Skip to content

Weather forecast web app with an open weather API (OpenWeatherMap)

License

Notifications You must be signed in to change notification settings

zakishaquille/Weather-Forecast

Repository files navigation

WeaCast - Weather Forecast

WeaCast is a web application about forecasting weather, climate, etc. This app is built with codeigniter and an weather API(OpenWeatherMap).

For more info about the API you can check here OpenWeatherMap API


1. Demo Apps

  • Clone/download this repo
  • Put in htdocs
  • Turn on your web server(ex: xampp,wampp)
  • Config base url configuration base_url (if needed)
  • Run in browser "localhost/weather-forecast/" (follow your configuration)

Homepage homepage

Result page result


2. Configuration

application/config.php - Set link app

$config['base_url'] = 'http://localhost/weather-forecast/';


3. Controller

application/controllers/Forecast.php - App controller

Homepage controller

public function index()
	{
		$data['title'] = "Home";
		$this->load->view('forecast', $data);
	}

Result page controller

public function forecasting()
	{
		if(!empty($_POST['city'])) {
			$data['current_weather'] = $this->M_Forecast->current_weather($_POST['city']);
			$data['forecast_weather'] = $this->M_Forecast->forecast_weather($_POST['city']);
		} else {
			$data['current_weather']=null;
			$data['forecast_weather']=null;
		}
		
		$data['title'] = "Result";
        $this->load->view('weacast', $data);
	}

4. Model

application/models/M_Forecast.php - App model

Get data Current Weather (Left side)

function current_weather($city)
    {
		 //get JSON
		 $json = file_get_contents("http://api.openweathermap.org/data/2.5/weather?appid=770a17f9520e41124656aa601bc34b3c&units=metric&q=$city", false);

		 //decode JSON to array
		 $data = json_decode($json,true);
		 
		 //return data array()
		 return $data;
    }

Get data Forecast (Right side)

function forecast_weather($city)
    {
		 //get JSON
		 $json = file_get_contents("http://api.openweathermap.org/data/2.5/forecast/daily?appid=770a17f9520e41124656aa601bc34b3c&units=metric&q=$city&cnt=7", false);

		 //decode JSON to array
		 $data = json_decode($json,true);
		 
		 //return data array()
		 return $data;
    }

About

Weather forecast web app with an open weather API (OpenWeatherMap)

Topics

Resources

License

Stars

Watchers

Forks