-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
150 lines (141 loc) · 6.98 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/openweathermap.php';
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Exception as OWMException;
try {
$cities = explode( "\n", file_get_contents(__DIR__ . "/data/cities.txt"));
$city = explode(";", $cities[array_rand($cities)]);
$owm = new OpenWeatherMap($_ENV['API_KEY'], null, new FileSystemCache(), 60);
$weather = $owm->getWeather($city[0], 'metric', 'de');
$c = $weather->temperature->now->getValue();
$color = color($c, 1);
$gradient = gradient($c, 1);
$city[]= join(',', $color);
$city[]= join(',', $gradient[0]);
$city[]= join(',', $gradient[1]);
$city[]= round($c);
$time = new DateTime();
$time->setTimezone(new DateTimeZone('UTC'));
$h = gmdate('H', $time->getTimestamp() + 3600 * $city[1]);
$m = gmdate('i', $time->getTimestamp() + 3600 * $city[1]);
$s = gmdate('s', $time->getTimestamp() + 3600 * $city[1]);
if (!empty($_GET['update'])) {
die(implode(';', $city));
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SOLOGRAPH</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<link rel="stylesheet" href="style.min.css" />
<!--[if lt IE 9]>
<style>
body {
color: #000;
}
</style>
<![endif]-->
<style>
body{
background: rgb(<?php echo $color[0]; ?>, <?php echo $color[1]; ?>, <?php echo $color[2]; ?> );
background: -moz-linear-gradient(-45deg, rgb(<?php echo $gradient[0][0]; ?>, <?php echo $gradient[0][1]; ?>, <?php echo $gradient[0][2]; ?>) 0%, rgb(<?php echo $gradient[1][0]; ?>, <?php echo $gradient[1][1]; ?>, <?php echo $gradient[1][2]; ?>) 100%);
background: -webkit-linear-gradient(-45deg, rgb(<?php echo $gradient[0][0]; ?>, <?php echo $gradient[0][1]; ?>, <?php echo $gradient[0][2]; ?>) 0%,rgb(<?php echo $gradient[1][0]; ?>, <?php echo $gradient[1][1]; ?>, <?php echo $gradient[1][2]; ?>) 100%);
background: linear-gradient(45deg, rgb(<?php echo $gradient[0][0]; ?>, <?php echo $gradient[0][1]; ?>, <?php echo $gradient[0][2]; ?>), rgb(<?php echo $gradient[1][0]; ?>, <?php echo $gradient[1][1]; ?>, <?php echo $gradient[1][2]; ?>));
color: #fff;
}
#outer, #inner{
display: none;
}
</style>
</head>
<body>
<div class="solograph">
<div class="solograph__content">
<div class="location">
<h1 class="location__name"><?php echo $weather->city->name; ?></h1>
<div class="location__time"><?php echo gmdate("H:i:s", $time->getTimestamp() + 3600 * $city[1]); ?></div>
<div class="visualization">
<div class="visualization__data">
<div class="temperature"><span class="temperature__value"><?php echo round($c); ?></span><span class="temperature__unit">°C</span></div>
</div>
</div>
</div>
<div class="graph">
<svg version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 800 800" style="enable-background:new 0 0 800 800;" xml:space="preserve">
<defs>
<linearGradient id="gradient" gradientUnits="objectBoundingBox"><stop offset="0" style="stop-color: rgb(<?php echo $color[0]; ?>, <?php echo $color[1]; ?>, <?php echo $color[2]; ?>);"></stop><stop offset="1" style="stop-color: rgba(255, 255, 255, 0.4);"></stop></linearGradient>
<filter id="filter_blur" x="0" y="0">
<feGaussianBlur in="SourceGraphic" stdDeviation="2"></feGaussianBlur>
</filter>
<clipPath id="clip_circle">
<circle cx="60" cy="60" r="40"></circle>
</clipPath>
<clipPath id="clip_rectangular" style="transform: translateX(103.3%); -moz-transform: translateX(103.3%); -ms-transform: translateX(103.3%); -webkit-transform: translateX(103.3%);">
<rect x="150" y="150" width="50" height="500"></rect>
</clipPath>
</defs>
<g id="seconds">
<g><circle class="st2" cx="400" cy="400" r="239.4"<?php echo ' style="fill: none; stroke:url(#gradient); stroke-dashoffset: ' . ($s * -26.183) . '"'; ?>></circle></g>
</g>
<g class="flare"<?php echo ' style="fill: url(#gradient);"'; ?>><circle class="st3" cx="400" cy="400" r="10"<?php echo ' style="fill: url(#gradient);"'; ?>></circle></g>
<g class="flare"<?php echo ' style="fill: url(#gradient);"'; ?>><circle class="st3" cx="400" cy="400" r="10"<?php echo ' style="fill: url(#gradient);"'; ?>></circle></g>
<g class="flare"<?php echo ' style="fill: url(#gradient);"'; ?>><circle class="st3" cx="400" cy="400" r="10"<?php echo ' style="fill: url(#gradient);"'; ?>></circle></g>
<g class="flare"<?php echo ' style="fill: url(#gradient);"'; ?>><circle class="st3" cx="400" cy="400" r="10"<?php echo ' style="fill: url(#gradient);"'; ?>></circle></g>
<g class="flare"<?php echo ' style="fill: url(#gradient);"'; ?>><circle class="st3" cx="400" cy="400" r="10"<?php echo ' style="fill: url(#gradient);"'; ?>></circle></g>
<g id="outer">
<g>
<g><circle class="st0" cx="400" cy="160.1" r="150.3"<?php echo ' style="fill: url(#gradient);"'; ?>></circle></g>
<g><circle class="st1" cx="400" cy="400" r="394.1"></circle></g>
</g>
</g>
<g id="basis">
<g><circle class="st10" cx="400" cy="400" r="239.4"<?php echo ' style="fill: url(#gradient); stroke:url(#gradient);"'; ?>></circle></g>
</g>
<g id="inner">
<g>
<g><circle class="st1" cx="400" cy="400" r="239.9"></circle></g>
</g>
<g>
<g><g><path class="st0" d="M400,310.9c66.6,0,123-43.3,142.8-103.2c-39.9-29.6-89.3-47.1-142.8-47.1s-102.9,17.5-142.8,47.1 C277,267.6,333.4,310.9,400,310.9z"<?php echo ' style="fill: url(#gradient);"'; ?>></path></g></g>
<g><circle class="st1" cx="400" cy="400" r="394.1"></circle></g>
</g>
</g>
</svg>
</div>
</div>
<div class="solograph__footer">
2016 by <a href="http://www.strichpunkt-design.de" target="_blank">Strichpunkt</a> – powered by <a href="http://www.openweathermap.org" target="_blank">OpenWeatherMap</a>
</div>
</div>
<script type="text/javascript" src="script.min.js"></script>
<script type="text/javascript">window.solograph.initialize("<?php echo trim(preg_replace('/\s+/', ' ', implode(";", $city))); ?>");</script>
</body>
</html>
<?php
} catch(Exception $exception) {
if (!empty($_GET['update'])) {
header('HTTP/1.0 404 Not Found');
die("");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>SOLOGRAPH</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<link rel="stylesheet" href="style.min.css" />
</head>
<body>
<h1>OpenWeatherMap API Error</h1>
<a href="index.php">Reload</a>
</body>
</html>
<?php
}
?>