openbsd-ports/astro/wmspaceweather/patches/patch-GetKp
2022-03-11 18:17:37 +00:00

80 lines
2.4 KiB
Plaintext

Index: wmSpaceWeather/GetKp
--- wmSpaceWeather/GetKp.orig
+++ wmSpaceWeather/GetKp
@@ -5,21 +5,33 @@
#
- require "ctime.pl";
+ use Time::CTime;
+ #
+ # Change to users home directory. We used to dump into /tmp
+ # but using home dir instead avoids multiple users interfering
+ # with one another. (Yeah, we could "unique-ize" the filenames, but
+ # this is easier for now...)
+ #
+ $home = (getpwuid($<))[7];
+ $ok = chdir() || chdir($home);
- ($Year, $Month, $Day) = &year_month_day();
-
- if (-e "/tmp/DGD.txt"){
- unlink("/tmp/DGD.txt");
+ #
+ # Check to see if .wmSpaceWeatherReports exists.
+ # If not, make it and move to it.
+ #
+ if ( !(-e ".wmSpaceWeatherReports") ){
+ mkdir(".wmSpaceWeatherReports", 0775);
}
+ chdir(".wmSpaceWeatherReports");
+ unlink("daily-geomagnetic-indices.txt");
+ unlink("current-space-weather-indices.txt");
- if (-e "/tmp/curind.txt"){
- unlink("/tmp/curind.txt");
- }
+ ($Year, $Month, $Day) = &year_month_day();
- $grabcmd = "cd /tmp; wget --passive-ftp --tries 2 -q ftp://www.sec.noaa.gov/pub/indices/DGD.txt";
+
+ $grabcmd = "ftp -V https://services.swpc.noaa.gov/text/daily-geomagnetic-indices.txt";
system "$grabcmd";
@@ -37,7 +49,7 @@
$Kp{190001018} = 999;
- open(TmpFile, "/tmp/DGD.txt");
+ open(TmpFile, "daily-geomagnetic-indices.txt");
while (<TmpFile>){
chop;
if ($_ =~ /^\d{4} \d{2} \d{2}\s*\d*/ ){
@@ -68,12 +80,12 @@
#
# Add in very latest stuff
#
- $grabcmd = "cd /tmp; wget --passive-ftp --tries 2 -q ftp://www.sec.noaa.gov/pub/latest/curind.txt";
+ $grabcmd = "ftp -V https://services.swpc.noaa.gov/text/current-space-weather-indices.txt";
system "$grabcmd";
%lmonstr = ( "Jan", 1, "Feb", 2, "Mar", 3, "Apr", 4, "May", 5, "Jun", 6, "Jul", 7, "Aug", 8, "Sep", 9, "Oct", 10, "Nov", 11, "Dec", 12);
@lval = ($lyear, $lmonstr{$lmon}, $ldom);
- open(TmpFile, "/tmp/curind.txt");
+ open(TmpFile, "current-space-weather-indices.txt");
while (<TmpFile>){
chop;
if ($_ =~ /^:Geomagnetic_Values: (\d{4}) (.*) (\d{1,2})/){
@@ -133,7 +145,7 @@
}
}
- open(TmpFile, ">/tmp/LatestKp.txt");
+ open(TmpFile, ">LatestKp.txt");
foreach $key (sort keys %Result ) {
if ($Result{$key} > 10) { $Result{$key} = -1; }
printf TmpFile "$key $Result{$key}\n";