From ff943ce2971c699ae1d9ed0ef6a234c8fe20b277 Mon Sep 17 00:00:00 2001
From: krzys-h <krzys_h@interia.pl>
Date: Sun, 22 Sep 2024 13:54:25 +0200
Subject: [PATCH] notification-spacex: migrate from spacexdata to launchlibrary

api.spacexdata.com is no longer updated
---
 .../notification-spacex/notification-spacex.sh     | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/polybar-scripts/notification-spacex/notification-spacex.sh b/polybar-scripts/notification-spacex/notification-spacex.sh
index 2337a4ff..854c4cdd 100644
--- a/polybar-scripts/notification-spacex/notification-spacex.sh
+++ b/polybar-scripts/notification-spacex/notification-spacex.sh
@@ -1,14 +1,18 @@
 #!/bin/sh
 
-spacex_launch=$(curl -sf https://api.spacexdata.com/v5/launches/next)
+spacex_launch=$(curl -sf "https://ll.thespacedevs.com/2.2.0/launch/upcoming/?lsp__name=SpaceX&status__ids=1&limit=1")
 
 if [ -n "$spacex_launch" ]; then
-    spacex_precision=$(echo "$spacex_launch" | jq -r '.date_precision' )
-    spacex_timestamp=$(echo "$spacex_launch" | jq -r '.date_unix' )
+    spacex_precision=$(printf "%s" "$spacex_launch" | jq -r '.results[0].net_precision.abbrev' )
+    spacex_timestamp=$(date +"%s" --date "$(printf "%s" "$spacex_launch" | jq -r '.results[0].net' )")
     spacex_duration=$((spacex_timestamp - $(date +%s)))
 
-    if [ "$spacex_precision" = "hour" ] && [ "$spacex_duration" -lt 43200 ] && [ "$spacex_duration" -gt 0 ]; then
-        echo "# $(date +"%H:%M" -u --date @$spacex_duration)"
+    if [ "$spacex_precision" = "HR" ] || [ "$spacex_precision" = "MIN" ] || [ "$spacex_precision" = "SEC" ]; then
+        if [ "$spacex_duration" -lt 43200 ] && [ "$spacex_duration" -gt 0 ]; then
+            echo "# $(date +"%H:%M" -u --date @$spacex_duration)"
+        else
+            echo ""
+        fi
     else
         echo ""
     fi