Adding computer readable news.
This commit is contained in:
parent
08244ef470
commit
161ca9b759
@ -7,6 +7,7 @@ use warnings;
|
|||||||
use utf8;
|
use utf8;
|
||||||
|
|
||||||
use Mojo::Base 'Mojolicious', -signatures;
|
use Mojo::Base 'Mojolicious', -signatures;
|
||||||
|
use Mojo::JSON;
|
||||||
|
|
||||||
use Mojo::UserAgent;
|
use Mojo::UserAgent;
|
||||||
use Mojo::Util qw/url_unescape url_escape b64_decode/;
|
use Mojo::Util qw/url_unescape url_escape b64_decode/;
|
||||||
@ -40,13 +41,20 @@ sub startup ($self) {
|
|||||||
# Router
|
# Router
|
||||||
my $r = $self->routes;
|
my $r = $self->routes;
|
||||||
$self->config(
|
$self->config(
|
||||||
hypnotoad => { proxy => 1, listen => [$self->config('listen') // 'http://localhost:3000'] } );
|
hypnotoad => {
|
||||||
|
proxy => 1,
|
||||||
|
listen => [ $self->config('listen') // 'http://localhost:3000' ]
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
# Normal route to controller
|
# Normal route to controller
|
||||||
$r->get('/')->to('Page#index');
|
$r->get('/')->to('Page#index');
|
||||||
$r->get('/all.rss')->to('Page#all_rss');
|
$r->get('/all.rss')->to('Page#all_rss');
|
||||||
$r->get('/shiny.rss')->to('Page#shiny_rss');
|
$r->get('/shiny.rss')->to('Page#shiny_rss');
|
||||||
$r->get('/pokerus.rss')->to('Page#pokerus_rss');
|
$r->get('/pokerus.rss')->to('Page#pokerus_rss');
|
||||||
|
$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');
|
||||||
$self->start_gts_bot;
|
$self->start_gts_bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +112,7 @@ sub fetch_gts_data {
|
|||||||
my @offers =
|
my @offers =
|
||||||
$html->find('.gtsPokemonSummary.gtsOffer.pfBoxThin.pfFormGroup')
|
$html->find('.gtsPokemonSummary.gtsOffer.pfBoxThin.pfFormGroup')
|
||||||
->each;
|
->each;
|
||||||
my $db = GTSRSSApi::DB->connect;
|
my $db = GTSRSSApi::DB->connect;
|
||||||
$db->do( <<'EOF', undef );
|
$db->do( <<'EOF', undef );
|
||||||
UPDATE offers SET marked_to_check_is_available = true WHERE is_available = true;
|
UPDATE offers SET marked_to_check_is_available = true WHERE is_available = true;
|
||||||
EOF
|
EOF
|
||||||
@ -272,6 +280,7 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $uuid = create_uuid_string;
|
my $uuid = create_uuid_string;
|
||||||
|
my $offer_uuid = $uuid;
|
||||||
my $query_create_offer = <<'EOF';
|
my $query_create_offer = <<'EOF';
|
||||||
INSERT
|
INSERT
|
||||||
INTO offers
|
INTO offers
|
||||||
@ -309,7 +318,24 @@ EOF
|
|||||||
$is_shiny, $has_pokerus,
|
$is_shiny, $has_pokerus,
|
||||||
$line, $held_item,
|
$line, $held_item,
|
||||||
);
|
);
|
||||||
|
my $query_create_computer_news = <<'EOF';
|
||||||
|
INSERT
|
||||||
|
INTO news_computer
|
||||||
|
(uuid, date, offerer, species, is_shiny, has_pokerus, news_text, held_item)
|
||||||
|
VALUES ( ?, ?, ?, ?, ?, ?, ?, ? );
|
||||||
|
EOF
|
||||||
|
my ($offer) =
|
||||||
|
$db->selectall_array( 'SELECT * FROM offers WHERE uuid = ?',
|
||||||
|
{ Slice => {} }, $offer_uuid );
|
||||||
|
$offer->{is_available} = 1;
|
||||||
|
$uuid = create_uuid_string;
|
||||||
|
$db->do(
|
||||||
|
$query_create_computer_news, undef,
|
||||||
|
$uuid, $pg_date,
|
||||||
|
decode( 'utf-8', $offerer ), $species,
|
||||||
|
$is_shiny, $has_pokerus,
|
||||||
|
Mojo::JSON::encode_json($offer), $held_item,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
warn $@;
|
warn $@;
|
||||||
@ -320,19 +346,19 @@ EOF
|
|||||||
SELECT * FROM offers WHERE is_available and marked_to_check_is_available;
|
SELECT * FROM offers WHERE is_available and marked_to_check_is_available;
|
||||||
EOF
|
EOF
|
||||||
for my $pokemon (@no_longer_available_pokemon) {
|
for my $pokemon (@no_longer_available_pokemon) {
|
||||||
my $species = $pokemon->{species};
|
my $species = $pokemon->{species};
|
||||||
my $nick = $pokemon->{nickname};
|
my $nick = $pokemon->{nickname};
|
||||||
my $offerer = $pokemon->{offerer};
|
my $offerer = $pokemon->{offerer};
|
||||||
my $pokeball = $pokemon->{pokeball};
|
my $pokeball = $pokemon->{pokeball};
|
||||||
my $level = $pokemon->{level};
|
my $level = $pokemon->{level};
|
||||||
my $gender = $pokemon->{gender};
|
my $gender = $pokemon->{gender};
|
||||||
my $nature = $pokemon->{nature};
|
my $nature = $pokemon->{nature};
|
||||||
my $ability = $pokemon->{ability};
|
my $ability = $pokemon->{ability};
|
||||||
my $is_shiny = $pokemon->{is_shiny};
|
my $is_shiny = $pokemon->{is_shiny};
|
||||||
my $has_pokerus = $pokemon->{has_pokerus};
|
my $has_pokerus = $pokemon->{has_pokerus};
|
||||||
my $pg_date = $pokemon->{date};
|
my $pg_date = $pokemon->{date};
|
||||||
my $date = DateTime->now().'';
|
my $date = DateTime->now() . '';
|
||||||
my $held_item = $pokemon->{held_item};
|
my $held_item = $pokemon->{held_item};
|
||||||
my $wanted_species = $pokemon->{wanted_species};
|
my $wanted_species = $pokemon->{wanted_species};
|
||||||
my $requirements = $pokemon->{wanted_requirements};
|
my $requirements = $pokemon->{wanted_requirements};
|
||||||
|
|
||||||
@ -359,6 +385,13 @@ INTO news
|
|||||||
(uuid, date, offerer, species, is_shiny, has_pokerus, news_text, held_item)
|
(uuid, date, offerer, species, is_shiny, has_pokerus, news_text, held_item)
|
||||||
VALUES ( ?, ?, ?, ?, ?, ?, ?, ? );
|
VALUES ( ?, ?, ?, ?, ?, ?, ?, ? );
|
||||||
EOF
|
EOF
|
||||||
|
my $query_create_computer_news = <<'EOF';
|
||||||
|
INSERT
|
||||||
|
INTO news_computer
|
||||||
|
(uuid, date, offerer, species, is_shiny, has_pokerus, news_text, held_item)
|
||||||
|
VALUES ( ?, ?, ?, ?, ?, ?, ?, ? );
|
||||||
|
EOF
|
||||||
|
|
||||||
my $uuid = create_uuid_string;
|
my $uuid = create_uuid_string;
|
||||||
$db->do(
|
$db->do(
|
||||||
$query_create_news, undef, $uuid,
|
$query_create_news, undef, $uuid,
|
||||||
@ -366,6 +399,15 @@ EOF
|
|||||||
$is_shiny, $has_pokerus, $line,
|
$is_shiny, $has_pokerus, $line,
|
||||||
$held_item,
|
$held_item,
|
||||||
);
|
);
|
||||||
|
$pokemon->{is_available} = 0;
|
||||||
|
$uuid = create_uuid_string;
|
||||||
|
$db->do(
|
||||||
|
$query_create_computer_news, undef,
|
||||||
|
$uuid, $pg_date,
|
||||||
|
decode( 'utf-8', $offerer ), $species,
|
||||||
|
$is_shiny, $has_pokerus,
|
||||||
|
Mojo::JSON::encode_json($pokemon), $held_item,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$db->do( <<'EOF', undef );
|
$db->do( <<'EOF', undef );
|
||||||
UPDATE offers SET is_available = false, marked_to_check_is_available = false = true WHERE is_available and marked_to_check_is_available;
|
UPDATE offers SET is_available = false, marked_to_check_is_available = false = true WHERE is_available and marked_to_check_is_available;
|
||||||
|
@ -22,7 +22,7 @@ sub index ($self) {
|
|||||||
sub all_rss ($self) {
|
sub all_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 news_text, date FROM news ORDER BY date DESC LIMIT 100;
|
SELECT species, news_text, date FROM news ORDER BY date DESC LIMIT 100;
|
||||||
EOF
|
EOF
|
||||||
my $dom = $self->_feed_from_news_list(
|
my $dom = $self->_feed_from_news_list(
|
||||||
\@news,
|
\@news,
|
||||||
@ -35,10 +35,26 @@ EOF
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub shiny_rss ($self) {
|
sub computer_all_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 news_text, date FROM news WHERE is_shiny ORDER BY date DESC LIMIT 100;
|
SELECT species, news_text, date FROM news_computer ORDER BY date DESC LIMIT 100;
|
||||||
|
EOF
|
||||||
|
my $dom = $self->_feed_from_news_list(
|
||||||
|
\@news,
|
||||||
|
'All trades GTS',
|
||||||
|
'https://pkmnclassic.net/gts/'
|
||||||
|
);
|
||||||
|
$self->render(
|
||||||
|
format => 'xml',
|
||||||
|
text => $dom,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub computer_shiny_rss ($self) {
|
||||||
|
my $db = GTSRSSApi::DB->connect;
|
||||||
|
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||||
|
SELECT species, news_text, date FROM news_computer WHERE is_shiny ORDER BY date DESC LIMIT 100;
|
||||||
EOF
|
EOF
|
||||||
my $dom = $self->_feed_from_news_list(
|
my $dom = $self->_feed_from_news_list(
|
||||||
\@news,
|
\@news,
|
||||||
@ -51,10 +67,42 @@ EOF
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub shiny_rss ($self) {
|
||||||
|
my $db = GTSRSSApi::DB->connect;
|
||||||
|
my @news = $db->selectall_array( <<'EOF', { Slice => {} } );
|
||||||
|
SELECT species, news_text, date FROM news WHERE is_shiny ORDER BY date DESC LIMIT 100;
|
||||||
|
EOF
|
||||||
|
my $dom = $self->_feed_from_news_list(
|
||||||
|
\@news,
|
||||||
|
'Shiny trades GTS',
|
||||||
|
'https://pkmnclassic.net/gts/'
|
||||||
|
);
|
||||||
|
$self->render(
|
||||||
|
format => 'xml',
|
||||||
|
text => $dom,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
EOF
|
||||||
|
my $dom = $self->_feed_from_news_list(
|
||||||
|
\@news,
|
||||||
|
'Pokerus infected trades GTS',
|
||||||
|
'https://pkmnclassic.net/gts/'
|
||||||
|
);
|
||||||
|
$self->render(
|
||||||
|
format => 'xml',
|
||||||
|
text => $dom,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
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 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;
|
||||||
EOF
|
EOF
|
||||||
my $dom = $self->_feed_from_news_list(
|
my $dom = $self->_feed_from_news_list(
|
||||||
\@news,
|
\@news,
|
||||||
@ -86,7 +134,7 @@ sub _feed_from_news_list ( $self, $news, $title, $link ) {
|
|||||||
|
|
||||||
sub _new_to_rss ( $self, $new ) {
|
sub _new_to_rss ( $self, $new ) {
|
||||||
my $item_tag = Mojo::DOM->new_tag('item');
|
my $item_tag = Mojo::DOM->new_tag('item');
|
||||||
my $title_tag = Mojo::DOM->new_tag( 'title', $new->{news_text} );
|
my $title_tag = Mojo::DOM->new_tag( 'title', $new->{species} );
|
||||||
my $link = Mojo::DOM->new_tag( 'link', 'https://pkmnclassic.net/gts/' );
|
my $link = Mojo::DOM->new_tag( 'link', 'https://pkmnclassic.net/gts/' );
|
||||||
my $description = Mojo::DOM->new_tag( 'description',
|
my $description = Mojo::DOM->new_tag( 'description',
|
||||||
$new->{news_text});
|
$new->{news_text});
|
||||||
|
@ -43,6 +43,16 @@ sub MIGRATIONS {
|
|||||||
news_text TEXT NOT NULL,
|
news_text TEXT NOT NULL,
|
||||||
held_item TEXT
|
held_item TEXT
|
||||||
);',
|
);',
|
||||||
|
'CREATE TABLE news_computer (
|
||||||
|
uuid UUID PRIMARY KEY,
|
||||||
|
date timestamp NOT NULL,
|
||||||
|
species TEXT NOT NULL,
|
||||||
|
offerer TEXT NOT NULL,
|
||||||
|
is_shiny boolean NOT NULL,
|
||||||
|
has_pokerus boolean NOT NULL,
|
||||||
|
news_text TEXT NOT NULL,
|
||||||
|
held_item TEXT
|
||||||
|
);',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
<li><a href="/all.rss">All trades.</a></li>
|
<li><a href="/all.rss">All trades.</a></li>
|
||||||
<li><a href="/shiny.rss">Only shiny trades.</a></li>
|
<li><a href="/shiny.rss">Only shiny trades.</a></li>
|
||||||
<li><a href="/pokerus.rss">Only pokerus trades.</a></li>
|
<li><a href="/pokerus.rss">Only pokerus trades.</a></li>
|
||||||
|
<li><a href="/computer-all.rss">All trades. (JSON)</a></li>
|
||||||
|
<li><a href="/computer-shiny.rss">Only shiny trades. (JSON)</a></li>
|
||||||
|
<li><a href="/computer-pokerus.rss">Only pokerus trades. (JSON)</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user