1 #!/opt/local/bin/perl
2
3 use strict;
4 use WWW::Mechanize;
5 use HTML::TreeBuilder;
6 use Data::Dumper;
7
8 my %login = (
9 url => 'http://irtsectraining.nih.gov/admin/',
10 form => 'form1',
11 fields => {
12 nedid1 => '',
13 nedid2 => '',
14 nedid3 => '',
15 txtPassword => '',
16 },
17 );
18
19 my %search = (
20 form => 'form1',
21 ticks => [qw(
22 cb_usertype_EMPLOYEE cb_usertype_CONTRACTOR cb_usertype_FELLOW cb_usertype_GUEST
23 cb_usertype_TENANT cb_usertype_VOLUNTEER cb_display4 cb_display6
24 )],
25 submit => 'btnSubmit',
26 );
27
28 my %report = (
29 filename => 'ReportIRTSecTraining.txt',
30 );
31
32 #
33 # Assemble our Bot
34 my $mech = WWW::Mechanize->new();
35
36 #
37 # Login:
38 #------------------------------------------------------------------------#
39 $mech->get($login{url});
40
41 # select the form
42 $mech->form_name( $login{form} );
43
44 # fill in the fields:
45 foreach my $k (keys %{ $login{fields} }) {
46 $mech->field( $k, $login{fields}->{$k} );
47 }
48
49 # stumbit the form:
50 $mech->submit();
51
52 #
53 # Goto the Report Query
54 $mech->click( 'btnReportQuery' );
55 #------------------------------------------------------------------------#
56 # Fill out the report query
57 #------------------------------------------------------------------------#
58 $mech->form_name( $search{form} );
59
60 # Tick things on.
61 foreach my $f (@{ $search{ticks} }) {
62 #print "$f -> ", $mech->value($f,1), "\n";
63 $mech->tick($f,'on');
64 }
65
66 #
67 # Stumbit
68 $mech->click( $search{submit} );
69
70 #------------------------------------------------------------------------#
71 # Parse the Tree and Turn it into TXT
72 #------------------------------------------------------------------------#
73 open( my $fh, '>', $report{filename} ) or die "unable to open $report{filename}: $!\n";
74
75
76 my $TOTAL = 0;
77 my $INCOMPLETE = 0;
78
79 my $tree = HTML::TreeBuilder->new_from_content( $mech->content );
80
81 $tree->elementify();
82
83 my $tbl = $tree->look_down( 'id', 'reportDataGrid' );
84
85 foreach my $tr ( $tbl->find( 'tr' ) ) {
86 my @row;
87 $TOTAL++;
88 foreach my $td ( $tr->find( 'td' ) ) {
89 if( my $cb = $td->look_down( 'type', 'checkbox' ) ) {
90 next unless ( $cb->attr('name') =~ /_fyr/ );
91
92 lc($cb->attr('checked')) eq 'checked' ? 0 : $INCOMPLETE++;
93
94 my $val = lc($cb->attr('checked')) eq 'checked' ? 'Y' : 'N';
95 push @row, $val;
96 }
97 else {
98 push @row, $td->as_text();
99 }
100 }
101 print $fh join("\t", @row), "\n";
102 }
103
104 print "Total Incomplete: $INCOMPLETE\nTotal Users: $TOTAL\n";
syntax highlighted by Code2HTML, v. 0.9.1