Skip to content

Instantly share code, notes, and snippets.

@lopnor
Created April 23, 2010 12:17
Show Gist options
  • Select an option

  • Save lopnor/376482 to your computer and use it in GitHub Desktop.

Select an option

Save lopnor/376482 to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use Config::Pit;
use Getopt::Long;
use Net::Google::Spreadsheets;
use Net::Google::DocumentsList;
use DateTime;
scalar @ARGV == 2 or die 'usage: wallet.pl [--type in] note amount';
my $type = 'out';
GetOptions(
'type=s' => \$type,
);
my $config = pit_get('google.com');
my $cli = Net::Google::Spreadsheets->new($config);
my $ss = $cli->spreadsheet({title => 'osdc.tw'});
my ($ws, $table);
if ($ss) {
$ws = $ss->worksheet;
$table = $ss->table(
{
title => 'wallet',
worksheet => $ws,
}
);
} else {
my $doc = Net::Google::DocumentsList->new($config)->add_item(
{
title => 'osdc.tw',
kind => 'spreadsheet',
}
) or die 'oops!';
my $key = (split(/:/,$doc->resource_id))[1];
$ss = $cli->spreadsheet({key => $key});
$ws = $ss->worksheet;
$table = $ss->add_table(
{
title => 'wallet',
worksheet => $ws,
columns => ['datetime', 'out', 'note', 'amount'],
}
);
}
$ws->add_row(
#$table->add_record(
{
datetime => DateTime->now(time_zone => 'Asia/Taipei')->iso8601,
$type eq 'out' ? (out => 1) : (),
note => $ARGV[0],
amount => $ARGV[1],
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment