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