Improving json format.

This commit is contained in:
sergiotarxz 2024-05-09 10:35:38 +02:00
parent 7a648052ee
commit 22908741b4
2 changed files with 33 additions and 19 deletions

View File

@ -59,7 +59,7 @@ sub startup ($self) {
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,6 +335,9 @@ 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,
@ -401,12 +404,20 @@ 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,

View File

@ -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;