#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $id = 'MSC2190225***'; my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time); my $mmdd = sprintf( "%02d%02d", $mon + 1, $mday ); if ( $#ARGV != -1 ) { if ( $ARGV[0] =~ /^(\w\w\w\d\d\d\d\d\d\d)/i ) { $id = $1; open( SH, ">case.sh" ); print SH qq{curl "https://egov.uscis.gov/casestatus/mycasestatus.do?changeLocale=&completedActionsCurrentPage=0&upcomingActionsCurrentPage=0&appReceiptNum=${id}[000-999]&caseStatusSearchBtn=CHECK+STATUS" -o "${mmdd}/${id}#1.html"\n}; close(SH); unless ( -d $mmdd ) { mkdir($mmdd); } print "sh case.sh\n"; print qx(sh case.sh &); my $one = &cases($mmdd); print Dumper($one); } } else { print "$0 [ID]\n"; print "# $0 $id\n"; } sub cases { my $mmdd = shift; my @files = <$mmdd/*.html>; my $status = 0; my %count = (); my @title = (); my @content = (); foreach my $file (@files) { open( FILE, $file ); my @data = ; close(FILE); foreach my $line (@data) { if ( $line =~ /
/ ) { $status = 1; } if ( $status == 1 ) { if ( $line =~ /<\/div>/ ) { $status = 2; } if ( $line =~ /

(.*?)<\/h1>/ ) { push( @title, $1 ); $count{$1}++; } if ( $line =~ /

(.*?)<\/p>/ ) { push( @content, $1 ); } } } } my $cases = 0; foreach my $key ( keys %count ) { $cases += $count{$key}; } print "Date: $mmdd | Cases: $cases\n"; return \%count; }