-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
117 lines (85 loc) · 3.38 KB
/
index.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<head>
<meta charset='utf-8'>
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="/style.css" media="screen" />
<script src="/skycons.js"></script>
<script>
function startTime() {
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('clock').innerHTML = h+":"+m+":"+s;
var t = setTimeout(function(){startTime()},500);
}
function checkTime(i) {
if (i<10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
</script>
<?php $WEATHER_API_KEY = "dd4adf301215e0ec1def6b9eba5107d8"; ?>
<?php $GUARDIAN_API_KEY = "uz4qna4uwg5vwhya5xmk37wg"; ?>
</head>
<body onload="startTime()">
<?php // WEATHER
$forecast_json = file_get_contents('https://api.forecast.io/forecast/'.$WEATHER_API_KEY.'/53.5361435,2.0936774?units=si');
$forecast_php = json_decode($forecast_json, true);
$current_summary = $forecast_php["currently"]["summary"];
$temp = $forecast_php["currently"]["temperature"];
$feels_like = $forecast_php["currently"]["apparentTemperature"];
$precip_prob = $forecast_php["currently"]["precipProbability"];
$precip_inten = $forecast_php["currently"]["precipIntensity"];
$cloud_cover = $forecast_php["currently"]["cloudCover"];
$pressure = $forecast_php["currently"]["pressure"];
$detailed_summary = $forecast_php["minutely"]["summary"];
?>
<div class="table">
<div class="row clock-temp">
<div class="left" id="clock">
</div>
<div class="right">
<canvas id="weather-icon" width="72" height="72"></canvas>
<script>
var skycons = new Skycons({"color": "white"});
skycons.add("weather-icon", Skycons.PARTLY_CLOUDY_DAY);
skycons.play();
</script>
<div class="temp">
<?php echo round($temp, 1); ?>°C
</div>
</div>
</div>
<div class="row">
<!-- <p><?php echo $current_summary; ?></p> -->
<p><?php echo $detailed_summary; ?></p>
<!-- <p>Feels like <?php echo $feels_like; ?>°C</p> -->
<p><?php echo $precip_prob*100; ?>% chance of rain</p>
<!-- <p>How heavy is it? <?php echo $precip_inten; ?></p> -->
<p><?php echo $cloud_cover*100; ?>% cloud cover</p>
<!-- <p>Pressure: <?php echo $pressure; ?></p> -->
</div>
<div class="row news-articles">
<h2>news</h2>
<?php // NEWS
$no_articles = 1;
show_news('world', $no_articles, $GUARDIAN_API_KEY);
show_news('technology', $no_articles, $GUARDIAN_API_KEY);
show_news('politics', $no_articles, $GUARDIAN_API_KEY);
function show_news($section, $no_articles, $GUARDIAN_API_KEY) {
$news_json = file_get_contents('http://content.guardianapis.com/'. $section .'?show-editors-picks=true&page-size='.$no_articles.'&api-key='.$GUARDIAN_API_KEY);
$news_array = json_decode($news_json, true);
foreach ($news_array['response']['results'] as &$article) {
echo "<p>" . $article['webTitle'] . "</p>";
}
}
?>
</div>
<div class="row">
</div>
</div>
</body>