From 45fd1d23c4b22d0b1bbd070d799ad3e6f274a8e5 Mon Sep 17 00:00:00 2001 From: Frankie B Date: Sun, 2 Jul 2023 02:01:54 +0100 Subject: feat: update lastfm & weather to use internal API --- resources/views/components/lastfm.blade.php | 15 ++++++------- resources/views/components/weather.blade.php | 32 +++++++++++++++------------- 2 files changed, 24 insertions(+), 23 deletions(-) (limited to 'resources/views/components') diff --git a/resources/views/components/lastfm.blade.php b/resources/views/components/lastfm.blade.php index 92b2c9c..75ec064 100644 --- a/resources/views/components/lastfm.blade.php +++ b/resources/views/components/lastfm.blade.php @@ -1,26 +1,25 @@ @php $cfg = app('config')->get('services')['lastfm']; +$api_root = app('config')->get('app')['api_root']; -$current_response = json_decode(file_get_contents("https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=".$cfg['user']."&nowplaying=true&format=json&api_key=".$cfg['key'])); -$nowplaying = $current_response->recenttracks->track[0]; -$toptracks = json_decode(file_get_contents("https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=".$cfg['user']."&format=json&period=7day&api_key=".$cfg['key'])); -$tracks = $toptracks->toptracks->track; +$current_track = json_decode(file_get_contents($api_root.'/lastfm/current')); +$toptracks = json_decode(file_get_contents($api_root.'/lastfm/top')); $count = 0; @endphp

Last.fm (Profile)

- Last/Current Track: {{ $nowplaying->name }} • {{ $nowplaying->artist->{"#text"} }} + Last/Current Track: {{ $current_track->name }} • {{ $current_track->artist }}

Top {{ $cfg['toptracks'] }} Tracks (Last 7 days)

    -@foreach ($tracks as $track) +@foreach ($toptracks as $track) @if ($count >= $cfg['toptracks'])
@break @endif
  • - {{ $track->name }} • {{ $track->artist->name }} - ({{ $track->playcount }} plays) + {{ $track->name }} • {{ $track->artist }} + ({{ $track->plays }} plays)
  • @php $count++ @endphp @endforeach diff --git a/resources/views/components/weather.blade.php b/resources/views/components/weather.blade.php index 2aa2ebb..a5a041f 100644 --- a/resources/views/components/weather.blade.php +++ b/resources/views/components/weather.blade.php @@ -1,20 +1,22 @@ @php - function degreesToCompassDirection($degrees) { - $cardinalDirections = [ - 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', - 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N' - ]; - return $cardinalDirections[round($degrees*16/360)]; - } +$api_root = app('config')->get('app')['api_root']; - $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]; +function degreesToCompassDirection($degrees) { + $cardinalDirections = [ + 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', + 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N' + ]; + return $cardinalDirections[round($degrees*16/360)]; +} + +$data = json_decode(file_get_contents($api_root.'/weather')); +$updated = gmdate('H:i Y-m-d', $data->updated); +$data = $data->data; @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) }}%
    + Wind Speed:     {{ $data->wind->speed }} mph
    + Wind Direction: {{ $data->wind->direction->degrees }}°, {{ $data->wind->direction->cardinal }}
    + Temperature:    {{ $data->temperature }}°C
    + Rain Rate:      {{ $data->rain_rate }} mm/hr
    + Humidity:       {{ $data->humidity }}%
    -- cgit v1.2.3-54-g00ecf