WebService::EveOnline

From EVEDev
Jump to: navigation, search

WebService::EveOnline on CPAN

To install:

$ cpan -i WebService::EveOnline

(use Strawberry perl cpan install under Windows)

WebService::EveOnline provides an object-oriented wrapper for the EVE API.

 
#!/usr/bin/perl
 
use strict;
use warnings;
 
use WebService::EveOnline;
 
my $API_KEY = $ENV{EVE_API_KEY};
my $USER_ID = $ENV{EVE_USER_ID};
 
unless ($API_KEY && $USER_ID) {
    print "Please export EVE_API_KEY and EVE_USER_ID before running\n";
    exit;
}
 
my $wanted = $ARGV[0] || undef;
 
my $eve = WebService::EveOnline->new( { user_id => $USER_ID, api_key => $API_KEY } );
 
foreach my $character ($eve->characters) {
    next if $wanted && $wanted ne $character->name;
 
    print $character->name . " has " . $character->account->balance . " ISK in the bank\n";
    foreach my $account ($character->accounts()) {
        print "  -- " . $account->balance . " ISK in " . $account->division . "/" . $account->type . "\n";
    }
    if ($character->skill->in_training) {
        my $skill = $character->skill->in_training;
        print "     Training " . $skill->name . " (" . $skill->time_remaining . " remaining)\n";
    }
}
 
 

Will output something along the lines of:

John Doe has 31335321.45 ISK in the bank
  -- 31335321.45 ISK in first/personal
  -- 23465347.88 ISK in first/corporate
  -- 854353.54 ISK in second/corporate
  -- 15643.22 ISK in third/corporate
  -- 0.00 ISK in fourth/corporate
  -- 0.00 ISK in fifth/corporate
  -- 0.00 ISK in sixth/corporate
  -- 0.00 ISK in seventh/corporate
Spare Part has 5000.00 ISK in the bank
  -- 5000.00 ISK in first/personal
Sue de Nym has 96786860.24 ISK in the bank
  -- 96786860.24 ISK in first/personal
     Training Gallente Battleship (13d 04h 39m 50s remaining)


This script will print out the most recent transactions carried out by all of your characters:

 
#!/usr/bin/perl
 
use warnings;
use strict;
 
use WebService::EveOnline;
 
my $API_KEY = $ENV{EVE_API_KEY};
my $USER_ID = $ENV{EVE_USER_ID};
 
unless ($API_KEY && $USER_ID) {
    print "Please export EVE_API_KEY and EVE_USER_ID before running\n";
    exit;
}
 
my $eve = WebService::EveOnline->new( { user_id => $USER_ID, api_key => $API_KEY } );
 
my $wanted = $ARGV[0] || undef;
my $show_max = $ARGV[1] || 5;
 
foreach my $char ($eve->characters) {
    next if $wanted && $wanted ne $char->name;
 
    my @transactions = $char->transactions;
    my $num_transactions = scalar(@transactions);
    my $max = ($num_transactions >= $show_max) ? $show_max : $num_transactions;
 
    if ($num_transactions == 0) {
        print "Sadly, " . $char->name . " has made no recorded transactions\n\n";
        next;
    }
 
    print $char->name . "'s last " . (($max == 1) ? "transaction:\n" : "$max transactions:\n");
    foreach my $t (@transactions) {
        next if $max-- <= 0;
        print "  " . (($t->type eq "sell") ? $t->client_name : $char->name) . " bought " 
                   . $t->quantity . " x " . $t->name 
                   . " for " . ($t->price * $t->quantity) 
                   . " ISK on " . $t->station_name 
                   . ", " . $t->evetime . "\n";
    }
    print "\n";
}
 

This script takes two optional parameters -- character name, and number of transactions to show, otherwise all characters and their last 5 transactions are displayed.

Personal tools