Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created July 20, 2009 13:30
Show Gist options
  • Save kriswallsmith/150339 to your computer and use it in GitHub Desktop.
Save kriswallsmith/150339 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
$username = $argv[1];
$password = $argv[2];
// copied from http://fabien.potencier.org/article/20/tweeting-from-php
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Authorization: Basic '.base64_encode("$username:$password"),
),
));
$blocked = file_get_contents('http://twitter.com/blocks/blocking/ids.json', false, $context);
$blocked = json_decode($blocked, true);
$query = array('q' => 'xurl.jp', 'format' => 'json', 'page' => 1);
while (true)
{
$search = file_get_contents('http://search.twitter.com/search?'.http_build_query($query));
$search = json_decode($search, true);
foreach ($search['results'] as $result)
{
if (!in_array($result['from_user_id'], $blocked))
{
@file_get_contents(sprintf('http://twitter.com/blocks/create/%s.json', $result['from_user_id']), false, $context);
$blocked[] = $result['from_user_id'];
echo sprintf("%s (%s)\n", $http_response_header[0], $result['from_user']);
}
}
if (!isset($search['next_page']))
{
break;
}
$query['page']++;
}
echo "\nYou are now blocking ".count($blocked)." user(s).\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment