Improving json format.
This commit is contained in:
parent
7a648052ee
commit
22908741b4
@ -57,9 +57,9 @@ sub startup ($self) {
|
|||||||
$r->get('/computer-shiny.rss')->to('Page#computer_shiny_rss');
|
$r->get('/computer-shiny.rss')->to('Page#computer_shiny_rss');
|
||||||
$r->get('/computer-pokerus.rss')->to('Page#computer_pokerus_rss');
|
$r->get('/computer-pokerus.rss')->to('Page#computer_pokerus_rss');
|
||||||
|
|
||||||
my $pidfile = path('/run/gtsrssapi.pid');
|
my $pidfile = path('/run/gtsrssapi.pid');
|
||||||
my $gts_bot_pid = path('last_pid_started_gts_bot');
|
my $gts_bot_pid = path('last_pid_started_gts_bot');
|
||||||
if (-f $pidfile) {
|
if ( -f $pidfile ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$self->start_gts_bot;
|
$self->start_gts_bot;
|
||||||
@ -335,12 +335,15 @@ EOF
|
|||||||
$db->selectall_array( 'SELECT * FROM offers WHERE uuid = ?',
|
$db->selectall_array( 'SELECT * FROM offers WHERE uuid = ?',
|
||||||
{ Slice => {} }, $offer_uuid );
|
{ Slice => {} }, $offer_uuid );
|
||||||
$offer->{is_available} = 1;
|
$offer->{is_available} = 1;
|
||||||
|
$offer->{date} =
|
||||||
|
DateTime::Format::Pg->parse_datetime( $offer->{date} );
|
||||||
|
$offer->{level} = int( $offer->{level} );
|
||||||
$uuid = create_uuid_string;
|
$uuid = create_uuid_string;
|
||||||
$db->do(
|
$db->do(
|
||||||
$query_create_computer_news, undef,
|
$query_create_computer_news, undef,
|
||||||
$uuid, $pg_date,
|
$uuid, $pg_date,
|
||||||
decode( 'utf-8', $offerer ), $species,
|
decode( 'utf-8', $offerer ), $species,
|
||||||
$is_shiny, $has_pokerus,
|
$is_shiny, $has_pokerus,
|
||||||
Mojo::JSON::to_json($offer), $held_item,
|
Mojo::JSON::to_json($offer), $held_item,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -401,18 +404,26 @@ EOF
|
|||||||
|
|
||||||
my $uuid = create_uuid_string;
|
my $uuid = create_uuid_string;
|
||||||
$db->do(
|
$db->do(
|
||||||
$query_create_news, undef, $uuid,
|
$query_create_news,
|
||||||
$pg_date_formatter->format_datetime($date), $offerer, $species,
|
undef,
|
||||||
$is_shiny, $has_pokerus, $line,
|
$uuid,
|
||||||
|
$pg_date_formatter->format_datetime($date),
|
||||||
|
$offerer,
|
||||||
|
$species,
|
||||||
|
$is_shiny,
|
||||||
|
$has_pokerus,
|
||||||
|
$line,
|
||||||
$held_item,
|
$held_item,
|
||||||
);
|
);
|
||||||
$pokemon->{is_available} = 0;
|
$pokemon->{is_available} = 0;
|
||||||
|
$pokemon->{date} = DateTime::Format::Pg->parse_datetime( $pokemon->{date} );
|
||||||
|
$pokemon->{level} = int($pokemon->{level});
|
||||||
$uuid = create_uuid_string;
|
$uuid = create_uuid_string;
|
||||||
$db->do(
|
$db->do(
|
||||||
$query_create_computer_news, undef,
|
$query_create_computer_news, undef,
|
||||||
$uuid, $pg_date,
|
$uuid, $pg_date,
|
||||||
$offerer, $species,
|
$offerer, $species,
|
||||||
$is_shiny, $has_pokerus,
|
$is_shiny, $has_pokerus,
|
||||||
Mojo::JSON::to_json($pokemon), $held_item,
|
Mojo::JSON::to_json($pokemon), $held_item,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,17 @@ sub index ($self) {
|
|||||||
$self->render;
|
$self->render;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub active_offers_json($self) {
|
sub active_offers_json ($self) {
|
||||||
my $db = GTSRSSApi::DB->connect;
|
my $db = GTSRSSApi::DB->connect;
|
||||||
my @offers = $db->selectall_array( <<'EOF', { Slice => {} } );
|
my @offers = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||||
SELECT * FROM offers WHERE is_available ORDER BY date DESC LIMIT 100;
|
SELECT * FROM offers WHERE is_available ORDER BY date DESC LIMIT 100;
|
||||||
EOF
|
EOF
|
||||||
@offers =
|
@offers =
|
||||||
map { $_->{date} = DateTime::Format::Pg->parse_datetime( $_->{date} ); $_ }
|
map {
|
||||||
@offers;
|
$_->{date} = DateTime::Format::Pg->parse_datetime( $_->{date} );
|
||||||
|
$_->{level} = int( $_->{level} );
|
||||||
|
$_
|
||||||
|
} @offers;
|
||||||
return $self->render( json => \@offers );
|
return $self->render( json => \@offers );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +97,7 @@ EOF
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub computer_pokerus_rss($self) {
|
sub computer_pokerus_rss ($self) {
|
||||||
my $db = GTSRSSApi::DB->connect;
|
my $db = GTSRSSApi::DB->connect;
|
||||||
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||||
SELECT species, news_text, date FROM news_computer WHERE has_pokerus ORDER BY date DESC LIMIT 100;
|
SELECT species, news_text, date FROM news_computer WHERE has_pokerus ORDER BY date DESC LIMIT 100;
|
||||||
@ -110,7 +113,7 @@ EOF
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub pokerus_rss($self) {
|
sub pokerus_rss ($self) {
|
||||||
my $db = GTSRSSApi::DB->connect;
|
my $db = GTSRSSApi::DB->connect;
|
||||||
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||||
SELECT species, news_text, date FROM news WHERE has_pokerus ORDER BY date DESC LIMIT 100;
|
SELECT species, news_text, date FROM news WHERE has_pokerus ORDER BY date DESC LIMIT 100;
|
||||||
|
Loading…
Reference in New Issue
Block a user