1
|
|
|
#!/usr/local/bin/php |
2
|
|
|
<?php |
3
|
|
|
|
4
|
|
|
declare(strict_types=1); |
5
|
|
|
|
6
|
|
|
use Chemaclass\StockTicker\Domain\Notifier\NotifierPolicy; |
7
|
|
|
use Chemaclass\StockTicker\Domain\Notifier\Policy\Condition\ComparingTwoGroups; |
|
|
|
|
8
|
|
|
use Chemaclass\StockTicker\Domain\Notifier\Policy\Condition\OlderWasFound; |
9
|
|
|
use Chemaclass\StockTicker\Domain\Notifier\Policy\PolicyGroup; |
10
|
|
|
use Chemaclass\StockTicker\StockTickerFacade; |
11
|
|
|
use Chemaclass\StockTicker\StockTickerFactory; |
12
|
|
|
use Symfony\Component\HttpClient\HttpClient; |
13
|
|
|
|
14
|
|
|
require_once __DIR__ . '/autoload.php'; |
15
|
|
|
|
16
|
|
|
$sleepingTimeInSeconds = 5; |
17
|
|
|
|
18
|
|
|
$symbols = (count($argv) <= 1) |
19
|
|
|
? ['GOOG'] |
20
|
|
|
: array_slice($argv, 1); |
21
|
|
|
|
22
|
|
|
$policyGroup = new PolicyGroup([ |
23
|
|
|
'More news was found' => new OlderWasFound('NEWS'), |
24
|
|
|
'Buying is higher than selling' => new ComparingTwoGroups( |
25
|
|
|
'TREND', |
26
|
|
|
['buy', 'strongBuy'], |
27
|
|
|
['selling', 'strongSelling'], |
28
|
|
|
), |
29
|
|
|
]); |
30
|
|
|
|
31
|
|
|
// Apply the same PolicyGroup to all symbols |
32
|
|
|
$policy = new NotifierPolicy( |
33
|
|
|
array_fill_keys($symbols, $policyGroup) |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
$facade = new StockTickerFacade( |
37
|
|
|
new StockTickerFactory( |
38
|
|
|
HttpClient::create(), |
39
|
|
|
createEmailChannel(), |
40
|
|
|
createSlackChannel() |
41
|
|
|
) |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$siteCrawlers = [ |
45
|
|
|
createFinanceYahooSiteCrawler(), |
46
|
|
|
createBarronsSiteCrawler(), |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
while (true) { |
50
|
|
|
print sprintf("Looking for news in %s ...\n", implode(', ', $symbols)); |
51
|
|
|
|
52
|
|
|
$crawlResult = $facade->crawlStock($siteCrawlers, $symbols); |
53
|
|
|
$notifyResult = $facade->notify($policy, $crawlResult); |
54
|
|
|
|
55
|
|
|
if ($notifyResult->isEmpty()) { |
56
|
|
|
print " ~~~ Nothing new here...\n"; |
57
|
|
|
sleepWithPrompt($sleepingTimeInSeconds); |
58
|
|
|
|
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
print "====== Notify result ======\n"; |
63
|
|
|
|
64
|
|
|
foreach ($notifyResult->conditionNamesGroupBySymbol() as $symbol => $conditionNames) { |
65
|
|
|
print $symbol . PHP_EOL; |
66
|
|
|
print "Conditions:\n"; |
67
|
|
|
|
68
|
|
|
foreach ($conditionNames as $conditionName) { |
69
|
|
|
print sprintf(" - %s\n", $conditionName); |
70
|
|
|
} |
71
|
|
|
print PHP_EOL; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
sleepWithPrompt($sleepingTimeInSeconds); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function sleepWithPrompt(int $sec): void |
78
|
|
|
{ |
79
|
|
|
print "Sleeping {$sec} seconds...\n"; |
80
|
|
|
$len = mb_strlen((string) $sec); |
81
|
|
|
|
82
|
|
|
for ($i = $sec; $i > 0; $i--) { |
83
|
|
|
print sprintf("%0{$len}d\r", $i); |
84
|
|
|
sleep(1); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
print "Awake again!\n"; |
88
|
|
|
} |
89
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths