From 5142133f16cb085d46fbfd9514ab423b684f41aa Mon Sep 17 00:00:00 2001 From: Frankie B Date: Wed, 14 Jun 2023 21:48:05 +0100 Subject: Made weatherdata less painful to look at --- resources/views/components/weather.blade.php | 19 +++++++ resources/views/components/weatherdata.blade.php | 68 ------------------------ resources/views/pages/home.blade.php | 2 +- 3 files changed, 20 insertions(+), 69 deletions(-) create mode 100644 resources/views/components/weather.blade.php delete mode 100644 resources/views/components/weatherdata.blade.php diff --git a/resources/views/components/weather.blade.php b/resources/views/components/weather.blade.php new file mode 100644 index 0000000..b29ccc9 --- /dev/null +++ b/resources/views/components/weather.blade.php @@ -0,0 +1,19 @@ +@php + function degreesToCompassDirection($degrees) { + $cardinalDirections = array('N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'); + $degreesPerDirection = 360 / count($cardinalDirections); + $index = round($degrees / $degreesPerDirection); + return $cardinalDirections[$index]; + } + + $data = json_decode(file_get_contents('http://weather.diskfloppy.me/data/weatherData.json')); + $updated = gmdate('H:i Y-m-d', intval(rtrim(file_get_contents('http://weather.diskfloppy.me/data/got.txt')))); + $data = $data->data->conditions[0]; +@endphp + +

Local Weather (Last Update: {{ $updated }})

+ Wind Speed: {{ $data->wind_speed_last }} mph
+ Wind Direction: {{ $data->wind_dir_last }}°, {{ degreesToCompassDirection($data->wind_dir_last) }}
+ Temperature: {{ round(($data->temp-32)*(5/9), 1) }}°C
+ Rain Rate: {{ round($data->rain_rate_last*0.2, 2) }} mm/hr
+ Humidity: {{ round($data->hum) }}%
diff --git a/resources/views/components/weatherdata.blade.php b/resources/views/components/weatherdata.blade.php deleted file mode 100644 index 28e163d..0000000 --- a/resources/views/components/weatherdata.blade.php +++ /dev/null @@ -1,68 +0,0 @@ - "http://weather.diskfloppy.me/data/weatherData.json", - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => "", - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 300, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => "GET", -]); - -$current_response = curl_exec($curl_current); -$err = curl_error($curl_current); - -curl_close($curl_current); - -$curl_current = curl_init(); - -curl_setopt_array($curl_current, [ - CURLOPT_URL => "http://weather.diskfloppy.me/data/got.txt", - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => "", - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 300, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => "GET", -]); - -$last_update = curl_exec($curl_current); -$err = curl_error($curl_current); - -curl_close($curl_current); - -if ($err) { - die("cURL Error: " . $err); -} -$current_response = json_decode($current_response, true); -$weather_data = $current_response['data']['conditions'][0]; -$windDirDeg = $weather_data['wind_dir_last']; -$windDir = ""; -// W I N D -if (349 <= $windDirDeg || $windDirDeg <= 11) { $windDir = "N"; } -else if (12 <= $windDirDeg && $windDirDeg <= 33) { $windDir = "NNE"; } -else if (34 <= $windDirDeg && $windDirDeg <= 56) { $windDir = "NE"; } -else if (57 <= $windDirDeg && $windDirDeg <= 78) { $windDir = "ENE"; } -else if (79 <= $windDirDeg && $windDirDeg <= 101) { $windDir = "E"; } -else if (102 <= $windDirDeg && $windDirDeg <= 123) { $windDir = "ESE"; } -else if (124 <= $windDirDeg && $windDirDeg <= 146) { $windDir = "SE"; } -else if (147 <= $windDirDeg && $windDirDeg <= 168) { $windDir = "SSE"; } -else if (169 <= $windDirDeg && $windDirDeg <= 191) { $windDir = "S"; } -else if (192 <= $windDirDeg && $windDirDeg <= 213) { $windDir = "SSW"; } -else if (214 <= $windDirDeg && $windDirDeg <= 236) { $windDir = "SW"; } -else if (237 <= $windDirDeg && $windDirDeg <= 258) { $windDir = "WSW"; } -else if (259 <= $windDirDeg && $windDirDeg <= 281) { $windDir = "W"; } -else if (282 <= $windDirDeg && $windDirDeg <= 303) { $windDir = "WNE"; } -else if (304 <= $windDirDeg && $windDirDeg <= 326) { $windDir = "NW"; } -else if (327 <= $windDirDeg && $windDirDeg <= 348) { $windDir = "WNW"; } - -?> -

Local Weather (Last Update: {{ gmdate('H:i Y-m-d', intval(rtrim($last_update))) }})

- Wind Speed: {{ $weather_data['wind_speed_last'] }} mph
- Wind Direction: {{ $weather_data['wind_dir_last']}}°, {{ $windDir }}
- Temperature: {{ round(($weather_data['temp']-32)*(5/9), 1) }}°C
- Rain Rate: {{ round($weather_data['rain_rate_last']*0.2, 2) }} mm/hr
- Humidity: {{ round($weather_data['hum']) }}%
diff --git a/resources/views/pages/home.blade.php b/resources/views/pages/home.blade.php index 0e84e10..9612685 100644 --- a/resources/views/pages/home.blade.php +++ b/resources/views/pages/home.blade.php @@ -9,7 +9,7 @@ @include('components.lastfm') - @include('components.weatherdata') + @include('components.weather')

Contact

Mail: contact@diskfloppy.me
-- cgit v1.2.3-54-g00ecf