Weather
Contents |
Awesome 2
w3m and bash
You'll need: w3m, a tb_weather textbox and an internet-connection...
#!/bin/bash
if [ $# -ne 1 ]; then
echo Usage: $(basename $0) city
exit 1
fi
CITY=$1
FILE=$(mktemp)
w3m -dump "http://www.google.com/search?hl=en&q=${CITY}+weather" > $FILE
FIRST=$(grep -n iGoogle $FILE | awk -F ":" {'print $1'})
FIRST=$((FIRST+1))
LAST=$((FIRST+14))
sed -n -i "$FIRST,$LAST p" $FILE
TEMP=$(sed -n "1 p" $FILE)
WIND=$(sed -n "2 p" $FILE)
HUM=$(sed -n "3 p" $FILE)
SUN=$(sed -n "5 p" $FILE)
MIN_MAX=$(sed -n "6 p" $FILE | awk {'print $4$5" - "$1$2'})
MIN_MAX_TOMORROW=$(sed -n "9 p" $FILE | awk {'print $4$5" - "$1$2'})
SUN_TOMORROW=$(sed -n "8 p" $FILE)
echo 0 widget_tell tb_weather $SUN, $TEMP"("$MIN_MAX") - " $WIND --- Tomorrow: $SUN_TOMORROW, $MIN_MAX_TOMORROW | awesome-client
rm ${FILE}
This is a "skeleton", you can modify this script.
--Uzsolt
bash script with wget for awesome 2.3
Here's another example:
#!/bin/bash # this script is for awesome 2.3 LOCATION=KNYC # station list at: http://www.rap.ucar.edu/weather/surface/stations.txt while true; do if [ -S ~/.awesome_ctl.0 ]; then while true; do NEW=$(wget -qO- "http://www.weather.gov/data/current_obs/${LOCATION}.xml"\ | sed -nr '/<(weather|temp_f)>/s/.*>(.*)<.*/\1/p' 2>/dev/null) if [ "x$NEW" != x ]; then NEW=$(echo "$NEW" | awk 'BEGIN{RS="";FS="\n"}{printf "%s %s\xb0",$1,$2}') echo -e "0 widget_tell mystatusbar weather text $NEW" echo "" # an empty line flushes data inside awesome fi sleep 600 done | awesome-client else sleep 1 fi done
--Profjim 16:19, 1 July 2008 (UTC)
Perl
This is a Perl example for XML weather from http://weather.com, you can change it.
#!/usr/bin/perl
use XML::Simple;
use LWP::Simple;
use strict;
use warnings;
my $wea=XMLin(get('http://xoap.weather.com/weather/local/RSXX0091?cc=*&unit=m'));
my $tmp=$wea->{'cc'}->{'tmp'};
my $t=$wea->{'cc'}->{'t'};
$t=~s/Light Rain Shower/LRS/;
$t=~s/Light Rain/LR/;
$t=~s/Light Snow Shower/LSS/;
$t=~s/Light Snow/LS/;
$t=~s/Light Freezing Rain/LFR/;
$t=~s/Light/L/;
$t=~s/Cloudy/C/;
$t=~s/Windy/W/;
#$t=~s/and/&/;
$t=~s/Partly/P/;
$t=~s/Mostly/M/;
if (length($t)<=4) { $t=~s/ //g;}
my $bar=$wea->{'cc'}->{'bar'}->{'r'};
$bar*=0.75006; //converts to mmHg
$bar=sprintf("%d",$bar);
my $wind=$wea->{'cc'}->{'wind'}->{'s'};
$wind/=3.6; //converts to m/s and rounds it to nearest integer.
$wind+=0.5;
$wind=sprintf("%d",$wind);
my $dir=$wea->{'cc'}->{'wind'}->{'t'};
print $tmp . "°C, " . $bar . " mmHg, " . $wind . " m/s, " . $dir . ", " . $t . "\n";
--IoGA 15:22, 17 November 2008 (UTC)
Awesome 3
Yahoo Weather
Widget set, naughty notification, nice icon updating at forecast change and day/night cycle, localization support.
See https://github.com/copycat-killer/yawn
--Luke Bonham 18:00:00, 22 April 2013 (CEST)
Google API + awful
I wrote a solution that makes a simple HTTP request to Google's Weather API based on postal code. See https://github.com/jesseadams/weather
--Jesseadams 06:15:38, 06 June 2011 (UTC)
Google API + libxslt + Naughty
Another solution, which shows Naughty notifications on mouse_hover at your widget (I use it for my text clock). Data is taken from Google API using query string, such as town name, postal code, etc. Futher reading at github
--IoGA 11:02, 7 August 2011 (CEST)
weather-util, awk, naughty and awful
This widget uses Naughty, awful, awk, the internet, and the commandline program "weather-util", which is also in the Debian, Ubuntu and Archlinux repositories. The widget creates a simple text box with the temperature, which you can hover over to get the full weather information.
Replace METARID with the metar ID of the weather station for your area. this is a four letter code like LYBE for Belgrade, Serbia. Stations list at [1]
--Create a weather widget
weatherwidget = widget({ type = "textbox" })
weatherwidget.text = awful.util.pread(
"weather -i METARID --headers=Temperature --quiet -m | awk '{print $2, $3}'"
) -- replace METARID with the metar ID for your area. This uses metric. If you prefer Fahrenheit remove the "-m" in "--quiet -m".
weathertimer = timer(
{ timeout = 900 } -- Update every 15 minutes.
)
weathertimer:add_signal(
"timeout", function()
weatherwidget.text = awful.util.pread(
"weather -i METARID --headers=Temperature --quiet -m | awk '{print $2, $3}' &"
) --replace METARID and remove -m if you want Fahrenheit
end)
weathertimer:start() -- Start the timer
weatherwidget:add_signal(
"mouse::enter", function()
weather = naughty.notify(
{title="Weather",text=awful.util.pread("weather -i METARID -m")})
end) -- this creates the hover feature. replace METARID and remove -m if you want Fahrenheit
weatherwidget:add_signal(
"mouse::leave", function()
naughty.destroy(weather)
end)
-- I added some spacing because on my computer it is right next to my clock.
awful.widget.layout.margins[weatherwidget] = { right = 5 }
Now add the widget in with your other widgets, for example left of the text clock:
mywibox[s].widgets = {
...
mytextclock,
weatherwidget,
...
--Pthalo 22:35, 12 April 2011 (UTC)