Src/0000775000175000017500000000000012451634013012116 5ustar profzoomprofzoomSrc/weather.pl0000775000175000017500000001667012451633773014143 0ustar profzoomprofzoom#!/usr/bin/perl # # Copyright # # Copyright (C) 2002,2010 Thibaut Colar # # License # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # Description # # See http://www.colar.net # # The Weather data can be retrieved through http of ftp. Http is # faster, however this might get broken if NOAA change their # webpage layout in wich case you should choose ftp. $mode="http"; # html || ftp $debug = 0; # turn On/Off debugging sub debug ($) { my ($str) = @_; if ( $debug ) { print "$str\n"; } } ######################################## # Start: ######################################## ($station, $tmpfolder) = @ARGV; debug("station: $station ; tmpfolder: $tmpfolder"); mkdir $tmpfolder; $html = "http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=${station}"; $ftp = "ftp://weather.noaa.gov/data/observations/metar/stations/${station}.TXT"; $url = $html; if ( $mode eq "ftp" ) { $url = $ftp; } # Change this line if wget isn't in your path: system "wget -q -O $tmpfolder/${station}_dat $url"; $line = ""; $file = "$tmpfolder/${station}_dat"; open DATA, "<", $file; # Not used: $allGood = 0; if ( $mode eq "http" ) { while ( (! ($line =~ m/START BODY OF TEXT HERE/)) and not eof DATA) { $line = ; } $i = 0; while ( $i != 21 and not eof DATA ) { $line = ; $i++; } } if ( eof DATA ) { debug("Unreadable HTML source, no point going any further, stopping\n"); exit 0; } $line = ; chomp $line; $time = (split /\ /, $line)[1]; ($hour, $minute) = split /:/, $time; $line = ""; if ( $mode eq "http" ) { $i = 0; while ( $i != 8 ) { $line = ; $i++; } } $newLine = ; $line .= $newLine; chomp $line; $line =~ s/
//; $line = "METAR $station $line"; close DATA; chomp $line; @args = split /\ /, $line; debug("line: $line"); debug("args: @args"); debug("line: $line"); $i = 0; $station = $args[$i]; if ( $station eq 'METAR' or $station eq 'SPECI' ) { $station = $args[$i+1]; $i++ } $i++; # date (ln 1) $i++; # time (ln 1) $i++; # station (ln 2) $i++; # datetime (ln 2) $wind = $args[$i]; if ( $wind eq 'AUTO' ) { $wind = $args[$i+1]; $i++; } debug("wind: $wind"); $i++; $visibility = $args[$i]; $i++; # Visibility debug("vis: $visibility"); #unless( $visibility =~ m/SM/ or $visibility eq "CAVOK" or $visibility eq "9999" ) #{ # $i++; # visibility with fractions, not using #} $next = $args[$i]; if ( $next =~ m/\// ) { $i++; # fractional visibility, skipping } $weather = ""; $clouds = " "; while ( not $args[$i] =~ /\// and $i < @args ) { $intensity = ""; $desc = ""; $precip = ""; $obsc = ""; $misc = ""; $j = 0; $curent = $args[$i]; $wasCloud = "no"; debug("cur : $curent"); if ( $curent =~ /^CAVOK/ ) { $clouds .= "CAVOK,0;"; $wasCloud = "yes"; } if ( $curent =~ /^VV/ ) { $clouds .= "VV,".substr($curent,2,3).";"; # Not used: $wasNotCloud = "yes"; } if ( $curent =~ /^CLR/ or $curent =~ /^SCK/ or $curent =~ /^FEW/ or $curent =~ /^SCT/ or $curent =~ /^BKN/ or $curent =~ /^OVC/ ) { $clouds .= substr($curent, 0, 3) . "," . substr($curent, 3, 3) . ";" ; $wasCloud = "yes"; } if ( $wasCloud ne "yes") { if ( length $curent > 0 ) { if ( $curent =~ /^\-/ ) # Should be weather { $intensity = "-"; $j = 1; } if ( $curent =~ /^\+/ ) { $intensity="+"; $j = 1; } if ( $curent =~ /^VC/ ) { $j = 2; } $curent = substr $curent, $j; if ( $curent =~ /^MI/ or $curent =~ /^PR/ or $curent =~ /^BC/ or $curent =~ /^DR/ or $curent =~ /^BL/ or $curent =~ /^SH/ or $curent =~ /^TS/ or $curent =~ /^FZ/ ) { $desc = substr $curent, 0, 2; $curent = substr $curent, 2; } if ( $curent=~/^DZ/ or $curent=~/^RA/ or $curent=~/^SN/ or $curent=~/^SG/ or $curent=~/^IC/ or $curent=~/^PE/ or $curent=~/^GR/ or $curent=~/^GX/ or $curent=~/^UP/ ) { $precip = substr $curent, 0, 2; $curent = substr $curent, 2; } if ( $curent=~/^BR/ or $curent=~/^FG/ or $curent=~/^FU/ or $curent=~/^VA/ or $curent=~/^DU/ or $curent=~/^SA/ or $curent=~/^HZ/ or $curent=~/^PY/ ) { $obsc = substr $curent, 0, 2; $curent = substr $curent, 2; } if ( $curent=~/^PO/ or $curent=~/^SQ/ or $curent=~/^FC/ or $curent=~/^SS/ ) { $misc = substr $curent, 0, 2; } $weather .= "$intensity,$desc,$precip,$obsc,$misc;" ; } } $i++; } ($temp, $dew) = split /\//, $args[$i]; $dir = substr $wind, 0, 3; $speed = substr $wind, 3, 2; if ( $wind =~ /G/ ) { $gust = substr $wind, 6, 2; $windUnit = substr $wind, 8, length $wind; } else { $windUnit = substr $wind, 5, length $wind; } if ( length $weather == 0 ) { $weather = ",,,,;" ; } if ( length $clouds == 0 ) { $clouds = ",,,,;" ; } $temp =~ s/M/-/g; $dew =~ s/M/-/g; if ( $hour eq "" ) { $hour = 0; } if ( $minute eq "" ) { $minute = 0; } if ( $speed eq "" ) { $speed = 0; } if ( $dir eq "" ) { $dir = -1; } if ( $gust eq "" ) { $gust = 0; } if ( $temp eq "" ) { $temp = 0; $station = ""; } if ( $dew eq "" ) { $dew = "-999"; # makes humidity 0 $station = ""; } debug("Hour:$hour"); debug("Minute:$minute"); debug("Station:$station"); debug("WindDir:$dir"); debug("WindSpeed:$speed"); debug("WindGust:$gust"); debug("Weather:$weather"); debug("Clouds:$clouds"); debug("Temp:$temp"); debug("Dew:$dew"); # Check for ok temperature if ( -f "$tmpfolder/$station" ) { open GREP, "grep Temp $tmpfolder/${station} | "; $templine = ; $templine = ~m/^Temp:(.*)$/; { if ( $temp > -50 and $temp < 150 ) { if ( $lasttemp > -50 and $lasttemp < 150 ) { if ( $temp > -2 and $temp < 2 ) { if ( $lasttemp > 7 or $lasttemp < -7 ) { $station = ""; # probably invalid } } } } else { $station = ""; } } close GREP; } debug("Station: $station"); if ( length $station == 4 ) { debug("Data OK"); open FILE, ">", "$tmpfolder/${station}"; print FILE "Hour:$hour\n"; print FILE "Minute:$minute\n"; print FILE "Station:$station\n"; print FILE "WindDir:$dir\n"; print FILE "WindSpeed:$speed\n"; print FILE "WindGust:$gust\n"; print FILE "Weather:$weather\n"; print FILE "Clouds:$clouds\n"; print FILE "Temp:$temp\n"; print FILE "Dew:$dew\n"; close FILE } else { debug("Invalid data, not writing to file, stopping\n"); } # End of file Src/wmfrog.c0000664000175000017500000004642612451633773013613 0ustar profzoomprofzoom/* Thibaut Colar http://www.colar.net/ 2002/05 This is a dockapp wich shows you the weather at a specific location from it's METAR code. If this program blew up your computer it isn't my fault :-) This use a bit of code borrowed from the wmWeather application(originally). To build from src needs libxpm-dev, libx11-dev, libext-dev */ /* * Includes */ #include #include #include #include #include #include #include #include #include #include #include #include "xutils.h" #include "frog.xpm" #include "frog.xbm" /* * Delay between refreshes (in microseconds) */ #define DEBUG 0 #define VERSION "0.3.1" // 5 mn in seconds #define DEFAULT_UPDATEDELAY 300L // max wind in KNOTS #define MAX_WIND 50 #define TIME_OFFSET 0 #define METRIC 0 void ParseCMDLine(int argc, char *argv[]); void ButtonPressEvent(XButtonEvent *); void KeyPressEvent(XKeyEvent *); char *StringToUpper(char *); char *mystrsep(char **stringp, char *delim); char *GetTempDir(char *suffix); void UpdateData(); void Repaint(); struct WeatherStruct { int intensity; char* precip; char* desc; char* obsc; char* misc; char* coverage; int temp; int dew; float humidity; int hour; int min; int wind; int gust; int dir; } weather; char StationID[10]; char Label[20]; int Metric = METRIC; int NeedsUpdate = 1; int maxWind = MAX_WIND; int timeOffset = TIME_OFFSET; long UpdateDelay; char* folder; int needsUpdate = 1; /* * main */ int main(int argc, char *argv[]) { XEvent event; Display *dis; dis = XOpenDisplay((char *) 0); /* * Parse any command line arguments. */ ParseCMDLine(argc, argv); folder = GetTempDir(".wmapps"); initXwindow(argc, argv); openXwindow(argc, argv, frog_xpm, frog_bits, frog_width, frog_height, "#181818", "#79bdbf", "#ff0000", "#ffbf50", "#c5a6ff"); XSelectInput(dis, win, ExposureMask); // Update the data now .... which calls itself back every x seconds (UpdateDelay) using an alarm UpdateData(); while (1) { while (XPending(display)) { XNextEvent(display, &event); switch (event.type) { case Expose: RedrawWindow(); break; } } // check for events 2x seconds to take it easy on cpu usleep(500000); } } void Repaint() { int i, y, q; char chr; /* * Clear window. */ copyXPMArea(0, 64, 56, 56, 4, 4); //clouds if (strcmp(weather.coverage, "FEW") == 0) { copyXPMArea(0, 183, 56, 15, 4, 4); } if (strcmp(weather.coverage, "SCT") == 0) { copyXPMArea(56, 183, 56, 15, 4, 4); } if (strcmp(weather.coverage, "BKN") == 0) { copyXPMArea(112, 183, 56, 15, 4, 4); } if (strcmp(weather.coverage, "OVC") == 0 || strcmp(weather.coverage, "VV") == 0) { copyXPMArea(168, 183, 56, 15, 4, 4); } //obstruction if (strcmp(weather.obsc, "") != 0) { //fog if (strcmp(weather.desc, "BL") == 0) copyXPMArea(56, 90, 56, 26, 4, 34); else if (strcmp(weather.desc, "FZ") == 0) copyXPMArea(112, 90, 56, 26, 4, 34); else copyXPMArea(168, 64, 56, 26, 4, 34); } //precipitation if (strcmp(weather.precip, "DZ") == 0) { copyXPMArea(112, 120, 56, 15, 4, 18); } if (strcmp(weather.precip, "RA") == 0) { if (weather.intensity == 0) copyXPMArea(56, 150, 56, 15, 4, 18); if (weather.intensity < 0) copyXPMArea(0, 150, 56, 15, 4, 18); if (weather.intensity > 0) copyXPMArea(112, 150, 56, 15, 4, 18); } if (strcmp(weather.precip, "SN") == 0 || strcmp(weather.precip, "SG") == 0) { if (weather.intensity == 0) copyXPMArea(56, 135, 56, 15, 4, 18); if (weather.intensity > 0) copyXPMArea(112, 135, 56, 15, 4, 18); if (weather.intensity < 0) copyXPMArea(0, 135, 56, 15, 4, 18); } if (strcmp(weather.precip, "IC") == 0 || strcmp(weather.precip, "IC") == 0 || strcmp(weather.precip, "IC") == 0 || strcmp(weather.precip, "IC") == 0) { if (weather.intensity == 0) copyXPMArea(56, 166, 56, 16, 4, 18); if (weather.intensity > 0) copyXPMArea(112, 166, 56, 16, 4, 18); if (weather.intensity < 0) copyXPMArea(0, 166, 56, 16, 4, 18); } //descriptor if (strcmp(weather.desc, "BL") == 0 && strcmp(weather.obsc, "") == 0) { copyXPMArea(56, 64, 56, 26, 4, 34); } if (strcmp(weather.desc, "FZ") == 0 && strcmp(weather.obsc, "") == 0) { copyXPMArea(112, 64, 56, 26, 4, 34); } if (strcmp(weather.desc, "TS") == 0) { if (strcmp(weather.precip, "") != 0) copyXPMArea(164, 150, 56, 15, 4, 18); else copyXPMArea(56, 120, 56, 15, 4, 18); } //special if (strcmp(weather.misc, "") != 0) { copyXPMArea(168, 90, 56, 26, 4, 34); copyXPMArea(0, 120, 56, 15, 4, 18); copyXPMArea(168, 183, 56, 16, 4, 4); } //writtings: //clearing: copyXPMArea(170, 20, 25, 17, 29, 44); copyXPMArea(220, 0, 3, 60, 4, 4); copyXPMArea(220, 0, 3, 60, 57, 4); copyXPMArea(220, 0, 3, 60, 4, 4); //humidity y = (weather.humidity * 58) / 100; copyXPMArea(60, 0, 1, y, 4, 60 - y); copyXPMArea(60, 0, 1, y, 5, 60 - y); //wind & gust y = (weather.gust * 58) / maxWind; copyXPMArea(62, 0, 1, y, 58, 60 - y); copyXPMArea(62, 0, 1, y, 59, 60 - y); y = (weather.wind * 58) / maxWind; copyXPMArea(61, 0, 1, y, 58, 60 - y); copyXPMArea(61, 0, 1, y, 59, 60 - y); //station name for (i = 0; i != 4; i++) { chr = (int) Label[i] - 65; copyXPMArea(chr * 5 + 89, 0, 5, 6, 31 + (i * 5), 45); } //time i = weather.hour / 10; copyXPMArea(89 + (i * 5), 7, 5, 6, 30, 53); i = weather.hour - ((weather.hour / 10)*10); copyXPMArea(89 + (i * 5), 7, 5, 6, 35, 53); copyXPMArea(89 + (52), 7, 1, 6, 41, 53); i = weather.min / 10; copyXPMArea(89 + (i * 5), 7, 5, 6, 43, 53); i = weather.min - ((weather.min / 10)*10); copyXPMArea(89 + (i * 5), 7, 5, 6, 48, 53); //temp q = 10; copyXPMArea(136, 30, 17, 9, q - 1, 22); if (weather.temp < 0) { copyXPMArea(90, 30, 3, 7, q, 23); q += 5; } /*if(temp>100) { copyXPMArea(96, 20, 5, 7, q, 23); q+=6; } */ copyXPMArea(136, 30, 17, 9, (q - 1), 22); i = weather.temp; if (i < 0) i = -i; if (i / 100 > 0) { copyXPMArea(96, 20, 5, 7, q, 23); q += 6; i -= 100; } if ((i == 0 && q > 10) || i / 10 > 0 || q > 10) { copyXPMArea(90 + 6 * (i / 10), 20, 5, 7, q, 23); q += 6; } copyXPMArea(90 + 6 * (i - ((i / 10)*10)), 20, 5, 7, q, 23); q += 5; copyXPMArea(95, 29, 5, 7, q, 23); // wind weather.dir if ((weather.dir >= 0 && weather.dir <= 22) || (weather.dir <= 360 && weather.dir > 337)) copyXPMArea(0, 198, 7, 7, 48, 6); if (weather.dir > 22 && weather.dir <= 67) copyXPMArea(42, 198, 7, 7, 48, 6); if (weather.dir > 67 && weather.dir <= 112) copyXPMArea(14, 198, 7, 7, 48, 6); if (weather.dir > 112 && weather.dir <= 157) copyXPMArea(28, 198, 7, 7, 48, 6); if (weather.dir > 157 && weather.dir <= 202) copyXPMArea(7, 198, 7, 7, 48, 6); if (weather.dir > 202 && weather.dir <= 247) copyXPMArea(35, 198, 7, 7, 48, 6); if (weather.dir > 247 && weather.dir <= 292) copyXPMArea(21, 198, 7, 7, 48, 6); if (weather.dir > 292 && weather.dir <= 337) copyXPMArea(49, 198, 7, 7, 48, 6); /* * Make changes visible */ RedrawWindow(); } /* * ParseCMDLine() */ void ParseCMDLine(int argc, char *argv[]) { int i; void print_usage(); StationID[0] = '\0'; UpdateDelay = DEFAULT_UPDATEDELAY; for (i = 1; i < argc; i++) { if ((!strcmp(argv[i], "-metric")) || (!strcmp(argv[i], "-m"))) { Metric = 1; } else if (!strcmp(argv[i], "-w")) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "You must give a max wind value with the -w option.\n"); print_usage(); exit(-1); } else if (sscanf(argv[i + 1], "%d", &maxWind) != 1) { fprintf(stderr, "Don't understand the max wind value have entered (%s).\n", argv[i + 1]); print_usage(); exit(-1); } } else if (!strcmp(argv[i], "-o")) { if ((i + 1 >= argc)) { fprintf(stderr, "You must give a time offset value with the -t option.\n"); print_usage(); exit(-1); } else if (sscanf(argv[i + 1], "%d", &timeOffset) != 1) { fprintf(stderr, "Don't understand the time offset value have entered (%s).\n", argv[i + 1]); print_usage(); exit(-1); } } else if (!strcmp(argv[i], "-tmp")) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "-tmp option invalid.\n"); print_usage(); exit(-1); } strcpy(folder, argv[++i]); } else if ((!strcmp(argv[i], "-station")) || (!strcmp(argv[i], "-s"))) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "No METAR station ID found\n"); print_usage(); exit(-1); } strcpy(StationID, StringToUpper(argv[++i])); strcpy(Label, StationID); } else if (!strcmp(argv[i], "-delay")) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "You must give a time with the -delay option.\n"); print_usage(); exit(-1); } else if (sscanf(argv[i + 1], "%ld", &UpdateDelay) != 1) { fprintf(stderr, "Don't understand the delay time you have entered (%s).\n", argv[i + 1]); print_usage(); exit(-1); } /* * Convert Time to seconds */ UpdateDelay *= 60; ++i; } else if (!strcmp(argv[i], "-l")) { if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) { fprintf(stderr, "You must give a station label name.\n"); print_usage(); exit(-1); } strcpy(Label, StringToUpper(argv[++i])); } } if (StationID[0] == '\0') { fprintf(stderr, "\nYou must specify a METAR station code\n\n"); print_usage(); exit(1); } } void print_usage() { printf("\nwmfrog version: %s\n", VERSION); printf("\nusage: wmfrog -s [-h] [-w ] [-t