From 94b441caacd670fc25f2b8045e2d9ee0d875ae0b Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sun, 24 Jul 2022 20:05:49 +0200 Subject: [PATCH] init --- .gitignore | 1 + config.dist.php | 6 +++ display.html.php | 68 ++++++++++++++++++++++++++ index.php | 121 +++++++++++++++++++++++++++++++++++++++++++++++ search.html.php | 28 +++++++++++ style.css | 45 ++++++++++++++++++ style.less | 55 +++++++++++++++++++++ 7 files changed, 324 insertions(+) create mode 100644 .gitignore create mode 100644 config.dist.php create mode 100644 display.html.php create mode 100644 index.php create mode 100644 search.html.php create mode 100644 style.css create mode 100644 style.less diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f4773f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.php diff --git a/config.dist.php b/config.dist.php new file mode 100644 index 0000000..37d7815 --- /dev/null +++ b/config.dist.php @@ -0,0 +1,6 @@ + '', + 'web_context' => '' +]; diff --git a/display.html.php b/display.html.php new file mode 100644 index 0000000..6d5f515 --- /dev/null +++ b/display.html.php @@ -0,0 +1,68 @@ + + + + + + Phedder + + + +

+

/

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
DatumRegenWindTemp
+ + + + + + + mm + + + + + + m/s°C
+ +
+ + +
+ + diff --git a/index.php b/index.php new file mode 100644 index 0000000..f670d2b --- /dev/null +++ b/index.php @@ -0,0 +1,121 @@ + $data->city->name . ', ' . $data->city->country, + 'population' => $data->city->population, + 'sunrise' => date('H:i:s', $data->city->sunrise), + 'sunset' => date('H:i:s', $data->city->sunset) +]; + +$icons = [ + //'01d' => "&#D83C;&#DF1E;", + '01d' => '🌞', + '01n' => '🌚', + '02d' => "🌤", + '02n' => "🌤", + '03d' => "🌥", + '03n' => "🌥", + '04d' => "☁", + '04n' => "☁", + '09d' => "🌦", + '09n' => "🌦", + '10d' => "🌧", + '10n' => "🌧", + '11d' => "🌩", + '11n' => "🌩", + '13d' => "⛄", + '13n' => "⛄", + '50d' => "🌫", + '50n' => "🌫" +]; + +$list = []; +foreach ($data->list as $line) { + $temp = $line->main->temp - 273.15; + $date = date('D. d.m. H:i', $line->dt); + $icon = $icons[$line->weather[0]->icon]; + + $rainArr = (array) ($line->rain ?? []); + $snowArr = (array) ($line->snow ?? []); + $rain = ($rainArr['3h'] ?? 0) + ($snowArr['3h'] ?? 0); + + $wind = $line->wind->speed; + $flying = $rain === 0 && $wind < 2.5 ? 'Y' + : $rain <= 0.3 && $wind < 3.1 ? 'M' + : 'N'; + $flyingIcon = $flying === 'Y' ? "🛩" + : $flying === 'M' ? "🛩" + : '⏚'; + + $riding = $rain === 0 && $temp > 15 ? 'Y' + : $rain <= 0.3 && $temp > 10 ? 'M' + : 'N'; + $ridingIcon = $riding === 'Y' ? "🏍" + : $riding === 'M' ? "🏍" + : "🚳"; + + $list[] = [ + 'temp' => $temp, + 'date' => $date, + 'icon' => $icon, + 'rain' => $rain, + 'wind' => $wind, + 'flying' => $flying, + 'flyingIcon' => $flyingIcon, + 'riding' => $riding, + 'ridingIcon' => $ridingIcon + ]; +} + +$lastDay = substr($list[0]['date'], 0, 11); +$dayGroup = []; +$grouped = []; +foreach($list as $line) { + $dayStr = substr($line['date'], 0, 11); + if ($dayStr === $lastDay) { + $dayGroup[] = $line; + } else { + $grouped[] = $dayGroup; + $dayGroup = []; + $lastDay = $dayStr; + } +} +$grouped[] = $dayGroup; + +require_once 'display.html.php'; diff --git a/search.html.php b/search.html.php new file mode 100644 index 0000000..50e373d --- /dev/null +++ b/search.html.php @@ -0,0 +1,28 @@ + + + + + + Phedder + + + +

Phedder

+
+ + +
+ +

Http Code:

+ + + diff --git a/style.css b/style.css new file mode 100644 index 0000000..01448dd --- /dev/null +++ b/style.css @@ -0,0 +1,45 @@ +body { + max-width: 50rem; + margin: auto; + font-family: sans-serif; + padding: .2rem; +} +body .search form * { + margin-right: 1rem; + display: inline-block; +} +body .forecast { + border-spacing: 0; + width: 100%; + margin-bottom: 2rem; +} +body .forecast tbody::after { + display: block; + height: 2rem; + content: ""; +} +body .forecast img { + height: 2rem; +} +body .forecast th { + border-bottom: .2rem solid #ccc; + background-color: #aaa; + padding: .8rem 0rem; +} +body .forecast td { + padding: .5rem 0rem; + border-bottom: 1px solid #ddd; +} +body .forecast td:not(:first-child) { + white-space: nowrap; +} +body .forecast .pictogram { + width: 0; + padding: .5rem .5rem; +} +body .forecast .flying-weather { + border-bottom: 3px solid green; +} +body .forecast .maybe-flying-weather { + border-bottom: 3px solid darkorange; +} diff --git a/style.less b/style.less new file mode 100644 index 0000000..3a76101 --- /dev/null +++ b/style.less @@ -0,0 +1,55 @@ +body { + max-width: 50rem; + margin: auto; + font-family: sans-serif; + padding: .2rem; + + .search form * { + margin-right: 1rem; + display: inline-block; + } + + .forecast { + border-spacing: 0; + width: 100%; + margin-bottom: 2rem; + + tbody::after { + display: block; + height: 2rem; + content: ""; + } + + img { + height: 2rem; + } + + th { + border-bottom: .2rem solid #ccc; + background-color: #aaa; + padding: .8rem 0rem; + } + + td { + padding: .5rem 0rem; + border-bottom: 1px solid #ddd; + + &:not(:first-child) { + white-space: nowrap; + } + } + + .pictogram { + width: 0; + padding: .5rem .5rem; + } + + .flying-weather { + border-bottom: 3px solid green; + } + + .maybe-flying-weather { + border-bottom: 3px solid darkorange; + } + } +}