|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created for IG Monitoring. |
|
4
|
|
|
* User: jakim <[email protected]> |
|
5
|
|
|
* Date: 21.06.2018 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace app\components\instagram\base; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
use app\components\instagram\models\Account; |
|
12
|
|
|
use app\components\instagram\models\Post; |
|
13
|
|
|
use yii\base\Component; |
|
14
|
|
|
|
|
15
|
|
|
abstract class Scraper extends Component |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var \GuzzleHttp\Client |
|
19
|
|
|
*/ |
|
20
|
|
|
public $httpClient; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct($httpClient, array $config = []) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->httpClient = $httpClient; |
|
25
|
|
|
parent::__construct($config); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param $posts |
|
30
|
|
|
* @return Post[]|array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function preparePosts($posts): array |
|
33
|
|
|
{ |
|
34
|
|
|
$arr = []; |
|
35
|
|
|
foreach ($posts as $post) { |
|
36
|
|
|
$arr[] = $this->preparePost($post); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $arr; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param \Jakim\Model\Post $post |
|
44
|
|
|
* @return \app\components\instagram\models\Post |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function preparePost(\Jakim\Model\Post $post): Post |
|
47
|
|
|
{ |
|
48
|
|
|
$model = new Post(); |
|
49
|
|
|
$model->id = $post->id; |
|
50
|
|
|
$model->shortcode = $post->shortcode; |
|
51
|
|
|
$model->url = $post->url; |
|
52
|
|
|
$model->isVideo = $post->isVideo; |
|
53
|
|
|
$model->caption = $post->caption; |
|
54
|
|
|
$model->takenAt = $post->takenAt; |
|
55
|
|
|
$model->likes = $post->likes; |
|
56
|
|
|
$model->comments = $post->comments; |
|
57
|
|
|
|
|
58
|
|
|
if ($post->account) { |
|
59
|
|
|
$account = new Account(); |
|
60
|
|
|
$account->id = $post->account->id; |
|
61
|
|
|
$account->profilePicUrl = $post->account->profilePicUrl; |
|
62
|
|
|
$account->username = $post->account->username; |
|
63
|
|
|
$account->fullName = $post->account->fullName; |
|
64
|
|
|
$account->isPrivate = $post->account->isPrivate; |
|
65
|
|
|
$model->account = $account; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $model; |
|
69
|
|
|
} |
|
70
|
|
|
} |