line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Grizzly::Command::news; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Gets the stock news for the given symbol |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
8945
|
use Grizzly -command; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
26
|
|
6
|
2
|
|
|
2
|
|
675
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
42
|
|
7
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
50
|
|
8
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
122
|
|
9
|
2
|
|
|
2
|
|
914
|
use open ':std', ':encoding(UTF-8)'; |
|
2
|
|
|
|
|
2424
|
|
|
2
|
|
|
|
|
13
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
33966
|
use Finance::Quote; |
|
2
|
|
|
|
|
128614
|
|
|
2
|
|
|
|
|
103
|
|
12
|
2
|
|
|
2
|
|
1074
|
use Web::NewsAPI; |
|
2
|
|
|
|
|
2553648
|
|
|
2
|
|
|
|
|
80
|
|
13
|
2
|
|
|
2
|
|
954
|
use Grizzly::Progress::Bar; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
71
|
|
14
|
2
|
|
|
2
|
|
1403
|
use Term::ANSIColor; |
|
2
|
|
|
|
|
18336
|
|
|
2
|
|
|
|
|
1257
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $q = Finance::Quote->new("YahooJSON"); |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
1
|
0
|
sub abstract { "display stock news" } |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
1
|
0
|
sub description { "Display the any news on the stock." } |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub validate_args { |
23
|
3
|
|
|
3
|
1
|
5655837
|
my ( $self, $opt, $args ) = @_; |
24
|
3
|
100
|
|
|
|
31
|
$self->usage_error("Need a symbol args") unless @$args; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub execute { |
28
|
2
|
|
|
2
|
1
|
14
|
my ( $self, $opt, $args ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
9
|
quote_info(@$args); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub quote_info { |
34
|
2
|
|
|
2
|
0
|
7
|
my ($symbol) = @_; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
3
|
my $article_number = 1; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
23
|
my %quote = $q->yahoo_json($symbol); |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
365228
|
Grizzly::Progress::Bar->progressbar(); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $name = $quote{ $symbol, "name" }; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
my $api_key = $ENV{'NEWS_API_KEY'} |
45
|
|
|
|
|
|
|
or croak |
46
|
|
|
|
|
|
|
"You need to set an API key to NEWS_API_KEY environment variable"; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $newsapi = Web::NewsAPI->new( api_key => $api_key, ); |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
unless ($name) { |
51
|
0
|
|
|
|
|
|
$name = $symbol; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
print colored( "Here are the top ten headlines worldwide for ", "blue" ) |
55
|
|
|
|
|
|
|
. colored( "$name...\n", "white" ); |
56
|
0
|
|
|
|
|
|
print "\n"; |
57
|
0
|
|
|
|
|
|
my $stock_news = $newsapi->everything( q => $name, pageSize => 10 ); |
58
|
0
|
|
|
|
|
|
for my $article ( $stock_news->articles ) { |
59
|
0
|
|
|
|
|
|
print colored( "$article_number: \n", "magenta" ) |
60
|
|
|
|
|
|
|
. $article->title . "\n"; |
61
|
0
|
|
|
|
|
|
print colored( "Link: ", "cyan" ) . $article->url . "\n"; |
62
|
0
|
|
|
|
|
|
print colored( "Description: ", "cyan" ) . $article->description . "\n"; |
63
|
0
|
|
|
|
|
|
print "\n"; |
64
|
0
|
|
|
|
|
|
$article_number += 1; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
print colored( "The total number of $name articles returned: ", "blue" ) |
67
|
|
|
|
|
|
|
. colored( $stock_news->total_results . "\n", "white" ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=pod |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=encoding UTF-8 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Grizzly::Command::news - Gets the stock news for the given symbol |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
version 0.103 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
grizzly news [stock symbol] |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The news feture will output stock in formation on the inputted ticker symbol. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Grizzly::Command::news |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 API Key |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
You will need to get a free API key from L<NewsAPI|https://newsapi.org/>. Afterwards you will need to set the NEWS_API_KEY environment variable to the API key. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Nobunaga <nobunaga@cpan.org> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Nobunaga. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
MIT License |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Nobunaga <nobunaga@cpan.org> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This software is Copyright (c) 2021 by Nobunaga. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is free software, licensed under: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The MIT (X11) License |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |