| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use NOLookup::BrregDifi::DataLookup; | ||
| 6 | use Encode; | ||
| 7 | use vars qw($opt_o $opt_n $opt_p $opt_i $opt_v $opt_h); | ||
| 8 | use Getopt::Std; | ||
| 9 | use Pod::Usage; | ||
| 10 | |||
| 11 | use Data::Dumper; | ||
| 12 | $Data::Dumper::Indent=1; | ||
| 13 | |||
| 14 | &getopts('hvo:n:p:i:'); | ||
| 15 | |||
| 16 | if ($opt_h) { | ||
| 17 | pod2usage(); | ||
| 18 | } | ||
| 19 | |||
| 20 | unless ($opt_o or $opt_n) { | ||
| 21 | pod2usage("An organization number or name must be specified!\n"); | ||
| 22 | } | ||
| 23 | |||
| 24 | my $bo = NOLookup::BrregDifi::DataLookup->new; | ||
| 25 | |||
| 26 | if ($opt_o) { | ||
| 27 | $bo->lookup_orgno($opt_o); | ||
| 28 | } elsif ($opt_n) { | ||
| 29 | my $nm = decode('UTF-8', $opt_n); | ||
| 30 | $bo->lookup_orgname($nm, $opt_p, $opt_i); | ||
| 31 | } | ||
| 32 | |||
| 33 | if ($bo->error) { | ||
| 34 | print STDERR "Error: ", $bo->status, "\n"; | ||
| 35 | |||
| 36 | } else { | ||
| 37 | if ($bo->warning) { | ||
| 38 | print STDERR "Warning: ", $bo->status, "\n"; | ||
| 39 | } | ||
| 40 | |||
| 41 | #print "bo: ", Dumper $bo; | ||
| 42 | |||
| 43 | if ($bo->size <1) { | ||
| 44 | print "No match on search\n"; | ||
| 45 | |||
| 46 | } elsif ($bo->size >= 1) { | ||
| 47 | print "Found ", $bo->size, " matching entries:\n"; | ||
| 48 | foreach my $e (@{$bo->data}) { | ||
| 49 | print $e->orgnr, "\t", | ||
| 50 | $e->organisasjonsform, "\t", | ||
| 51 | encode('UTF-8', $e->navn), "\n"; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | if ($opt_v) { | ||
| 55 | print "\n--\nJSON data structure: ", | ||
| 56 | Dumper($bo->raw_json_decoded), "\n--\n"; | ||
| 57 | } | ||
| 58 | |||
| 59 | } | ||
| 60 | |||
| 61 | |||
| 62 | =pod | ||
| 63 | |||
| 64 | =head1 NAME | ||
| 65 | |||
| 66 | no_brreg_difi.pl | ||
| 67 | |||
| 68 | =head1 DESCRIPTION | ||
| 69 | |||
| 70 | Uses NOLookup::BrregDifi::DataLookup to perform lookup on an orgnumber | ||
| 71 | or an orgname and fetch and print the matching information. | ||
| 72 | |||
| 73 | The data found are stored as NOLookup::BrregDifi::Entry data objects. | ||
| 74 | |||
| 75 | =head1 USAGE | ||
| 76 | |||
| 77 | no_brreg_difi.pl -o 985821585 | ||
| 78 | |||
| 79 | no_brreg_difi.pl -n norid | ||
| 80 | |||
| 81 | For -o: successful output is the orgno and orgname of the organization. | ||
| 82 | |||
| 83 | perl no_brreg_difi.pl -o 985821585 | ||
| 84 | Found 1 matching entries: | ||
| 85 | 985821585 UNINETT NORID AS | ||
| 86 | |||
| 87 | For -n: successful output is a list of orgno and orgname of | ||
| 88 | the matching organizations. | ||
| 89 | Note that only orgs starting with -n are listed due | ||
| 90 | to a limitation in the Brreg API service. | ||
| 91 | |||
| 92 | perl no_brreg_difi.pl -n uninett | ||
| 93 | Found 4 matching entries: | ||
| 94 | 968100211 UNINETT AS | ||
| 95 | 985821585 UNINETT NORID AS | ||
| 96 | 887625352 UNINETT SIGMA AS | ||
| 97 | 814864332 UNINETT SIGMA2 AS | ||
| 98 | |||
| 99 | Up to a maximum of 100 matches are listed. | ||
| 100 | |||
| 101 | Arguments: | ||
| 102 | |||
| 103 | -o: orgnumber | ||
| 104 | |||
| 105 | -n: orgname (complete name or start of name, minimum 2 chars) | ||
| 106 | |||
| 107 | When -n is specifed, also: | ||
| 108 | -p: page number (1..x), max. number of pages | ||
| 109 | -i: page index (1..x), which page to start on | ||
| 110 | |||
| 111 | -v: verbose dump of the complete JSON data structure | ||
| 112 | |||
| 113 | =cut | ||
| 114 | |||
| 115 | 1; | ||
| 116 | |||
| 117 |