#  Copyright (c) GPL mmc Mike Chirico
#  Created: Mon Apr 12 21:16:02 EDT 2004
#  Updated: Sun May 16 08:44:04 EDT 2004
#  Thu May  6 17:18:30 EDT 2004
#    o Humidity, Pressure
#  Wed May  5 19:08:53 EDT 2004
#    o Clouds ... they changed it again
#      I still need a more robust fix.
#  Wed May  5 19:08:53 EDT 2004
#    o it's going to take more than a quick
#      fix -- they keep changing the layout
#  Mon May  3 14:05:08 EDT 2004  
#   Sat Apr 17 14:52:43 EDT 2004
#    o clouds they have more varied format
#   Thu Apr 15 23:12:46 EDT 2004
#    o see below 100 my bleed into 2 to give 200 
#    o gust is optional
#  Program to read weather ... so far only reads temperature
#  and displays temp on the delcom USB numeric display
#  Requires LWP cpan utility
#  I guess this can be run in a cron job.
#                               The number below is the zip code ------v
#                 --                                                  
#		  -- Table structure for table `weather`              
#                 --                                                  
#                 DROP TABLE IF EXISTS weather;                       
#		  CREATE TABLE weather (                              
#                   pkey int(11) NOT NULL auto_increment,             
#		    deg float default NULL,                           
#                   humidity float default NULL,                      
#		    dewpt float default NULL,                         
#                   winddir varchar(5) default NULL,                  
#		    windspeed float default NULL,                     
#                   windgust float default NULL,                      
#		    pressure float default NULL,                      
#                   pressurehg int(11) default NULL,                  
#		    pressurevec varchar(10) default NULL,             
#                   conditions varchar(60) default NULL,              
#		    visibility int(11) default NULL,                  
#                   clouds varchar(60) default NULL,                  
#		    cloudsst varchar(10) default NULL,                
#                   cloudheight int(11) default NULL,                 
#		    timeEnter timestamp NOT NULL,                     
#                   PRIMARY KEY  (pkey)                               
#		  ) TYPE=MyISAM DEFAULT CHARSET=latin1;               

use LWP::Simple;
use Fcntl;

sysopen(MINOR, "${filename}minor", O_RDWR)
    or die "Can't open ${filename}minor";
sysopen(LSB, "${filename}lsb", O_RDWR)
    or die "Can't open ${filename}lsb";
sysopen(MSB, "${filename}msb", O_RDWR)
    or die "Can't open ${filename}msb";
sysopen(LENGTH, "${filename}length", O_RDWR)
    or die "Can't open ${filename}length";
sysopen(ZERO, "${filename}zero", O_RDWR)
    or die "Can't open ${filename}zero";
sysopen(ONE, "${filename}one", O_RDWR)
    or die "Can't open ${filename}one";
sysopen(TWO, "${filename}two", O_RDWR)
    or die "Can't open ${filename}two";
sysopen(THREE, "${filename}three", O_RDWR)
    or die "Can't open ${filename}three";
sysopen(FOUR, "${filename}four", O_RDWR)
    or die "Can't open ${filename}four";
sysopen(FIVE, "${filename}five", O_RDWR)
    or die "Can't open ${filename}five";

# Keep last temperature, if no last create stats database
use strict;
use lib qw(/home/chirico/package);
use mMySQL;
my $zipcode=19027;

my $oldtmp;
my $dbh = mMySQL::connect_weather();
my $s = $dbh->prepare("select deg from weather where pkey= (select max(pkey) from weather)");

while(my @val = $s->fetchrow_array())
   $oldtmp = $val[0];


