#!/usr/bin/gawk -f
#
# netdrawhtml -- 2007-12-13, last edit 2008-09-04
#
# script to write an html file referencing the most recent netdraw
# images, this writes an include file that is shown on the right hand
# side of http://bugsplatter.id.au/netdraw/
#
# Copyright (C) 2007 Grant Coady GPLv2
#
BEGIN {
ARGV[ARGC++] = "/etc/netdraw.conf" # read configuration file first
}
/^#|^$/ { next } # skip comment and empty lines
# read configuration file
NR == FNR {
conf[$1] = $2
if ($1 == "daycopylog") ARGV[ARGC++] = conf["htmlpath"]"/"$2
if ($1 == "moncopylog") ARGV[ARGC++] = conf["htmlpath"]"/"$2
}
# read image filenames from log files
NR != FNR {
split($1, imgname, "-")
if (imgname[1] == "netdraw")
dayimage[i++] = $1
else
monimage[j++] = $1
}
# write the per image markup
function markup(c, t, o, a, date)
{
if (!c) return
split(c, a, "[-.]") # extract date from image name
date = a[2]"-"a[3]"-"a[4]
printf "
o
printf " alt=\"" t date "\"" > o
if (conf["imagetitle"])
printf " title=\"" t date "\"" > o
printf " src=\"" conf["imagepath"] "/" c "\"" > o
print ">
" > o
}
# write the html markup files
END {
tag = "Internet monitor: daily snapshot for "
out = conf["htmlpath"]"/"conf["htmlfileday"]
for (j = 0; j < conf["htmldaynum"]; j++)
markup(dayimage[j], tag, out)
close(out)
tag = "Internet monitor: monthly summary for "
out = conf["htmlpath"]"/"conf["htmlfilemon"]
for (j = 0; j < conf["htmlmonnum"]; j++)
markup(monimage[j], tag, out)
close(out)
}