AI-generated script to extract basionyms from World Register of Marine Species (marinespecies.org)
收藏资源简介:
#!/usr/bin/perluse strict;use warnings;use LWP::UserAgent;use JSON;# Check for input fileif (@ARGV != 1) {die "Usage: $0 species_list.txt\n";}my $input_file = $ARGV[0];# Read species listopen(my $fh, '<', $input_file) or die "Cannot open $input_file: $!";my @species = map { chomp; $_ } <$fh>;close($fh);# Set up HTTP clientmy $ua = LWP::UserAgent->new;$ua->timeout(10);# API base URLmy $api_base = 'https://www.marinespecies.org/rest/AphiaRecordsByName/';# Process each speciesforeach my $sp (@species) {# Encode spaces for URLmy $query = $sp;$query =~ s/ /%20/g;my $url = $api_base . $query . '?like=false';my $response = $ua->get($url);if (!$response->is_success) {warn "Failed to fetch $sp: ", $response->status_line, "\n";next;}my $content = $response->decoded_content;my $data = eval { decode_json($content) };if ($@) {warn "JSON parse error for $sp: $@\n";next;}# Sometimes API returns an arrayif (ref $data eq 'ARRAY' && @$data) {my $record = $data->[0]; # Take first matchmy $basionym = $record->{originalName} // 'NULL';my $authority = $record->{authority} // 'NULL';print join("\t", $sp, $basionym, $authority), "\n";} else {print join("\t", $sp, 'NULL', 'NULL'), "\n";}}



