head	1.1;
access;
symbols;
locks
	perlman:1.1; strict;
comment	@# @;


1.1
date	2009.07.22.01.47.16;	author perlman;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@#! /usr/bin/perl

use LWP::Simple;

($tg, $tocurl) = ($ARGV[0], $ARGV[1]);
if (! $tg) {
	print "Usage: gethfes [tg] url\n";
	exit;
}
if (! $tocurl) {
	$tocurl = $tg;
	$tg = "";
} else {
	&init();
	$tg =~ tr/a-z/A-Z/; # map to upper case
	$tg = $tgs{$tg} ?  $tgs{$tg} : $tg;
}

# print "$tocurl\n";

$toc = get($tocurl);
# print "$toc";

for $line (split (/\n/, $toc)) {
	$line =~ s/^\s*//;   # remove leading space
	$line =~ s/\s*$//;   # remove trailing space
	if ($line) {
		if ($line =~ m|<p class="heading">([^<]*)</p>|) {
			$section = $1;
			# print "*************** $tg: $section\n";
		} elsif ($line =~ m|<input type="checkbox" name="art\d+" value="infobike://(hfes/hfproc/(\d\d\d\d)/000000(\d\d)/000000(\d\d)/art000(\d\d))" />|) {
			$recurl = $1;
			# print "=============== $recurl\n";
			$recurl = "http://www.ingentaconnect.com/content/" . $recurl;
			&getrecord($recurl, $tg, $section);
		}
		# print "	$line\n";
	}
}

sub cleanup {
	local ($text) = (@@_);
	$text =~ s/&ndash;/-/g;
	$text =~ s/&quest;/?/g;
	$text =~ s/&sol;/\//g;
	$text =~ s/&ldquo;/"/g;
	$text =~ s/&rdquo;/"/g;
	$text =~ s/&excl;/!/g;
	$text =~ s/&#33;/!/g;
	$text =~ s/&#37;/%/g;
	$text =~ s/&#38;/&amp;/g;
	$text =~ s/&#39;/'/g;
	$text =~ s/&#47;/\//g;
	$text =~ s/&#43;/+/g;
	$text =~ s/&#60;/&lt;/g;
	$text =~ s/&#61;/=/g;
	$text =~ s/&#62;/&gt;/g;
	$text =~ s/&#63;/?/g;
	$text =~ s/&#174;//g;          # tm or reg
	$text =~ s/&#176;/&deg;/g;     # degree
	$text =~ s/&#177;/&plusmn;/g;  
	$text =~ s/&#235;/&euml;/g;    # naive
	$text =~ s/&#239;/&iuml;/g;    # naive
	$text =~ s/&#916;/&Delta;/g;   # 
	$text =~ s/&#8212;/--/g;
	$text =~ s/&#8221;/"/g;
	$text =~ s/&#8220;/"/g;
	$text =~ s/&#8482;//g;         # TM
	$text =~ s/&#8722;/-/g;        # negative
	$text =~ s|<i>||gi; $text =~ s|</i>||gi;
	$text =~ s|<p></p>|\n   |gi; # paragraph break
	return $text;
}

sub getrecord { # url
	local ($recurl, $tg, $section) = @@_;
	$recurl .= "?format=bib"; # will get info in bibtex format
	local ($rec) = get $recurl;
	local (@@lines) = split (/\n/, $rec);
	for $line (@@lines) {
		# print "$line\n";
		if ($line =~ m|\@@article|) {
			if ($tg) {
				print "%S $tg: $section\n";
			} else {
				print "%S $section\n";
			}
		} elsif ($line =~ m|^\s*}\s*$|) {
			print "\n"; # end of record
		} elsif ($line =~ m|author\s*=\s*"([^"]*)"|) {
			print "%A $1\n";
		} elsif ($line =~ m|title\s*=\s*"([^"]*)"|) {
			$title = &cleanup($1);
			print "%T $title\n";
		} elsif ($line =~ m|volume\s*=\s*"([^"]*)"|) {
			print "%V $1\n";
		} elsif ($line =~ m|year\s*=\s*"(\d\d(\d\d))"|) {
			print "%D $1\n";
			print "%B HFES$2\n";
		} elsif ($line =~ m|pages?\s*=\s*"([^"]*)"|) {
			$pages = $1;
			$pages =~ s/\(.*$//; # remove number of pages
			print "%P $pages\n";
		} elsif ($line =~ m|url\s*=\s*"([^"]*)"|) {
			print "%W $1\n";
		} elsif ($line =~ m|abstract\s*=\s*"([^"]*)"|) {
			$abstract = &cleanup($1);
			print "%X $abstract\n";
		}
	}
}

sub init {
	local (@@tgs) = (
		"AS=AEROSPACE SYSTEMS",
		"A=AGING",                                           # ?
		"AC=AUGMENTED COGNITION",                            # ?
		"CE=COGNITIVE ENGINEERING AND DECISION MAKING",      # ?
		"C=COMMUNICATIONS",                                  # ?
		"CS=COMPUTER SYSTEMS",                               # !!!
		"E=EDUCATION",
		"ED=ENVIRONMENTAL DESIGN",
		"FP=FORENSICS PROFESSIONAL",
		"HC=HEALTH CARE",
		"HPM=HUMAN PERFORMANCE MODELING",
		"PM=HUMAN PERFORMANCE MODELING",
		"IDP=INDIVIDUAL DIFFERENCES IN PERFORMANCE",
		"I=INTERNET",                                        # !!!
		"IE=INDUSTRIAL ERGONOMICS",
		"M=MACROERGONOMICS",
		"POS=POSTERS",                                       # ?
		"PP=PERCEPTION AND PERFORMANCE",                     # ?
		"PD=PRODUCT DESIGN",
		"S=SAFETY",
		"SF=STUDENT FORUM",                                  # ?
		"ST=SURFACE TRANSPORTATION",
		"SD=SYSTEM DEVELOPMENT",                             # ?
		"TE=TEST AND EVALUATION",                            # ?
		"T=TRAINING",
		"VE=VIRTUAL ENVIRONMENTS",                           # ?
	);
	local ($line, $code, $name);
	for $line (@@tgs) {
		($code, $name) = split (/=/, $line);
		# print "$code $name\n";
		$tgs{$code} = $name;
	}
}

@
