diff options
Diffstat (limited to 'resources/views/components')
-rw-r--r-- | resources/views/components/lastfm.blade.php | 67 | ||||
-rw-r--r-- | resources/views/components/weatherdata.blade.php | 68 |
2 files changed, 135 insertions, 0 deletions
diff --git a/resources/views/components/lastfm.blade.php b/resources/views/components/lastfm.blade.php new file mode 100644 index 0000000..78c5f81 --- /dev/null +++ b/resources/views/components/lastfm.blade.php @@ -0,0 +1,67 @@ +<?php +$cfg = app('config')->get('services')['lastfm']; + +$curl_current = curl_init(); + +curl_setopt_array($curl_current, [ + CURLOPT_URL => "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=".$cfg['user']."&nowplaying=true&format=json&api_key=".$cfg['key'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + 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); + +if ($err) { + die("cURL Error #:" . $err); +} +$current_response = json_decode($current_response, true); +$nowplaying = $current_response['recenttracks']['track'][0]; + + +$tracks_to_show = 10; + +$curl = curl_init(); +curl_setopt_array($curl, [ + CURLOPT_URL => "https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=".$cfg['user']."&format=json&period=7day&api_key=".$cfg['key'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "GET", +]); + +$toptracks = curl_exec($curl); +$err = curl_error($curl); +curl_close($curl); +if ($err) { + die("cURL Error #:" . $err); +} + +$toptracks = json_decode($toptracks, true); +$tracks = $toptracks['toptracks']['track']; +$count = 0; +?> + +<h1>Last.fm <small>(<a href="https://www.last.fm/user/{{ $cfg['user']}}">Profile</a>)</small></h1> + <b>Last/Current Track:</b> <a href="{{ $nowplaying['url'] }}">{{ $nowplaying['name'] }} • {{ $nowplaying['artist']['#text'] }}</a> + <h2>Top {{ $tracks_to_show }} Tracks (Last 7 days)</h2> + <ol> +@foreach ($tracks as $track) + @if ($count >= $tracks_to_show) + </ol> + @break + @endif + <li> + <a href="{{ $track['url'] }}">{{ $track['name'] }} • {{ $track['artist']['name'] }}</a> + <small>({{$track['playcount']}} plays)</small> + </li> +<?php $count++ ?> +@endforeach diff --git a/resources/views/components/weatherdata.blade.php b/resources/views/components/weatherdata.blade.php new file mode 100644 index 0000000..28e163d --- /dev/null +++ b/resources/views/components/weatherdata.blade.php @@ -0,0 +1,68 @@ +<?php + +$curl_current = curl_init(); + +curl_setopt_array($curl_current, [ + CURLOPT_URL => "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"; } + +?> +<h1>Local Weather <small>(Last Update: {{ gmdate('H:i Y-m-d', intval(rtrim($last_update))) }})</small></h1> + <b>Wind Speed:</b> {{ $weather_data['wind_speed_last'] }} mph<br> + <b>Wind Direction:</b> {{ $weather_data['wind_dir_last']}}°, {{ $windDir }}<br> + <b>Temperature:</b> {{ round(($weather_data['temp']-32)*(5/9), 1) }}°C<br> + <b>Rain Rate:</b> {{ round($weather_data['rain_rate_last']*0.2, 2) }} mm/hr<br> + <b>Humidity:</b> {{ round($weather_data['hum']) }}%<br> |