-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFetchFMIWeather.php
More file actions
95 lines (64 loc) · 2.42 KB
/
FetchFMIWeather.php
File metadata and controls
95 lines (64 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
use WeatherAPI\Logger;
use WeatherAPI\WeatherAPI;
use WeatherAPI\PDOSource;
/*
* Load Config
* Remember to edit weather.ini to suit your environment
* Use docs/weatherdata.sql to create a database
*/
require 'config.php';
$config = parse_ini_file(CONFIG_FILE);
if ($config['devmode']) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
/*
* Create an instance of WeatherAPI and Logger
*
*/
$weather = new WeatherAPI(new PDOSource($config));
$logger = new Logger(ROOT_DIR . $config['logfile']);
/**
* Get all enabled weatherstations
*/
$enabledStations = $weather->getEnabledWeatherStations();
/**
* Loop through enabled weatherstations
*/
foreach ($enabledStations as $weatherStation) {
/**
* If the enabled station has "sää" as a group get weather for it
*/
if (strpos($weatherStation['groups'], "sää") !== false) {
$weatherObservations = $weather->parseWeatherData($weather->fetchWeatherByFMISID($weatherStation['fmisid']));
$observationInsertResult = $weather->insertObservationData($weatherObservations);
$logger->msg("Inserted / Updated " . $observationInsertResult . " Observations for: " . $weatherStation['name'] . "\n");
}
}
/**
* Get all enabled forecast locations
*
* Forecast location names can be any valid district or city in Finland or recorded by FMI
*/
$forecastLocations = $weather->getEnabledForecastLocations();
/*
* Loop throguh all enabled forecast locations and insert them accordingly
*/
foreach ($forecastLocations as $location) {
$weatherForecastData = $weather->parseWeatherData($weather->fetchForeCast($location['name']));
$forecastInserResult = $weather->insertForecastData($weatherForecastData);
$logger->msg("Inserted / Updated " . $forecastInserResult . " Forecasts\n");
}
/*
* Get Forecast Data, parse the data and insert it
* For testing purposes
*
$weatherForecastData = $weather->parseWeatherData($weather->fetchForeCast($desiredLocation));
$forecastInserResult = $weather->insertForecastData($weatherForecastData);
$logger->msg("Inserted / Updated " . $forecastInserResult . " Forecasts\n");
$weatherObservations = $weather->parseWeatherData($weather->fetchWeather($desiredLocation));
$observationInsertResult = $weather->insertObservationData($weatherObservations);
$logger->msg("Inserted / Updated " . $observationInsertResult . " Observations\n");
*/