|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Model\Stats; |
|
6
|
|
|
use App\Model\Tweets; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
use Illuminate\Support\Facades\DB; |
|
9
|
|
|
|
|
10
|
|
|
class Twitter extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The name and signature of the console command. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $signature = 'twitter:import'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'Youtube import tweets on Mongo'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create a new command instance. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the console command. |
|
38
|
|
|
* |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
public function handle() |
|
42
|
|
|
{ |
|
43
|
|
|
|
|
44
|
|
|
$infos = \Thujohn\Twitter\Facades\Twitter::getUsersLookup(['screen_name' => 'Symfomany','format' => 'php']); |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
if(!empty($infos)){ |
|
|
|
|
|
|
47
|
|
|
DB::connection('mongodb')->collection('stats') |
|
48
|
|
|
->where(['origin' => 'Twitter', 'type' => 'infos'])->delete(); |
|
49
|
|
|
|
|
50
|
|
|
$stat = new Stats(); |
|
51
|
|
|
$stat->origin = "Twitter"; |
|
52
|
|
|
$stat->type = "infos"; |
|
53
|
|
|
$stat->data = $infos; |
|
54
|
|
|
$stat->save(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getDmsOut(['format' => 'php']); |
|
59
|
|
View Code Duplication |
if(!empty($tweets)){ |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
DB::connection('mongodb')->collection('tweets') |
|
62
|
|
|
->where(['origin' => 'Twitter', 'type' => 'dmsout']) |
|
63
|
|
|
->delete(); |
|
64
|
|
|
foreach($tweets as $tweet){ |
|
65
|
|
|
$vi = new Tweets(); |
|
66
|
|
|
$vi->origin = "Twitter"; |
|
67
|
|
|
$vi->type = "dmsout"; |
|
68
|
|
|
$vi->data = $tweet; |
|
69
|
|
|
$vi->save(); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getFavorites(['format' => 'php']); |
|
74
|
|
View Code Duplication |
if(!empty($tweets)){ |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
DB::connection('mongodb')->collection('tweets') |
|
77
|
|
|
->where(['origin' => 'Twitter', 'type' => 'favorites']) |
|
78
|
|
|
->delete(); |
|
79
|
|
|
foreach($tweets as $tweet){ |
|
80
|
|
|
$vi = new Tweets(); |
|
81
|
|
|
$vi->origin = "Twitter"; |
|
82
|
|
|
$vi->type = "favorites"; |
|
83
|
|
|
$vi->data = $tweet; |
|
84
|
|
|
$vi->save(); |
|
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
|
|
|
|
|
95
|
|
|
DB::connection('mongodb')->collection('tweets') |
|
96
|
|
|
->where(['origin' => 'Twitter', 'type' => 'mentionstimeline']) |
|
97
|
|
|
->delete(); |
|
98
|
|
|
foreach($tweets as $tweet){ |
|
99
|
|
|
$vi = new Tweets(); |
|
100
|
|
|
$vi->origin = "Twitter"; |
|
101
|
|
|
$vi->type = "mentionstimeline"; |
|
102
|
|
|
$vi->data = $tweet; |
|
103
|
|
|
$vi->save(); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getHomeTimeline( |
|
108
|
|
|
[ |
|
109
|
|
|
'count' => 15, |
|
110
|
|
|
'format' => 'php']); |
|
111
|
|
|
|
|
112
|
|
View Code Duplication |
if(!empty($tweets)){ |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
DB::connection('mongodb')->collection('tweets') |
|
115
|
|
|
->where(['origin' => 'Twitter', 'type' => 'hometimeline']) |
|
116
|
|
|
->delete(); |
|
117
|
|
|
foreach($tweets as $tweet){ |
|
118
|
|
|
$vi = new Tweets(); |
|
119
|
|
|
$vi->data = $tweet; |
|
120
|
|
|
$vi->origin = "Twitter"; |
|
121
|
|
|
$vi->type = "hometimeline"; |
|
122
|
|
|
$vi->save(); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
$tweets = \Thujohn\Twitter\Facades\Twitter::getUserTimeline( |
|
127
|
|
|
[ |
|
128
|
|
|
'screen_name' => 'allocine', |
|
129
|
|
|
'count' => 15, |
|
130
|
|
|
'format' => 'php']); |
|
131
|
|
|
|
|
132
|
|
View Code Duplication |
if(!empty($tweets)){ |
|
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
DB::connection('mongodb')->collection('tweets') |
|
135
|
|
|
->where(['origin' => 'Twitter', 'type' => 'usertimeline']) |
|
136
|
|
|
->delete(); |
|
137
|
|
|
foreach($tweets as $tweet){ |
|
138
|
|
|
$vi = new Tweets(); |
|
139
|
|
|
$vi->data = $tweet; |
|
140
|
|
|
$vi->origin = "Twitter"; |
|
141
|
|
|
$vi->type = "usertimeline"; |
|
142
|
|
|
$vi->save(); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.