Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step 4 #6

Open
wants to merge 1 commit into
base: cmgmyr/twitter-3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class UpdateTwitterList extends Command
*/
protected $description = 'Updates our Twitter list with new interactions';

protected $user_id;
protected $connection;
protected $list_id;

/**
* Create a new command instance.
*
Expand All @@ -28,6 +32,10 @@ class UpdateTwitterList extends Command
public function __construct()
{
parent::__construct();

$this->user_id = config('services.twitter.user');
$this->connection = app('Twitter');
$this->list_id = config('services.twitter.list');
}

/**
Expand All @@ -37,15 +45,12 @@ public function __construct()
*/
public function handle()
{
$user_id = config('services.twitter.user');
$connection = app('Twitter');
$list_id = config('services.twitter.list');

$new_users = [];

$finished = false;
$raw_statuses = [];
$conditions = [
'user_id' => $user_id,
'user_id' => $this->user_id,
'include_rts' => true,
'exclude_replies' => false,
'count' => 3200
Expand All @@ -56,7 +61,7 @@ public function handle()
echo "Going through the timeline...\n";

while (!$finished) {
$data = $connection->get(
$data = $this->connection->get(
"statuses/user_timeline",
$conditions
);
Expand Down Expand Up @@ -122,11 +127,11 @@ public function handle()
echo "Grabbing favorites...\n";
$finished = false;
$max_id = 0;
$conditions = ['user_id' => $user_id, 'count' => 200];
$conditions = ['user_id' => $this->user_id, 'count' => 200];
$favorites = [];

while (!$finished) {
$data = $connection->get(
$data = $this->connection->get(
"favorites/list",
$conditions
);
Expand Down Expand Up @@ -157,9 +162,9 @@ public function handle()

// Get current users on our list
echo "Grabbing users currently on our cycle list...\n";
$members = $connection->get(
$members = $this->connection->get(
"lists/members",
['list_id' => $list_id, 'count' => 5000]
['list_id' => $this->list_id, 'count' => 5000]
);
$users = $members->users;
$current_users = [];
Expand All @@ -184,12 +189,12 @@ public function handle()

while (!$finished) {
$user_slice = array_slice($users_to_remove, $offset, 100);
$response = $connection->post(
$response = $this->connection->post(
"lists/members/destroy_all",
['list_id' => $list_id, 'user_id' => implode(",", $user_slice)]
['list_id' => $this->list_id, 'user_id' => implode(",", $user_slice)]
);

if ($connection->getLastHttpCode() !== 200) {
if ($this->connection->getLastHttpCode() !== 200) {
echo "ERROR while trying to remove users from the cycle list\n";
print_r($response);
exit();
Expand All @@ -213,12 +218,12 @@ public function handle()
$finished = false;
while (!$finished) {
$user_slice = array_slice($users_to_add, $offset, 100);
$response = $connection->post(
$response = $this->connection->post(
"lists/members/create_all",
['list_id' => $list_id, 'user_id' => implode(",", $user_slice)]
['list_id' => $this->list_id, 'user_id' => implode(",", $user_slice)]
);

if ($connection->getLastHttpCode() !== 200) {
if ($this->connection->getLastHttpCode() !== 200) {
echo "ERROR while trying to add users to the cycle list\n";
print_r($response);
exit();
Expand Down