Advertisement
Halbheld

ISS Spotter Script

Feb 6th, 2024
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 KB | Science | 0 0
  1. <html>
  2. <head><title>ISS Spotter</title></head>
  3.  
  4. <body>
  5. <?php
  6.  
  7. /*
  8. Title: ISS Spotter Script
  9.  
  10. Abstract: This PHP script is designed to track the International Space
  11. Station (ISS) using NASA's Spot the Station data. It fetches XML data
  12. from NASA's specified URL, which contains information about the ISS's
  13. passing times over a specific location (in this case, Remscheid, Germany).
  14. The script uses cURL to retrieve this data and then parses it using
  15. SimpleXMLElement. It extracts and formats relevant information such as
  16. passing date, time, duration, and maximum elevation of the ISS. The script
  17. then calculates the timestamp for the next ISS pass and sets up a shell
  18. command to trigger an external script ('iss-fader.sh') that will execute
  19. corresponding actions (e.g., lighting control) at the right time. This
  20. setup provides a user-friendly interface to display the next ISS passing
  21. time and other details on a web page. It's a unique way to engage with
  22. space through web technology.
  23. */
  24.      
  25.    
  26. $url = "https://spotthestation.nasa.gov/sightings/xml_files.cfm?filename=Germany_None_Remscheid.xml";
  27.  
  28. $ch = curl_init();
  29. curl_setopt($ch, CURLOPT_URL, "$url");
  30. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  31. $output = curl_exec($ch);
  32. curl_close($ch);
  33.  
  34. $jetzt = time();
  35.  
  36. $iss = new SimpleXMLElement($output);
  37.  
  38. foreach ($iss->channel->item as $flug) {
  39.     $desc = $flug->description;
  40.         $zeilen = explode("<br/>", $flug->description);
  41.  
  42.         $zeilen[0] = str_replace("Date: ", "", $zeilen[0]);
  43.         $zeilen[1] = str_replace("Time: ", "", $zeilen[1]);
  44.  
  45.         $zeit = "$zeilen[0] $zeilen[1]";
  46.         $dauer = $zeilen[2];
  47.         $max = $zeilen[3];
  48.  
  49.         $timestamp = strtotime($zeit);
  50.         if ($timestamp > $jetzt) {break;}
  51. }
  52.  
  53.  
  54.  
  55. if ($timestamp < $jetzt) {echo "Kein ISS Pass in der Zukunft gefunden. <a href=\"$url\">NASA</a>"; die;}
  56.  
  57. $dauer = preg_replace("/[^0-9]/","",$dauer);
  58. $dauer = $dauer * 60;
  59.  
  60. $max = str_replace("Maximum Elevation: ", "", $max);
  61. $max = substr($max, 0, -3);
  62.  
  63. // DEBUG
  64. //$dauer = 10;
  65. //$timestamp = $jetzt + $dauer;
  66. // DEBUG
  67.  
  68. $output = shell_exec("nohup /bin/bash /path/to/iss-fader.sh $dauer $timestamp > /dev/null 2>&1 &");
  69.  
  70.  
  71. echo "iss-fader.sh f&uuml;r <b>$zeit</b> ($timestamp).<br><a href=\"$url\">Dauer $dauer s, maximale H&ouml;he $max&deg;</a><br><br>";
  72. echo "$desc<br><br>";
  73.  
  74. //$output = shell_exec("ps aux | grep '[iss]-fader' | wc -l");
  75. // 2 Zeilen bedeutet, dass diese Instanz läuft UND eine andere. Abbrechen!
  76. //if ($output >= 1) {
  77. //  echo '<b>Abbruch! Programm wartet bereits.</b><br>';
  78.     $countdown = ($timestamp - $jetzt) / 60;
  79.     $countdown = round($countdown, 1);
  80.     echo "<br>T-$countdown min";
  81.     $countdown = $countdown / 60;
  82.     $countdown = round($countdown, 1);
  83.     echo "/$countdown h";
  84.  
  85.  
  86.         ob_flush();
  87.         flush();
  88.     sleep(1);
  89.     $output = shell_exec("ps aux | grep '[iss]-fader'");
  90.     echo "<pre>USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND\n$output</pre>";
  91. //  }
  92.  
  93.    
  94. ?>
  95. </body></html>
Tags: iss hue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement