| 1 | #!/usr/local/bin/perl -W | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use JSON::XS; | ||
| 5 | use Data::Dumper; | ||
| 6 | use AI::MicroStructure; | ||
| 7 | use AI::MicroStructure::Util; | ||
| 8 | use Storable::CouchDB; | ||
| 9 | my @ARGVX = (); | ||
| 10 | |||
| 11 | my $state = AI::MicroStructure::util::load_config(); my @CWD=$state->{cwd}; my $config=$state->{cfg}; | ||
| 12 | |||
| 13 | our $json_main = {lang=>"C",category=>"no",name=>"santex",size=>1,children=>[]}; | ||
| 14 | |||
| 15 | @ARGVX=("user", | ||
| 16 | "pass", | ||
| 17 | "localhost", | ||
| 18 | "nav") unless($#ARGVX>2); | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | my $x = AI::MicroStructure->new; | ||
| 23 | |||
| 24 | sub getAll { | ||
| 25 | my $key =shift; | ||
| 26 | |||
| 27 | require LWP::UserAgent; | ||
| 28 | my $ua = LWP::UserAgent->new; | ||
| 29 | my ($server,$db) = ($config->{couchdb},"table"); | ||
| 30 | my $res = $ua->get(sprintf('%s/%s/_design/base/_view/instances?reduce=false&start_key=["%s"]&end_key=["%sZZZ"]', | ||
| 31 | $server, | ||
| 32 | $db, | ||
| 33 | $key, | ||
| 34 | $key)); | ||
| 35 | |||
| 36 | |||
| 37 | my $content = decode_json($res->content); | ||
| 38 | my @all; | ||
| 39 | my @book; | ||
| 40 | |||
| 41 | foreach(@{$content->{rows}}){ | ||
| 42 | |||
| 43 | if(@{$_->{key}}){ | ||
| 44 | push @all,grep{!/\W/}@{$_->{key}}; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | return @all; | ||
| 50 | |||
| 51 | |||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | $ARGV[0] = "" unless($ARGV[0]); | ||
| 58 | my $key = sprintf("%s_%s",join("",@ARGVX),$ARGV[0]); | ||
| 59 | my @datax = getAll($ARGV[0]); | ||
| 60 | |||
| 61 | if($#datax){ | ||
| 62 | |||
| 63 | |||
| 64 | foreach my $i(0..$#datax) { | ||
| 65 | |||
| 66 | printf("%s\n","".$datax[$i]) unless(!$datax[$i]); | ||
| 67 | |||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; | ||
| 72 | __DATA__ | ||
| 73 | |||
| 74 |