view flash.pl @ 374:e551351b18de

updated for timestamp of scores information
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 14 Apr 2009 17:01:17 +0800
parents 0522468991c1
children
line wrap: on
line source

#!/usr/bin/perl

use strict;
use Ikariam;
use Ikariam::CitiesRules;
use Data::Dumper;
use Decision::ParseTree q{ParseTree};
use YAML qw/LoadFile Dump DumpFile/;

package main;
my $cityId = 95780;
my $cities = {};

our $i = new Ikariam($::server, $::user, $::pass);
$i->login;
$i->changeCity($cityId);
$cities->{$cityId} = $i->checkCity($cityId);

# Genereic rules for both overall and city level arranagement.
my $rules = Ikariam::CitiesRules->new($i);
my $tree  = LoadFile('flash-city.yaml');
$cities->{$cityId}->{parse_path} = [];
$cities->{$cityId}->{parse_answer} = undef;
if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) {
    triggerAction($action, $cityId);
}

$i->logout;

sub triggerAction {
    my ($action, $cityId) = @_;

    my ($func, $param) = split(/_/,$action);
    printf('$i->%s("%s", %s);'. "\n", $func, $param, $cityId);
    eval(sprintf('$i->%s("%s", %s);', $func, $param, $cityId));
    warn $@ if $@;
}