Last active
December 14, 2015 12:38
-
-
Save alyssais/5087314 to your computer and use it in GitHub Desktop.
Uses the built-in dictionary in a *nix system to run through every word in the dictionary from shortest to longest and find available Twitter usernames.
Usage: `php -f path/to/twitter.php`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Made by Ross Penman (@PenmanRoss, rosspenman.com) | |
ob_implicit_flush(); | |
$words = trim(file_get_contents("/usr/share/dict/words")); | |
$words = explode("\n", $words); | |
$sorted_words = array(); | |
foreach ($words as $word) { | |
$len = strlen($word); | |
if (!$sorted_words[$len]) $sorted_words[$len] = array(); | |
array_push($sorted_words[$len], $word); | |
} | |
// You can't have a Twitter username over 15 characters. | |
while (count($sorted_words) > 15) { | |
array_pop($sorted_words); | |
} | |
// Twitter won't let new users register usernames less than three characters. | |
array_shift($sorted_words); | |
array_shift($sorted_words); | |
$flattened_words = array(); | |
foreach ($sorted_words as $length) { | |
foreach ($length as $word) { | |
array_push($flattened_words, $word); | |
} | |
} | |
$words = $flattened_words; | |
$available = array(); | |
foreach ($words as $word) { | |
echo "Trying $word\n"; | |
$response = json_decode(file_get_contents("https://twitter.com/users/username_available?context=signup&custom=true&email=&full_name=&suggest=1&suggest_on_username=true&username=$word")); | |
if ($response->valid) { | |
echo "Available"; | |
array_push($available, $word); | |
} else { | |
echo "Not Avilable"; | |
} | |
echo "\n\n"; | |
} | |
echo "===================\nAviailable Usernames\n\n"; | |
foreach ($available as $word) { | |
echo "$word\n"; | |
} | |
echo "===================\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regarding https://twitter.com/PenmanRoss/status/313761056918999040 ... you could add this at the top:
// Discover unused twitter handles which are dictionary words between 3-15 characters in length.
//
// Copyright (C) 2013 Ross Penman http://rosspenman.com/ross
//
// Copying and distribution of this file, with or without modification,
// are permitted in any medium without royalty provided the copyright
// notice and this notice are preserved. This file is offered as-is,
// without any warranty.