Created
March 7, 2016 00:45
-
-
Save timbennett/80b3696c2c53c6eaf101 to your computer and use it in GitHub Desktop.
Check whether a specified Twitter username is available for registration.
This file contains hidden or 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
## Check whether a specified Twitter username is available for registration. | |
## Usage: 'check_username_available.py username' | |
## IFTTT.com instructions: | |
## You will need an ifttt.com account. Activate the maker channel (https://ifttt.com/maker) and copy your key to this script. | |
## Create a new recipe with trigger "Receive a web request" from the Maker channel. | |
## The script will send the username as Value1 and status as Value2. You can use these in your recipe. | |
## e.g. "Twitter username {{Value1}} {{Value2}}" will come across as "Twitter username jack available" | |
import requests | |
import sys | |
## Copy your maker channel key here: | |
maker_key = '' | |
## Copy the recipe event name field here (e.g. "username_event"): | |
event_name = '' | |
## Get the username provided in the command line argument (else use @jack) | |
try: | |
username = sys.argv[1] | |
except: | |
username = 'jack' | |
## Check the username and store the response | |
url = 'https://twitter.com/users/username_available?username={0}&value={1}'.format(username,username) | |
r = requests.get(url) | |
status = r.json() | |
## If the username is available, send the trigger to ifttt | |
if status['reason'] == 'available': | |
payload = {'value1': username, 'value2' : status['reason']} | |
requests.post('https://maker.ifttt.com/trigger/{0}/with/key/{1}'.format(event_name,maker_key), data=payload) | |
print "Username available" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment