#!/usr/bin/perl -w #=============================================================================== # # FILE: clock.pl # # USAGE: ./clock.pl # # DESCRIPTION: Perl back end to the SVG ACPI monitoring widget # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Ronan Oger (ogerr), # COMPANY: RO IT Systems # VERSION: 1.0 # CREATED: 12/16/2005 12:49:33 AM UTC # REVISION: --- #=============================================================================== use strict; use JSON; #debugging help if needed #use Data::Dumper; my $j = new JSON; my $acpicall = `acpi -V`; #some perl data-mining tricks #battery $acpicall =~ /\s*Battery\s\d\:\s(\S+)\,\s+(\d+)\%/; my ($battStatus,$battCharge) = ($1,$2); #my ($battStatus,$battCharge) = ($1,100); #thermal $acpicall =~ /\s*Thermal\s\d\:\s(\S+)\,\s+(\d+\.?\d+).+(C|F)/; #my ($thermalStatus,$thermalTemp,$thermalUnits) = ($1,100,$3); my ($thermalStatus,$thermalTemp,$thermalUnits) = ($1,$2,$3); #AC $acpicall =~ /\s*AC\sAdapter\s\d\:\s(\S+)/; my ($acStatus) = ($1); #build the output hash my $obj = { battCharge => $battCharge, battStatus => $battStatus, thermalStatus => $thermalStatus, thermalTemp => $thermalTemp, thermalUnits => $thermalUnits, acStatus => $acStatus, }; my $js = $j->objToJson($obj); print "Content-type: text/plain\n\n$js";