1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Task to register all tweets |
9
|
|
|
* Class Twitter. |
10
|
|
|
*/ |
11
|
|
|
class Twitter extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The name and signature of the console command. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $signature = 'twitter:import'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'Twitter import tweets on Mongo'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create a new command instance. |
29
|
|
|
*/ |
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute the console command. |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
|
public function handle() |
41
|
|
|
{ |
42
|
|
|
$infos = \Thujohn\Twitter\Facades\Twitter::getUsersLookup(['screen_name' => 'Symfomany', 'format' => 'php']); |
43
|
|
|
$manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017'); |
44
|
|
|
$collection = new \MongoDB\Collection($manager, 'laravel.tweets'); |
|
|
|
|
45
|
|
|
|
46
|
|
View Code Duplication |
if (!empty($infos)) { |
|
|
|
|
47
|
|
|
$collection->deleteMany(['origin' => 'Twitter', 'type' => 'infos']); |
48
|
|
|
|
49
|
|
|
$stat = [ |
50
|
|
|
'origin' => 'Twitter', |
51
|
|
|
'type' => 'infos', |
52
|
|
|
'data' => $infos, |
53
|
|
|
'created' => new \MongoDB\BSON\UTCDatetime(time()), |
54
|
|
|
]; |
55
|
|
|
$collection->insertOne($stat); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getDmsOut(['format' => 'php']); |
59
|
|
View Code Duplication |
if (!empty($tweets)) { |
|
|
|
|
60
|
|
|
$collection->deleteMany(['origin' => 'Twitter', 'type' => 'dmsout']); |
61
|
|
|
|
62
|
|
|
foreach ($tweets as $tweet) { |
63
|
|
|
$stat = [ |
64
|
|
|
'origin' => 'Twitter', |
65
|
|
|
'type' => 'dmsout', |
66
|
|
|
'data' => $tweet, |
67
|
|
|
'created' => new \MongoDB\BSON\UTCDatetime(time()), |
68
|
|
|
]; |
69
|
|
|
$collection->insertOne($stat); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getFavorites(['format' => 'php']); |
74
|
|
View Code Duplication |
if (!empty($tweets)) { |
|
|
|
|
75
|
|
|
$collection->deleteMany(['origin' => 'Twitter', 'type' => 'favorites']); |
76
|
|
|
|
77
|
|
|
foreach ($tweets as $tweet) { |
78
|
|
|
$stat = [ |
79
|
|
|
'origin' => 'Twitter', |
80
|
|
|
'type' => 'favorites', |
81
|
|
|
'data' => $tweet, |
82
|
|
|
'created' => new \MongoDB\BSON\UTCDatetime(time()), |
83
|
|
|
]; |
84
|
|
|
$collection->insertOne($stat); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getMentionsTimeline( |
89
|
|
|
[ |
90
|
|
|
'count' => 15, |
91
|
|
|
'format' => 'php', ]); |
92
|
|
|
|
93
|
|
View Code Duplication |
if (!empty($tweets)) { |
|
|
|
|
94
|
|
|
$collection->deleteMany(['origin' => 'Twitter', 'type' => 'mentionstimeline']); |
95
|
|
|
|
96
|
|
|
foreach ($tweets as $tweet) { |
97
|
|
|
$stat = [ |
98
|
|
|
'origin' => 'Twitter', |
99
|
|
|
'type' => 'mentionstimeline', |
100
|
|
|
'data' => $tweet, |
101
|
|
|
'created' => new \MongoDB\BSON\UTCDatetime(time()), |
102
|
|
|
]; |
103
|
|
|
$collection->insertOne($stat); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getHomeTimeline([ |
108
|
|
|
'count' => 15, |
109
|
|
|
'format' => 'php', |
110
|
|
|
]); |
111
|
|
|
|
112
|
|
View Code Duplication |
if (!empty($tweets)) { |
|
|
|
|
113
|
|
|
$collection->deleteMany(['origin' => 'Twitter', 'type' => 'hometimeline']); |
114
|
|
|
|
115
|
|
|
foreach ($tweets as $tweet) { |
116
|
|
|
$stat = [ |
117
|
|
|
'origin' => 'Twitter', |
118
|
|
|
'type' => 'hometimeline', |
119
|
|
|
'data' => $tweet, |
120
|
|
|
'created' => new \MongoDB\BSON\UTCDatetime(time()), |
121
|
|
|
]; |
122
|
|
|
$collection->insertOne($stat); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getUserTimeline([ |
127
|
|
|
'screen_name' => 'allocine', |
128
|
|
|
'count' => 15, |
129
|
|
|
'format' => 'php', |
130
|
|
|
]); |
131
|
|
|
|
132
|
|
View Code Duplication |
if (!empty($tweets)) { |
|
|
|
|
133
|
|
|
$collection->deleteMany(['origin' => 'Twitter', 'type' => 'usertimeline']); |
134
|
|
|
|
135
|
|
|
foreach ($tweets as $tweet) { |
136
|
|
|
$stat = [ |
137
|
|
|
'origin' => 'Twitter', |
138
|
|
|
'type' => 'usertimeline', |
139
|
|
|
'data' => $tweet, |
140
|
|
|
'created' => new \MongoDB\BSON\UTCDatetime(time()), |
141
|
|
|
]; |
142
|
|
|
$collection->insertOne($stat); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
This check looks for function calls that miss required arguments.