#!/usr/bin/perl -X
use strict;
use warnings;
use JSON::XS;
use Data::Printer;
use AI::MicroStructure;
use Storable::CouchDB;
my @ARGVX = ();

  sub checkIsThere {

    my $key =shift;


    require LWP::UserAgent;
    my $ua = LWP::UserAgent->new;
    my ($server,$db) = (sprintf("http://%s:5984","localhost"),"table");

   my $res ;
                                
    $res = $ua->get(sprintf('%s/%s/_design/base/_view/instances?reduce=false&start_key=["%s"]&end_key=["%sz"]',
                              $server,
                              $db,
                              $key,
                              $key));


$res = decode_json($res->content);
return @{$res->{rows}};
    
  
}


   our $x = Storable::CouchDB->new(
                                      uri =>"http://user:pass\@localhost:5984/",  #default
                                      db  =>"table"
                                     );



push @ARGV,'film';
push @ARGV,"band";
push @ARGV,"single";
push @ARGV,"album";
push @ARGV,"music";
push @ARGV,"movie";
push @ARGV,"rapstar";
push @ARGV,"artist";
push @ARGV,"actor";
push @ARGV,"movie"; 
push @ARGV,"rock";
push @ARGV,"pop";
push @ARGV,"song";


sub deleteByCategory  {
my $cat = shift;
my @q=();
my @set = checkIsThere($cat);
print  map{  push @q,$_->{id} unless(!$_->{id});}@set;
print join "\n",@q;
map{ $x->delete($_); }@q;
} 


deleteByCategory($_) for(@ARGV);
 
#p @set;
#print map{  p @set,$x;}@set;
#map{ $x->delete($_->{id}); }@set;
  
  1;
  
  __END__
