Guest User

Untitled

a guest
Apr 7th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.50 KB | None | 0 0
  1. # Trying to write a useful script FAR TOO EARLY!
  2.  
  3. use strict;
  4. use warnings;
  5. use Data::Dumper;
  6. use FindBin;
  7. use lib "$FindBin::Bin/../../lib";
  8. use List::Util            qw(min max);
  9. use List::MoreUtils       qw( uniq );
  10. use Games::Lacuna::Client ();
  11.  
  12. my $cfg_file = shift(@ARGV) || '../lacuna.yml';
  13. unless ( $cfg_file and -e $cfg_file ) {
  14.   $cfg_file = eval{
  15.     require File::HomeDir;
  16.     require File::Spec;
  17.     my $dist = File::HomeDir->my_dist_config('Games-Lacuna-Client');
  18.     File::Spec->catfile(
  19.       $dist,
  20.       'login.yml'
  21.     ) if $dist;
  22.   };
  23.   unless ( $cfg_file and -e $cfg_file ) {
  24.     die "Did not provide a config file";
  25.   }
  26. }
  27.  
  28. my $client = Games::Lacuna::Client->new(
  29.     cfg_file => $cfg_file,
  30.     # debug    => 1,
  31. );
  32.  
  33. # Load the planets
  34. my $empire  = $client->empire->get_status->{empire};
  35.  
  36. # reverse hash, to key by name instead of id
  37. my %planets = map { $empire->{planets}{$_}, $_ } keys %{ $empire->{planets} };
  38.  
  39. # Scan each planet
  40. foreach my $name ( sort keys %planets ) {
  41.     # Load planet data
  42.     my $planet    = $client->body( id => $planets{$name} );
  43.     my $result    = $planet->get_buildings;
  44.     my $body      = $result->{status}->{body};
  45.     my $buildings = $result->{buildings};
  46.     my $arch      = List::Util::first {
  47.         $buildings->{$_}->{url} eq '/archaeology'
  48.     }
  49.     keys %$buildings;
  50.    
  51.     next unless defined $arch;
  52.    
  53.     my $level = $buildings->{$arch}{level};
  54.    
  55.     # Print out the planet name and archaeology level
  56.     print "$name\n";
  57.     print "$level\n";
  58.    
  59.     my @build;
  60.    
  61.     push @build, $buildings->{$arch} if $level < 15;
  62.    
  63. }
Add Comment
Please, Sign In to add comment