Skip to content

Instantly share code, notes, and snippets.

@notionparallax
Created June 22, 2016 18:27
Show Gist options
  • Select an option

  • Save notionparallax/b73be97574e5ac8d721c3dce64530e88 to your computer and use it in GitHub Desktop.

Select an option

Save notionparallax/b73be97574e5ac8d721c3dce64530e88 to your computer and use it in GitHub Desktop.
My twitter name is a bit long. I was wondering if there were any good, shorter ones out there. This is a naive way of finding out, but it gets banned by twitter pretty quickly.
#example response: {"valid":false,"reason":"taken","msg":"Username has already been taken","desc":"That username has been taken. Please choose another."}
permissableChars = list("abcdefghijklmnopqrstuvwxyz_1234567890")
import json
import urllib2
import itertools
possibleUsernames = []
for i in range(4,5):
options = itertools.combinations(permissableChars, i)
for o in options:
uname = "".join(o)
url = "https://twitter.com/users/username_available?username="+uname
response = urllib2.urlopen(url)
data = response.read()
values = json.loads(data)
print uname, values
if values["valid"] == "true":
print "\n\n\n WE GOT ONE!"
print uname, values
possibleUsernames.push(uname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment