/
FollowersCommand.php
47 lines (41 loc) · 1.03 KB
/
FollowersCommand.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
<?php
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class FollowersCommand extends BaseCommand
{
protected function configure()
{
$this
->setName('followers')
->addArgument(
'usernames',
InputArgument::IS_ARRAY
)
;
}
protected function fire(InputInterface $input, OutputInterface $output)
{
$usernames = $input->getArgument('usernames');
$api = new Api;
$merged = [];
foreach ($usernames as $username) {
$followers = $api->followersIds($username);
dump('data/followers-'.$username.'.json', $followers);
foreach ($followers as $f) {
$merged[] = [$f, $username];
}
}
$tmpFilename = sprintf(
'merged-%s',
date('Ymd-His')
);
dump('data/'.$tmpFilename, $merged);
$md5 = md5_file(app_path('data/'.$tmpFilename));
rename(
app_path('data/'.$tmpFilename),
app_path('data/'.$tmpFilename.'-'.$md5.'.json')
);
}
}