-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy-platinums.php
executable file
·82 lines (70 loc) · 4.09 KB
/
easy-platinums.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
if (php_sapi_name() !== 'cli') {
exit;
}
require __DIR__ . '/vendor/autoload.php';
use Ahc\Cli\Application;
use App\GameFetcher;
use App\FileWriter;
use App\ManualUpdater;
use App\Result\Row;
// Build container and use DI.
$builder = new DI\ContainerBuilder();
$builder->addDefinitions('config.php');
$container = $builder->build();
$app = new Application('Easy platinums', '0.0.1');
$app
->command('games:fetch', 'Fetch new easy platinums and store in json file')
->argument('<profile-names>', 'PSN Profiles to use to determine easy platinums')
->action(function ($profileNames) use($container) {
$gameFetcher = $container->get(GameFetcher::class);
$addedRows = [];
foreach (explode(',', $profileNames) as $profileName) {
$addedRows = [...$addedRows, ...$gameFetcher->doFetch($profileName)];
}
if (!$addedRows) {
return;
}
echo sprintf(
'Added %s new games to list: %s',
count($addedRows),
implode(', ', array_map(fn(Row $row) => $row->getFullTitle(), $addedRows))
);
})
->tap()
->command('files:update', 'Update list of games')
->action(function () use($container) {
$fileWriter = $container->get(FileWriter::class);
$fileWriter->writePages();
})
->tap()
->command('price:set', 'Set price of one game')
->argument('<id>', 'PSN Profile game id to set price for')
->argument('<amountInCents>', 'The price in cents')
->action(function (string $id, int $amountInCents) use($container) {
$updatedRow = ($container->get(ManualUpdater::class))->updatePriceForId(array_map('trim', explode(',', $id)), $amountInCents);
echo sprintf(
'Manual price update for %s to %s via workflow',
$updatedRow->getFullTitle(),
$updatedRow->getPriceFormattedAsMoney()
);
})
->tap()
->command('game:remove', 'Remove a game from the results')
->argument('<id>', 'PSN Profile game id to remove')
->action(function (string $id) use($container) {
$updatedRow = ($container->get(ManualUpdater::class))->removeGameById($id);
echo sprintf(
'Manually removed game %s via workflow',
$updatedRow->getFullTitle(),
);
});
$app->logo('
███████╗ █████╗ ███████╗██╗ ██╗ ██████╗ ██╗ █████╗ ████████╗██╗███╗ ██╗██╗ ██╗███╗ ███╗███████╗
██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝ ██╔══██╗██║ ██╔══██╗╚══██╔══╝██║████╗ ██║██║ ██║████╗ ████║██╔════╝
█████╗ ███████║███████╗ ╚████╔╝ ██████╔╝██║ ███████║ ██║ ██║██╔██╗ ██║██║ ██║██╔████╔██║███████╗
██╔══╝ ██╔══██║╚════██║ ╚██╔╝ ██╔═══╝ ██║ ██╔══██║ ██║ ██║██║╚██╗██║██║ ██║██║╚██╔╝██║╚════██║
███████╗██║ ██║███████║ ██║ ██║ ███████╗██║ ██║ ██║ ██║██║ ╚████║╚██████╔╝██║ ╚═╝ ██║███████║
╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
');
$app->handle($_SERVER['argv']);