line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Optical::StrongBuy; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23151
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
92
|
|
6
|
1
|
|
|
1
|
|
469
|
use GD; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use GD::Image; |
8
|
|
|
|
|
|
|
use Data::Dumper; |
9
|
|
|
|
|
|
|
use WWW::Mechanize; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
17
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
18
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# This allows declaration use Finance::Optical::StrongBuy ':all'; |
21
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
22
|
|
|
|
|
|
|
# will save memory. |
23
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
) ] ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @EXPORT = qw( |
30
|
|
|
|
|
|
|
callCheck new recommended |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $img = ""; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $result = {}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub recommended { |
41
|
|
|
|
|
|
|
my $class = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$class->new("/tmp"); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
|
|
|
|
|
|
my $class = shift; |
48
|
|
|
|
|
|
|
my $this = bless { |
49
|
|
|
|
|
|
|
}, $class; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $dir = shift; |
52
|
|
|
|
|
|
|
if( defined $dir ) { |
53
|
|
|
|
|
|
|
$this->set_path( $dir ); |
54
|
|
|
|
|
|
|
$this->{result}=$result; |
55
|
|
|
|
|
|
|
}else{ |
56
|
|
|
|
|
|
|
croak "need a working directory"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return $this; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub set_path { |
63
|
|
|
|
|
|
|
my $this = shift; |
64
|
|
|
|
|
|
|
my $arg = shift; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
croak "need a working directory" if !defined($arg); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$this->{dir} = $arg; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get_source_image |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
my($this)= shift; |
79
|
|
|
|
|
|
|
my ($json_url) = @_; |
80
|
|
|
|
|
|
|
my $EXIT_CODE = 1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $browser = WWW::Mechanize->new( |
83
|
|
|
|
|
|
|
stack_depth => 0, |
84
|
|
|
|
|
|
|
timeout => 3, |
85
|
|
|
|
|
|
|
autocheck => 0, |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
$browser->get( $json_url ); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
if ( $browser->success( ) ) { |
90
|
|
|
|
|
|
|
# print "OK:",$browser->response->status_line(),"\n"; |
91
|
|
|
|
|
|
|
$EXIT_CODE=0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
|
|
|
|
|
|
# print "Fail:",$browser->response->status_line(),"\n"; |
95
|
|
|
|
|
|
|
$EXIT_CODE=1; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub writeImg { |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my($this)= shift; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my ($raw,$file) = @_; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
if($raw !~/404/){ |
107
|
|
|
|
|
|
|
open(OUT, '>', $file); |
108
|
|
|
|
|
|
|
print OUT $raw; |
109
|
|
|
|
|
|
|
close(OUT); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $content = ""; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$content = $browser->content() unless($EXIT_CODE); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return $content; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub callCheck { |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my($this)= shift; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my($symbol)= shift; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $raw = $this->get_source_image(sprintf("http://content.nasdaq.com/ibes/%s_Smallcon.jpg",$symbol)); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $l = length $raw; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
return if($raw =~ m/404|Fail:400 Bad Request/ || $l == 0); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$this->writeImg($raw,sprintf("%s/%s_Smallcon.jpg",$this->{dir},$symbol)); |
137
|
|
|
|
|
|
|
croak("shit image") unless (defined $raw); |
138
|
|
|
|
|
|
|
{ |
139
|
|
|
|
|
|
|
$img = GD::Image->newFromJpeg(sprintf("%s/%s_Smallcon.jpg",$this->{dir},$symbol)); |
140
|
|
|
|
|
|
|
my $myImage = new GD::Image(10,1); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# copy a pixel region from $srcImage to |
143
|
|
|
|
|
|
|
# the rectangle to look for black pixel which marks match |
144
|
|
|
|
|
|
|
# have reduced it strikt right have in strong buy |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
next if(!$img); |
147
|
|
|
|
|
|
|
# |
148
|
|
|
|
|
|
|
$myImage->copy($img,0,0,105,11,10,10); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
binmode STDOUT; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
open (PNG, sprintf(">%s/%s.png",$this->{dir},$symbol)); |
153
|
|
|
|
|
|
|
print PNG $myImage->png; |
154
|
|
|
|
|
|
|
close (PNG); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $sig = $myImage->colorsTotal>=18?'strong buy':undef; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
next unless ($sig); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$this->{result}->{$symbol} =$sig; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
166
|
|
|
|
|
|
|
__END__ |