################################################################################ # # Perl script to search for specific pattern in data received from DX cluster # Usually searching specific amateur station callsign, DX expedition or prefix # # Note: The script connects to cluster.f5len.org, the received list has specific structure. # For other cluster the data pasing part would need to be modified. # # (c) 2018, Jan Uhrin, OM2JU # License: Free, enjoy # # ################################################################################ # # my $cluster = 'http://cluster.f5len.org/html/last.html'; my $proxy = 'http://myproxy:84'; $config = 'awards.cfg'; # # This is URL which will be opened with -s switch my $refURL = 'http://www.dxawards.com/REALSHORT.htm'; # $divider = "-------------------------------------------------------------------------------\n"; # # ################################################################################ # Process config file before parsing command line arguments as some options can be specified in config file if ( open(CONFIG, $config) ) { while () { chop; # Comments if ($_ =~ /^#/) { next }; # URL to open if ($_ =~ /http:/) { s/#\s+//g; push(@urllist, $_); next; } # Options if ($_ =~ /^-/) { print("Note: Option '" . $_ . "' found in config file.\n"); @options = split; push(@ARGV, @options); next }; # # All other entries should be callsign filter / regular expressions s/#\s.*$//g; push(@filter, $_); #print; } close(CONFIG); } else { print("Note: config file " . $config . " not found...\n"); print("Using default configuration: SOTA, IOTA, WFF + autorepeat 5 minutes\n"); push(@filter, "sota"); push(@filter, "iota"); push(@filter, "wff\-"); $timeRepeat = 5; } # # use Getopt::Long; ################################################################################ usage() if ( ! GetOptions( 'h|?' => \$help, # help 'c=s' => \$config, # name of configuration file 'l' => \$list, # only list config file entries 's' => \$showURL, # show parsed URLs from config file 'e' => \$edit, # edit configuration file 'b' => \$beep, # beep upon succesful match 'p' => \$proxyURL, # access internet over PROXY 'm=s' => \$matchString,# filter the entries based on match-string 'n=s' => \$noString, # string to ignore 't=s' => \$timeRepeat, # repeat time in minutes 'a' => \$all) # show all entries or defined $help); # # -e switch if (defined $edit) { system("notepad.exe " . $config); exit; } # if (defined $proxyURL) { $proxyURL = $proxy; } if (defined $timeRepeat) { $timeRepeatMin = int($timeRepeat); if ($timeRepeatMin < 1) { $timeRepeatMin = 1; } $timeRepeatSec = 60 * $timeRepeatMin; } ################################################################################ printf($divider); # Only list filter antries if (defined $list) { printf("Filter entries from file %s:\n", $config); foreach $_ (@filter) { printf(" %s\n", $_); } exit; } # Matchstring/filter from command-line if (defined $matchString) { @filter = (); push(@filter, $matchString); } # -s switch if (defined $showURL) { printf("Choose URL to open ...\n\n"); $i = 1; foreach $url (@urllist) { printf("%s) %s\n", $i, $url); $i++; } printf("\nYour choice or Ctrl-C ? "); $_ = ; chop; $choice = int($_); $choice--; system("start " . $urllist[$choice]); exit; } ################################################################################ use LWP::Simple qw( $ua get ); if (defined $proxyURL) { $ua->proxy( 'http', $proxyURL ); } # while (1) { $beeped = 0; my $content = get $cluster; die "Couldn't get $cluster" unless defined $content; # # Process the content $_ = $content; # Some replacements in order to get raw data from HTML s/\//gi; s/\//gi; s/\<\/pre\>//gi; s/\//gi; s/\//gi; s/\<\/span\>/%/gi; # Get the items @items = split(/%/); @items2 = (); # Remove initial 10 characters from each line, place the result in @items2 foreach $_ (@items) { s/\n//gi; $aa = substr($_,10); push(@items2, $aa); } # Sort the result (will be sorted according frequency) foreach $_ (sort @items2) { $found = 0; foreach $string (@filter) { #printf("-- %s =~ %s\n", $_, $string); if ($_ =~ /$string/i) { $found++; } } if (defined $all) { $found++; } if ((defined $noString) && ($_ =~ /$noString/i)) { $found = 0; } if ($found > 0) { print $_ . "\n"; # Beep only once if -b option if ((defined $beep) && ($beeped == 0)) { printf chr(7); printf chr(7); printf chr(7); $beeped = 1; } } } if (defined $timeRepeat) { printf($divider); printf("Waiting %s minutes ...\n", $timeRepeatMin); sleep($timeRepeatSec); } else { exit; } } # end while(1) ################################################################################ #-------------------------------------------------------------------------------------------------- sub usage { print "\nUnknown option: @_\n" if ( @_ ); printf <<"~~~~~~~~~~"; Usage: $0 [-c file] Use given file as config file instead of $config [-p] Use Proxy $proxy [-a] No filter; prints out all entries [-l] Lists filter entries only [-e] Edit filter entries in file \"$config\" [-b] Beep on succesful match (only once per whole list) [-m string] Show only entries matching the string [-n string] Do not show entries matching the string [-t minutes] Autorepeat query in minutes [-s] Show Award Reference URL [-h|-?] ~~~~~~~~~~ exit; }