From d7f4e6cdc9693e58733f67168a1fe84f0c805507 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Wed, 14 Dec 2022 12:55:45 -0700 Subject: Rewrite xmobar-weather in Haskell. This adds a new binary that replaces the jenky Perl weather script. In addition this switches the weather source to wttr.in. Before it would always pull the weather from the same weather station, which is not what I want. --- extras/HOME/.xmonad/xmobar-weather | 103 ------------------------------------- 1 file changed, 103 deletions(-) delete mode 100755 extras/HOME/.xmonad/xmobar-weather (limited to 'extras') diff --git a/extras/HOME/.xmonad/xmobar-weather b/extras/HOME/.xmonad/xmobar-weather deleted file mode 100755 index b95fadb..0000000 --- a/extras/HOME/.xmonad/xmobar-weather +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/perl - -use Time::Local; -use POSIX; - -$content = `curl https://ipinfo.io`; - -die "Unable to get IP info" unless defined $content; - -($city, $lat, $lon) = - ($content =~ m/.*"city":\s+"([^"]+)".*"loc":\s+"(-?[0-9.]+),(-?[0-9.]+).*"/ims); - -$content = `curl "https://api.sunrise-sunset.org/json?lat=$lat&lng=$lon&formatted=0"`; - -die "Unable to get sunrise/sunset data" unless defined $content; - -if (length($content) == 0) { - printf(" "); - exit -} - -$sunrise_str=$content; -$sunset_str=$content; -$sunrise_str =~ s#.*"sunrise":"([^"]*)".*#\1#; -$sunset_str =~ s#.*"sunset":"([^"]*)".*#\1#; -$current_str=strftime "%Y-%m-%dT%H:%M:%S+00:00", gmtime(); - -$content = `curl "https://tgftp.nws.noaa.gov/data/observations/metar/decoded/KLMO.TXT"`; - -die "Unable to get weather data" unless defined $content; - -$sky_conditions = $content; -$sky_conditions =~ s#.*Sky conditions:\s+([^\n]+).*#\1#ims; -$sky_conditions =~ s#\s#_#g; - -$wind = $content; -$wind =~ s#.*Wind:\s+([^\n]+).*#\1#ims; -($wind_direction, $wind_speed) = - ($wind =~ m/from the ([A-Z]+).*at (\d+) MPH.*/g); - - -$temp = $content; -$temp =~ s#.*Temperature:\s+(-?[0-9.]+) F.*#\1#ims; - -if ($current_str gt $sunrise_str and $current_str lt $sunset_str) { - $is_day = 1; -} else { - $is_day = 0; -} - -%directions = ( - NE => "", - NNE => "", - ENE => "", - SE => "", - SSE => "", - ESE => "", - NW => "", - NNW => "", - WNW => "", - SW => "", - SSW => "", - WSW => "", - N => "", - S => "", - W => "", - E => "" ); - -$dir=%directions{$wind_direction}; - -%conditions_day = ( - clear => " ", - sunny => " ", - mostly_clear => " ", - mostly_sunny => " ", - partly_sunny => " ", - fair => "🌑 ", - cloudy =>"摒 ", - overcast =>" ", - partly_cloudy => "杖 ", - mostly_cloudy => " ", - considerable_cloudiness => "ﭽ " ); - -%conditions_night = ( - clear => " ", - sunny => " ", - mostly_clear => " ", - mostly_sunny => " ", - partly_sunny => " ", - fair => "🌑 ", - cloudy =>"摒 ", - overcast =>" ", - partly_cloudy => " ", - mostly_cloudy => " ", - considerable_cloudiness => "ﭽ " ); - -if ($is_day) { - $conditions = %conditions_day{$sky_conditions}; -} else { - $conditions = %conditions_night{$sky_conditions}; -} - -printf("$city $dir ${wind_speed} $conditions%.0f°F\n", $temp); -- cgit