my $url = "${zipcode}";
my $content = get($url);
die "Couldn't get $url" unless defined $content;
if ($content =~ /.*Observed at(.|\n)*/i ) {
my $temp;
my $humidity;
my $dew;
my $direction;
my $speed;    
my $gust;
my $pressure;
my $vector;
my $hPa;
my $conditions;
my $visibility;
my $clouds;
my $stat;
my $cloudsft;
my $t2;

    my $t = $&;
#    if ($t =~/.*<\/table>/i)
    if (1)
	$t2 =~ s/\n//g;
	$t2 =~ s/\r//g;

#        print $t2;
	if( $t2 =~ /<b>(\d+)<\/b>\&nbsp;\&#176;F<\/nobr>/i) {
	     $temp = $1;

        $humidity = 0;
	if( $t2 =~ /Humidity:<\/td><td valign=top><b>(\d+)[\%]*<\/b>/i) {  
	     $humidity = $1;

	if( $t2 =~ /.*Dew Point.*<b>(\d+)<\/b>\&nbsp;\&#176;F/i) {
	     $dew = $1;

	if( $t2 =~ /.*Wind:.*<b>(\d+)<\/b>&nbsp;mph/i) {
	     $speed = $1;

	if( $t2 =~ /.*from\s+the\s+<b>(\w*)<\/b>/i) {
	     $direction = $1;

	if( $t2 =~ / Gust\s*.*<b>\s*(\d+)\s*<\/b>\&nbsp;mph/i) {
	     $gust = $1;

        $pressure = 0;
        $hPa = 0;
        $vector = 'N/A';
	if( $t2 =~ /(\d+\.\d+)\s*<\/b>\&nbsp;in/i) {
	     $pressure = $1;

	if( $t2 =~ /(\d+\.\d+)<\/b>\&nbsp;hPa/i) {
	     $hPa = $1;

	if( $t2 =~ /Pressure.*<b>\s*(\d+\.\d+)\s*<\/b>\&nbsp;in.*<b>(\d+)<\/b>\&nbsp;hPa\s*.*\((\w*)\)/i) {
             $vector = $1;

        $visibility = 'N/A';
	if( $t2 =~ /Visibility:\s*.*<b>\s*(\d+)\s*<\/b>\&nbsp;miles/i) {
	     $visibility = $1;


        $conditions = 'N/A';
	if( $t2 =~ /<td>Conditions\s*<\/td>\s*<td>\s*<b>\s*(\w+\s*\w*\s*\w*)\s*<\/b>/i) {
	     $conditions = $1;


                   #<\/span><\/td>\s*\((\w+\s*\w*\s*\w*\))\:\s*<b>\s*(\d+)\s*<\/b>\&nbsp;ft/i) {

	if( $t2 =~ /Clouds.*<i>\((\w+\s*\w*\s*\w*)\)<\/i>/i) {
	     $clouds = $1;

	if( $t2 =~ /Clouds.*<b>(\w*\s*\w*\s*)<\/b><!--/i) {
	     $stat = $1;

	if( $t2 =~ /Clouds.*<b>\s*(\d+)\s*<\/b>\&nbsp;ft/i) {
	     $cloudsft = $1;

	print "Temp:            $temp \n";
	print "Humidity:        $humidity \n";
	print "Dew Point:       $dew \n";
	print "Wind: direction: $direction  speed:   $speed \n";
	print "Wind Gust:       $gust  \n";
	print "Pressure:        $pressure     $hPa   $vector  \n";
	print "Conditions:      $conditions  \n";
	print "Visibility:      $visibility  \n";
	print "Clouds:          $clouds       $stat  $cloudsft  \n";

#print "insert into weather (deg,humidity,dewpt,winddir,windspeed,windgust,pressure,pressurehg,pressurevec,conditions,visibility,clouds,
#              cloudsst,cloudheight) values 
#              ($temp,$humidity,$dew,'$direction',$speed,$gust,$pressure,$hPa,'$vector','$conditions','$visibility','$clouds','$stat',$cloudsft)";

     $s = $dbh->prepare("insert into weather (deg,humidity,dewpt,winddir,windspeed,windgust,pressure,pressurehg,pressurevec,conditions,visibility,clouds,
              cloudsst,cloudheight) values 





	if ( $humidity > 99 ) {
       } elsif ($humidity < 99 && $humidity > 9  ) {

       } else {



    if ( $temp != $oldtmp )  {

         # buzzer tmp change
	     sleep 1;

    sleep 7;    

    if ($speed < 10)    {
     } else {

    sleep 1;

# This is why something needs to be fixed
# it's keeping the values from the old
# large numbers
my $a = "00".substr($hPa,2,1);
my $b = "00".substr($hPa,1,1);

    sleep 8;


# Turn off

# Close Database
$dbh->disconnect ( );

# Close files


Linux System Admin Tips: There are over 200 Linux tips and tricks in this article. That is over 100 pages covering everything from NTP, setting up 2 IP address on one NIC, sharing directories among several users, putting running jobs in the background, find out who is doing what on your system by examining open sockets and the ps command, how to watch a file, how to prevent even root from deleting a file, tape commands, setting up cron jobs, using rsync, using screen conveniently with emacs, how to kill every process for a user, security tips and a lot more. These tip grow weekly. The above link will download the text version for easy grep searching. There is also an html version here.

Breaking Firewalls with OpenSSH and PuTTY: If the system administrator deliberately filters out all traffic except port 22 (ssh), to a single server, it is very likely that you can still gain access other computers behind the firewall. This article shows how remote Linux and Windows users can gain access to firewalled samba, mail, and http servers. In essence, it shows how openSSH and Putty can be used as a VPN solution for your home or workplace.

MySQL Tips and Tricks: Find out who is doing what in MySQL and how to kill the process, create binary log files, connect, create and select with Perl and Java, remove duplicates in a table with the index command, rollback and how to apply, merging several tables into one, updating foreign keys, monitor port 3306 with the tcpdump command, creating a C API, complex selects, and much more.

Create a Live Linux CD - BusyBox and OpenSSH Included: These steps will show you how to create a functioning Linux system, with the latest 2.6 kernel compiled from source, and how to integrate the BusyBox utilities including the installation of DHCP. Plus, how to compile in the OpenSSH package on this CD based system. On system boot-up a filesystem will be created and the contents from the CD will be uncompressed and completely loaded into RAM -- the CD could be removed at this point for boot-up on a second computer. The remaining functioning system will have full ssh capabilities. You can take over any PC assuming, of course, you have configured the kernel with the appropriate drivers and the PC can boot from a CD. This tutorial steps you through the whole processes.

SQLite Tutorial : This article explores the power and simplicity of sqlite3, first by starting with common commands and triggers, then the attach statement with the union operation is introduced in a way that allows multiple tables, in separate databases, to be combined as one virtual table, without the overhead of copying or moving data. Next, the simple sign function and the amazingly powerful trick of using this function in SQL select statements to solve complex queries with a single pass through the data is demonstrated, after making a brief mathematical case for how the sign function defines the absolute value and IF conditions.

The Lemon Parser Tutorial: This article explains how to build grammars and programs using the lemon parser, which is faster than yacc. And, unlike yacc, it is thread safe.

How to Compile the 2.6 kernel for Red Hat 9 and 8.0 and get Fedora Updates: This is a step by step tutorial on how to compile the 2.6 kernel from source.

Virtual Filesystem: Building A Linux Filesystem From An Ordinary File. You can take a disk file, format it as ext2, ext3, or reiser filesystem and then mount it, just like a physical drive. Yes, it then possible to read and write files to this newly mounted device. You can also copy the complete filesystem, since it is just a file, to another computer. If security is an issue, read on. This article will show you how to encrypt the filesystem, and mount it with ACL (Access Control Lists), which give you rights beyond the traditional read (r) write (w) and execute (x) for the 3 user groups file, owner and other.

Working With Time: What? There are 61 seconds in a minute? We can go back in time? We still tell time by the sun?

Chirico img Mike Chirico, a father of triplets (all girls) lives outside of Philadelphia, PA, USA. He has worked with Linux since 1996, has a Masters in Computer Science and Mathematics from Villanova University, and has worked in computer-related jobs from Wall Street to the University of Pennsylvania. His hero is Paul Erdos, a brilliant number theorist who was known for his open collaboration with others.

Mike's notes page is souptonuts. For open source consulting needs, please send an email to All consulting work must include a donation to Logo Logo