-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron_weather.php
67 lines (59 loc) · 2.28 KB
/
cron_weather.php
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
<?php require_once("utility.php");
$config = getConfig();
$openWeatherMapConfig = getDataFromFile("OpenWeatherMap.json");
if($config != -1 || $openWeatherMapConfig != -1)
{
if(!empty($openWeatherMapConfig["forecast"]["params"]) &&
!empty($openWeatherMapConfig["APIParamName"]) &&
!empty($openWeatherMapConfig["forecast"]["url"]) &&
!empty($config["OpenWeatherAPI"]))
{
$openWeatherMapConfig["weather"]["params"][] = $openWeatherMapConfig["APIParamName"].'='.$config["OpenWeatherAPI"];
$url = generateFinalUrl($openWeatherMapConfig["weather"]["url"], $openWeatherMapConfig["weather"]["params"]);
$responseData = getDataFromFile($url, true);
if($responseData != -1)
{
if($responseData["cod"] == "200")
{
$newObject = array();
if(!empty($responseData["dt"]) && !empty($responseData["sys"]["sunrise"]) && !empty($responseData["sys"]["sunset"]) && !empty($responseData["weather"][0]["id"]))
{
$newObject['date'] = $responseData['dt'];
$newObject['sunrise'] = $responseData['sys']['sunrise'];
$newObject['sunset'] = $responseData['sys']['sunset'];
$newObject['code'] = getWeatherCode($responseData['weather'][0]['id']);
if(saveDataToFile($newObject, 'weather.json') == -1)
{
//mail
mail($config['mailTo'], 'Weather Server bug repport', 'Weather Server encountered a problem in cron_weather during saving the file');
}
}
else
{
//mail
mail($config['mailTo'], 'Weather Server bug repport', 'Weather Server encountered a problem in cron_weather during checking the response validity');
}
}
else
{
//mail
mail($config['mailTo'], 'Weather Server bug repport', 'Weather Server encountered a problem in cron_weather during checking response code api');
}
}
else
{
//mail
mail($config['mailTo'], 'Weather Server bug repport', 'Weather Server encountered a problem in cron_weather during checking if the api server respond');
}
}
else
{
//mail
mail($config['mailTo'], 'Weather Server bug repport', 'Weather Server encountered a problem in cron_weather during parsing the config file');
}
}
else
{
mail($config['mailTo'], 'Weather Server bug repport', 'Weather Server encountered a problem in cron_weather: fatal error');
}
?>